From b8cbafa040de03d5e864fd77a427a7024a1f2ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20M=C3=A9rian?= Date: Tue, 21 Apr 2020 13:32:50 +0200 Subject: [PATCH] Add mk_livestatus --- Dockerfile | 24 +++++++++++++++++++++--- overlay/etc/sv/xinetd/run | 3 +++ overlay/etc/xinetd.d/livestatus | 14 ++++++++++++++ overlay/opt/nagios/etc/nagios.cfg | 2 +- overlay/usr/local/bin/start_nagios | 6 +++++- 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100755 overlay/etc/sv/xinetd/run create mode 100644 overlay/etc/xinetd.d/livestatus diff --git a/Dockerfile b/Dockerfile index a6edab3..11507f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,7 @@ ENV NG_CGI_URL /cgi-bin ENV NAGIOS_BRANCH nagios-4.4.5 ENV NAGIOS_PLUGINS_BRANCH release-2.2.1 ENV NRPE_BRANCH nrpe-3.2.1 +ENV MK_LIVESTATUS_VERSION 1.2.8p18 RUN echo postfix postfix/main_mailer_type string "'Internet Site'" | debconf-set-selections && \ @@ -79,6 +80,7 @@ RUN echo postfix postfix/main_mailer_type string "'Internet Site'" | debconf-set snmp-mibs-downloader \ unzip \ python \ + xinetd \ && \ apt-get clean && rm -Rf /var/lib/apt/lists/* @@ -173,6 +175,18 @@ RUN cd /opt cp /opt/nagios-mssql/check_mssql_database.py ${NAGIOS_HOME}/libexec/ && \ cp /opt/nagios-mssql/check_mssql_server.py ${NAGIOS_HOME}/libexec/ +RUN cd /tmp && \ + wget https://mathias-kettner.de/download/mk-livestatus-${MK_LIVESTATUS_VERSION}.tar.gz && \ + tar zxf mk-livestatus-${MK_LIVESTATUS_VERSION}.tar.gz && \ + cd mk-livestatus-${MK_LIVESTATUS_VERSION} && \ + ./configure --with-nagios4 && \ + make && \ + make install && \ + cd /tmp && rm -Rf mk-livestatus-${MK_LIVESTATUS_VERSION} && \ + cd /tmp && rm -f mk-livestatus-${MK_LIVESTATUS_VERSION}.tar.gz + +RUN mkdir -p /usr/local/nagios/var/rw && \ + chown ${NAGIOS_USER}:${NAGIOS_GROUP} /usr/local/nagios/var/rw RUN sed -i.bak 's/.*\=www\-data//g' /etc/apache2/envvars RUN export DOC_ROOT="DocumentRoot $(echo $NAGIOS_HOME/share)" && \ @@ -206,9 +220,12 @@ RUN echo "use_timezone=${NAGIOS_TIMEZONE}" >> ${NAGIOS_HOME}/etc/nagios.cfg # Copy example config in-case the user has started with empty var or etc -RUN mkdir -p /orig/var && mkdir -p /orig/etc && \ - cp -Rp ${NAGIOS_HOME}/var/* /orig/var/ && \ - cp -Rp ${NAGIOS_HOME}/etc/* /orig/etc/ +RUN mkdir -p /orig/var && \ + mkdir -p /orig/etc && \ + mkdir -p /orig/xinetd.d && \ + cp -Rp ${NAGIOS_HOME}/var/* /orig/var/ && \ + cp -Rp ${NAGIOS_HOME}/etc/* /orig/etc/ && \ + cp -Rp /etc/xinetd.d/* /orig/xinetd.d/ RUN a2enmod session && \ a2enmod session_cookie && \ @@ -241,6 +258,7 @@ RUN echo "ServerName ${NAGIOS_FQDN}" > /etc/apache2/conf-available/servername.co ln -s /etc/apache2/conf-available/timezone.conf /etc/apache2/conf-enabled/timezone.conf EXPOSE 80 +EXPOSE 6557 VOLUME "${NAGIOS_HOME}/var" "${NAGIOS_HOME}/etc" "/var/log/apache2" "/opt/Custom-Nagios-Plugins" "/opt/nagiosgraph/var" "/opt/nagiosgraph/etc" diff --git a/overlay/etc/sv/xinetd/run b/overlay/etc/sv/xinetd/run new file mode 100755 index 0000000..a0ab22e --- /dev/null +++ b/overlay/etc/sv/xinetd/run @@ -0,0 +1,3 @@ +#!/bin/bash + +exec /usr/sbin/xinetd -f /etc/xinetd.conf -dontfork diff --git a/overlay/etc/xinetd.d/livestatus b/overlay/etc/xinetd.d/livestatus new file mode 100644 index 0000000..085d2a0 --- /dev/null +++ b/overlay/etc/xinetd.d/livestatus @@ -0,0 +1,14 @@ +service livestatus +{ + type = UNLISTED + port = 6557 + socket_type = stream + protocol = tcp + wait = no + cps = 100 3 + flags = NODELAY + user = nagios + server = /usr/local/bin/unixcat + server_args = /usr/local/nagios/var/rw/live + disable = no +} diff --git a/overlay/opt/nagios/etc/nagios.cfg b/overlay/opt/nagios/etc/nagios.cfg index d0fdbc3..e5927c7 100644 --- a/overlay/opt/nagios/etc/nagios.cfg +++ b/overlay/opt/nagios/etc/nagios.cfg @@ -222,7 +222,7 @@ event_broker_options=-1 #broker_module=/somewhere/module1.o #broker_module=/somewhere/module2.o arg1 arg2=3 debug=0 - +broker_module=/usr/local/lib/mk-livestatus/livestatus.o /usr/local/nagios/var/rw/live event_broker_options=-1 # LOG ROTATION METHOD diff --git a/overlay/usr/local/bin/start_nagios b/overlay/usr/local/bin/start_nagios index 1c8c488..4cebb35 100755 --- a/overlay/usr/local/bin/start_nagios +++ b/overlay/usr/local/bin/start_nagios @@ -14,6 +14,11 @@ if [ -z "$(ls -A /opt/nagios/var)" ]; then cp -Rp /orig/var/* /opt/nagios/var/ fi +if [ -z "$(ls -A /etc/xinetd.d)" ]; then + echo "Started with empty xinetd config, copying example data in-place" + cp -Rp /orig/xinetd.d/* /etc/xinetd.d/ +fi + if [ ! -f "${NAGIOS_HOME}/etc/htpasswd.users" ] ; then htpasswd -c -b -s "${NAGIOS_HOME}/etc/htpasswd.users" "${NAGIOSADMIN_USER}" "${NAGIOSADMIN_PASS}" chown -R ${NAGIOS_USER}.${NAGIOS_GROUP} "${NAGIOS_HOME}/etc/htpasswd.users" @@ -43,4 +48,3 @@ trap shutdown SIGTERM SIGHUP SIGINT wait "${RUNSVDIR}" shutdown -