From f06375d814938290dc5c37e2f2dcfae8cfade0e6 Mon Sep 17 00:00:00 2001 From: astebenkova Date: Fri, 24 May 2024 18:14:44 +0300 Subject: [PATCH] [nagios] Build Jammy-based image + unify Dockerfiles for different Ubuntu versions + switch plugins to use Python 3, as it is the only supported version starting from Ubuntu Focal Change-Id: I0e66ed0c96ed72c8202940e8a97db17d932a5e47 --- nagios/Dockerfile.ubuntu | 79 +++++++++++++++++++ nagios/Dockerfile.ubuntu_bionic | 71 ----------------- nagios/Dockerfile.ubuntu_focal | 66 ---------------- nagios/build.sh | 5 +- .../plugins/check_exporter_health_metric.py | 2 +- nagios/plugins/check_rest_get_api.py | 2 +- nagios/plugins/define-nagios-hosts.py | 2 +- nagios/plugins/query_elasticsearch.py | 2 +- nagios/plugins/query_prometheus_alerts.py | 2 +- nagios/plugins/send_http_post_event.py | 2 +- zuul.d/nagios.yaml | 18 +++-- 11 files changed, 99 insertions(+), 152 deletions(-) create mode 100644 nagios/Dockerfile.ubuntu delete mode 100644 nagios/Dockerfile.ubuntu_bionic delete mode 100644 nagios/Dockerfile.ubuntu_focal diff --git a/nagios/Dockerfile.ubuntu b/nagios/Dockerfile.ubuntu new file mode 100644 index 00000000..8cd80396 --- /dev/null +++ b/nagios/Dockerfile.ubuntu @@ -0,0 +1,79 @@ +ARG FROM=docker.io/ubuntu:jammy +FROM ${FROM} + +ENV DEBIAN_FRONTEND=noninteractive +ENV APACHE_FRONTEND_PORT 8000 +ENV APACHE_FRONTEND_SECURE_PORT 8443 +ENV KUBE_VERSION=1.29.5 +ENV ES_DSL_VERSION=8.13.1 +ENV ES_VERSION=8.13.2 + +ENV NAGIOSADMIN_EMAIL nagios@localhost +ENV NAGIOS_HOME /opt/nagios +ENV NAGIOS_PLUGIN_DIR /usr/lib/nagios/plugins +ENV VERSION=4.5.0 + +RUN set -ex \ + && apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y --install-recommends \ + jq \ + curl \ + snmp \ + snmpd \ + unzip \ + apache2 \ + libssl-dev \ + checkinstall \ + libapache2-mod-php \ + snmp-mibs-downloader \ + && apt-get install -y --no-install-recommends \ + python3-pip \ + python3-requests \ + monitoring-plugins \ + && pip3 install --upgrade --no-cache-dir pip \ + && pip3 install --upgrade --no-cache-dir \ + requests \ + setuptools \ + kubernetes \ + elasticsearch==${ES_VERSION} \ + elasticsearch-dsl==${ES_DSL_VERSION} \ + && curl --silent -L https://dl.k8s.io/v${KUBE_VERSION}/kubernetes-client-linux-amd64.tar.gz \ + | tar -zC /usr/bin --strip-components=3 --wildcards -x "*/*/*/kubectl" \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN groupadd -g 3000 nagios \ + && useradd -u 3000 -g nagios -d ${NAGIOS_HOME} -s /bin/bash -c 'Nagios Admin' nagios \ + && adduser www-data nagios + +RUN set -ex \ + && cd ${TMP_DIR} \ + && curl --silent -L https://assets.nagios.com/downloads/nagioscore/releases/nagios-${VERSION}.tar.gz \ + | tar -zx --strip-components=1 \ + && ./configure --prefix=${NAGIOS_HOME} \ + --with-nagios-user=nagios \ + --with-nagios-group=nagios \ + --with-command-user=nagios \ + --with-command-group=nagios \ + --with-lockfile=/var/run/nagios.lock \ + && make all \ + && make install \ + && make install-init \ + && make install-config \ + && make install-commandmode \ + && make install-webconf \ + && rm -rf ${TMP_DIR} + +COPY apache2/sites-available/* /etc/apache2/sites-available/ +COPY apache2/ports.conf /etc/apache2/ + +RUN a2ensite nagios && a2enmod cgi && a2dissite 000-default + +COPY scripts/entrypoint.sh /entrypoint.sh +COPY plugins/* ${NAGIOS_PLUGIN_DIR}/ +COPY scripts/snmp-mibs/* /usr/share/snmp/mibs/ + +EXPOSE ${APACHE_FRONTEND_PORT}/tcp +EXPOSE ${APACHE_FRONTEND_SECURE_PORT}/tcp + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/nagios/Dockerfile.ubuntu_bionic b/nagios/Dockerfile.ubuntu_bionic deleted file mode 100644 index 8118dc76..00000000 --- a/nagios/Dockerfile.ubuntu_bionic +++ /dev/null @@ -1,71 +0,0 @@ -ARG FROM=docker.io/ubuntu:bionic -FROM ${FROM} - -ENV DEBIAN_FRONTEND=noninteractive -ENV APACHE_FRONTEND_PORT 8000 -ENV APACHE_FRONTEND_SECURE_PORT 8443 -ENV ES_DSL_VERSION=5.4.0 -ENV ES_VERSION=5.5.3 -ENV KUBE_VERSION=1.16.2 -ENV NAGIOSADMIN_EMAIL nagios@localhost -ENV NAGIOS_HOME /opt/nagios -ENV NAGIOS_PLUGIN_DIR /usr/lib/nagios/plugins -ENV VERSION=4.4.3 - -RUN apt-get -o Acquire::ForceIPv4=true -y update \ - && apt-get -y install curl apache2 checkinstall unzip libapache2-mod-php snmp snmpd snmp-mibs-downloader jq python3-requests \ - && apt-get -y install --no-install-recommends monitoring-plugins python3-pip \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -RUN rm -f /usr/bin/python -RUN ln -s /usr/bin/python3 /usr/bin/python - -RUN pip3 install --upgrade pip \ - && hash -r \ - && pip3 --no-cache-dir install --upgrade setuptools \ - && pip3 --no-cache-dir install --upgrade kubernetes==22.6.0 \ - && pip3 --no-cache-dir install --upgrade elasticsearch==${ES_VERSION} \ - && pip3 --no-cache-dir install --upgrade elasticsearch-dsl==${ES_DSL_VERSION} \ - && pip3 install requests -U - -RUN groupadd -g 3000 nagios -RUN useradd -u 3000 -g nagios -d ${NAGIOS_HOME} -s /bin/bash -c 'Nagios Admin' nagios -RUN adduser www-data nagios - -RUN TMP_DIR=$(mktemp --directory) ;\ - cd ${TMP_DIR} ;\ - curl -sSL https://dl.k8s.io/v${KUBE_VERSION}/kubernetes-client-linux-amd64.tar.gz | tar -zxv --strip-components=1 ;\ - mv ${TMP_DIR}/client/bin/kubectl /usr/local/bin/kubectl ;\ - chmod +x /usr/local/bin/kubectl - -ADD https://assets.nagios.com/downloads/nagioscore/releases/nagios-${VERSION}.tar.gz ${TMP_DIR}/ -RUN cd ${TMP_DIR} && \ - tar zxf ${TMP_DIR}/nagios-${VERSION}.tar.gz && \ - cd nagios-${VERSION} && \ - ./configure --with-lockfile=/var/run/nagios.lock --prefix=${NAGIOS_HOME} --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagios && \ - make all && \ - make install && \ - make install-init && \ - make install-config && \ - make install-commandmode && \ - make install-webconf && \ - cd ${TMP_DIR} && \ - rm -rf nagios-* && \ - rm -rf ${TMP_DIR} - -COPY apache2/sites-available/* /etc/apache2/sites-available/ -COPY apache2/ports.conf /etc/apache2/ - -RUN a2ensite nagios && \ - a2enmod cgi && \ - a2dissite 000-default - -COPY scripts/entrypoint.sh /entrypoint.sh -COPY plugins/* ${NAGIOS_PLUGIN_DIR}/ -COPY scripts/snmp-mibs/* /usr/share/snmp/mibs/ - -EXPOSE ${APACHE_FRONTEND_PORT}/tcp -EXPOSE ${APACHE_FRONTEND_SECURE_PORT}/tcp - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/nagios/Dockerfile.ubuntu_focal b/nagios/Dockerfile.ubuntu_focal deleted file mode 100644 index 6a828c4c..00000000 --- a/nagios/Dockerfile.ubuntu_focal +++ /dev/null @@ -1,66 +0,0 @@ -ARG FROM=docker.io/ubuntu:focal -FROM ${FROM} - -ENV DEBIAN_FRONTEND=noninteractive -ENV APACHE_FRONTEND_PORT 8000 -ENV APACHE_FRONTEND_SECURE_PORT 8443 -ENV ES_DSL_VERSION=7.4.0 -ENV ES_VERSION=7.17.8 -ENV KUBE_VERSION=1.24.6 - -ENV NAGIOSADMIN_EMAIL nagios@localhost -ENV NAGIOS_HOME /opt/nagios -ENV NAGIOS_PLUGIN_DIR /usr/lib/nagios/plugins -ENV VERSION=4.4.9 - -RUN apt-get -o Acquire::ForceIPv4=true -y update && apt-get -y upgrade && \ - apt-get -y install curl apache2 checkinstall unzip libapache2-mod-php snmp snmpd snmp-mibs-downloader jq python3-requests libssl-dev && \ - apt-get -y install --no-install-recommends monitoring-plugins python3-pip && \ - apt-get clean && rm -rf /var/lib/apt/lists/* - -RUN rm -f /usr/bin/python && ln -s /usr/bin/python3 /usr/bin/python - -RUN pip3 install --upgrade pip && \ - hash -r && \ - pip3 --no-cache-dir install --upgrade setuptools && \ - pip3 --no-cache-dir install --upgrade kubernetes && \ - pip3 --no-cache-dir install --upgrade elasticsearch==${ES_VERSION} && \ - pip3 --no-cache-dir install --upgrade elasticsearch-dsl==${ES_DSL_VERSION} && \ - pip3 install requests -U - -RUN groupadd -g 3000 nagios -RUN useradd -u 3000 -g nagios -d ${NAGIOS_HOME} -s /bin/bash -c 'Nagios Admin' nagios -RUN adduser www-data nagios - -RUN TMP_DIR=$(mktemp --directory) && \ - cd ${TMP_DIR} && \ - curl -sSL https://dl.k8s.io/v${KUBE_VERSION}/kubernetes-client-linux-amd64.tar.gz | tar -zxv --strip-components=1 && \ - mv ${TMP_DIR}/client/bin/kubectl /usr/local/bin/kubectl && \ - chmod +x /usr/local/bin/kubectl - -ADD https://assets.nagios.com/downloads/nagioscore/releases/nagios-${VERSION}.tar.gz ${TMP_DIR}/ -RUN cd ${TMP_DIR} && \ - tar zxf ${TMP_DIR}/nagios-${VERSION}.tar.gz && \ - cd nagios-${VERSION} && \ - ./configure --with-lockfile=/var/run/nagios.lock --prefix=${NAGIOS_HOME} --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagios && \ - make all && \ - make install && \ - make install-init && \ - make install-config && \ - make install-commandmode && \ - make install-webconf && \ - cd ${TMP_DIR} && rm -rf nagios-* && rm -rf ${TMP_DIR} - -COPY apache2/sites-available/* /etc/apache2/sites-available/ -COPY apache2/ports.conf /etc/apache2/ - -RUN a2ensite nagios && a2enmod cgi && a2dissite 000-default - -COPY scripts/entrypoint.sh /entrypoint.sh -COPY plugins/* ${NAGIOS_PLUGIN_DIR}/ -COPY scripts/snmp-mibs/* /usr/share/snmp/mibs/ - -EXPOSE ${APACHE_FRONTEND_PORT}/tcp -EXPOSE ${APACHE_FRONTEND_SECURE_PORT}/tcp - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/nagios/build.sh b/nagios/build.sh index 412bbc01..4e35690e 100644 --- a/nagios/build.sh +++ b/nagios/build.sh @@ -6,9 +6,10 @@ cd ${SCRIPT_DIR}/.. IMAGE="nagios" VERSION=${VERSION:-latest} -DISTRO=${DISTRO:-ubuntu_focal} +DISTRO=${DISTRO:-ubuntu} +DISTRO_VERSION=${DISTRO_VERSION:-focal} REGISTRY_URI=${REGISTRY_URI:-"openstackhelm/"} EXTRA_TAG_INFO=${EXTRA_TAG_INFO:-""} -docker build -f ${IMAGE}/Dockerfile.${DISTRO} --network=host -t ${REGISTRY_URI}${IMAGE}:${VERSION}-${DISTRO}${EXTRA_TAG_INFO} ${extra_build_args} ${IMAGE} +docker build -f ${IMAGE}/Dockerfile.${DISTRO} --network=host --build-arg="FROM=${DISTRO}:${DISTRO_VERSION}" -t ${REGISTRY_URI}${IMAGE}:${VERSION}-${DISTRO}${EXTRA_TAG_INFO} ${extra_build_args} ${IMAGE} cd - diff --git a/nagios/plugins/check_exporter_health_metric.py b/nagios/plugins/check_exporter_health_metric.py index 92bebf0d..18a4e4ad 100755 --- a/nagios/plugins/check_exporter_health_metric.py +++ b/nagios/plugins/check_exporter_health_metric.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/nagios/plugins/check_rest_get_api.py b/nagios/plugins/check_rest_get_api.py index 1c822f3c..a71e88ea 100755 --- a/nagios/plugins/check_rest_get_api.py +++ b/nagios/plugins/check_rest_get_api.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- encoding: utf-8 -*- # # REST API monitoring script for Nagios diff --git a/nagios/plugins/define-nagios-hosts.py b/nagios/plugins/define-nagios-hosts.py index 178e9782..3c590553 100755 --- a/nagios/plugins/define-nagios-hosts.py +++ b/nagios/plugins/define-nagios-hosts.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import argparse import sys import requests diff --git a/nagios/plugins/query_elasticsearch.py b/nagios/plugins/query_elasticsearch.py index 4135a57c..3b9138a3 100755 --- a/nagios/plugins/query_elasticsearch.py +++ b/nagios/plugins/query_elasticsearch.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/nagios/plugins/query_prometheus_alerts.py b/nagios/plugins/query_prometheus_alerts.py index 73fbe57e..1cce2b0a 100755 --- a/nagios/plugins/query_prometheus_alerts.py +++ b/nagios/plugins/query_prometheus_alerts.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/nagios/plugins/send_http_post_event.py b/nagios/plugins/send_http_post_event.py index f1f48b11..8d3eba56 100755 --- a/nagios/plugins/send_http_post_event.py +++ b/nagios/plugins/send_http_post_event.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/zuul.d/nagios.yaml b/zuul.d/nagios.yaml index eb022621..558b45e3 100644 --- a/zuul.d/nagios.yaml +++ b/zuul.d/nagios.yaml @@ -37,16 +37,20 @@ docker_images: - context: nagios repository: openstackhelm/nagios - dockerfile: Dockerfile.ubuntu_bionic - tags: - - latest-ubuntu_bionic - - "ubuntu_bionic-{{ currentdate }}" - - context: nagios - repository: openstackhelm/nagios - dockerfile: Dockerfile.ubuntu_focal + dockerfile: Dockerfile.ubuntu + build_args: + - "FROM=docker.io/ubuntu:focal" tags: - latest-ubuntu_focal - "ubuntu_focal-{{ currentdate }}" + - context: nagios + repository: openstackhelm/nagios + dockerfile: Dockerfile.ubuntu + build_args: + - "FROM=docker.io/ubuntu:jammy" + tags: + - latest-ubuntu_jammy + - "ubuntu_jammy-{{ currentdate }}" files: &nagios_files - nagios/.* - zuul.d/nagios.yaml