From 3f16e88babcf06f22444bb15848ab503c0b62fff Mon Sep 17 00:00:00 2001 From: Mark Vartanyan Date: Fri, 27 Jun 2014 13:22:43 +0200 Subject: [PATCH] Works, yeehaw! :) --- Dockerfile | 78 +++++++++++++++++++++++++++++++++------- README.md | 63 +++++++++----------------------- conf/apache2-site.conf | 24 +++++++++++++ conf/nagios.cfg | 0 conf/php.ini | 11 ++++++ conf/supervisor-all.conf | 10 ++++++ run.sh | 17 +++++++++ 7 files changed, 144 insertions(+), 59 deletions(-) create mode 100644 conf/apache2-site.conf create mode 100644 conf/nagios.cfg create mode 100644 conf/php.ini create mode 100644 conf/supervisor-all.conf create mode 100755 run.sh diff --git a/Dockerfile b/Dockerfile index 6a08539..da8023c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,31 +2,83 @@ FROM ubuntu:14.04 MAINTAINER "Mark Vartanyan " -# Const -ENV NAGIOS_PHP_TIMEZONE UTC -ENV NAGIOS_TARBALL http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.7.tar.gz -ENV NAGIOS_PLUGINS_TARBALL http://www.nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz - # Packages: update & install ENV DEBCONF_FRONTEND noninteractive RUN sed -i 's~.* universe$~\0 multiverse~' /etc/apt/sources.list RUN apt-get update -qq RUN apt-get install -qq -y --no-install-recommends python-pip supervisor build-essential RUN apt-get install -qq -y --no-install-recommends apache2 libapache2-mod-php5 snmp-mibs-downloader -RUN apt-get install -qq -y --no-install-recommends wget curl samba-common samba-common-bin smbclient snmp whois +RUN apt-get install -qq -y --no-install-recommends apache2-utils wget curl samba-common samba-common-bin smbclient snmp whois traceroute RUN apt-get install -qq -y --no-install-recommends libgd2-xpm-dev libssl-dev libnet-snmp-perl libperl-dev libpq5 libradius1 libsensors4 libsnmp-base libtalloc2 libtdb1 libwbclient0 libmysqlclient15-dev RUN pip install j2cli + + +# Const +ENV NAGIOS_PHP_TIMEZONE UTC +ENV NAGIOS_TARBALL http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.7.tar.gz +ENV NAGIOS_PLUGINS_TARBALL http://www.nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz +ENV NAGIOS_NRPE_TARBALL http://kent.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz +# Using manual: https://raymii.org/s/tutorials/Nagios_Core_4_Installation_on_Ubuntu_12.04.html + + + # Users RUN groupadd -g 3000 nagios -RUN useradd -u 3000 -g nagios -m -s /bin/bash nagios +RUN useradd -u 3000 -g nagios -G www-data -m -s /bin/bash nagios # Install nagios -# RUN mkdir -p /usr/local/src/nagios4 -# RUN cd /usr/local/src/nagios4 && wget $NAGIOS_TARBALL -O- | tar -zxp --strip-components 1 && ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagios && make all -# -# # Install nagios plugins -# RUN mkdir -p /usr/local/src/nagios4-plugins -# RUN cd /usr/local/src/nagios4-plugins && wget $NAGIOS_PLUGINS_TARBALL -O- | tar -zxp --strip-components 1 && ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules --enable-libtap +RUN mkdir -p /usr/local/src/nagios4 +RUN cd /usr/local/src/nagios4 && wget $NAGIOS_TARBALL -O- | tar -zxp --strip-components 1 && ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagios && make all && make install install-init install-config install-commandmode + +# Install nagios plugins +RUN mkdir -p /usr/local/src/nagios4-plugins +RUN cd /usr/local/src/nagios4-plugins && wget $NAGIOS_PLUGINS_TARBALL -O- | tar -zxp --strip-components 1 && ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules --enable-libtap && make && make install + +# Install nagios NRPE +RUN mkdir -p /usr/local/src/nagios4-nrpe +RUN cd /usr/local/src/nagios4-nrpe && wget $NAGIOS_NRPE_TARBALL -O- | tar -zxp --strip-components 1 && ./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu && make all && make install + +# Clean-up +RUN rm -rf /usr/local/src/nagios* + +# Add files +ADD conf /root/conf + +# Configure: php +RUN j2 /root/conf/php.ini > /etc/php5/mods-available/custom.ini +RUN php5enmod custom + +# Configure: apache +ADD conf/apache2-site.conf /etc/apache2/sites-available/nagios.conf +RUN a2dissite 000-default +RUN a2ensite nagios + +# Configure: supervisor +ADD conf/supervisor-all.conf /etc/supervisor/conf.d/ + + + + +# Configure: nagios +RUN ln -s /usr/local/nagios/etc /etc/nagios +RUN bash -c 'mkdir -p /etc/nagios/conf.d /etc/nagios/conf.d/{hosts,services,timeperiods,templates,hostgroups,servicegroups,contacts}' +RUN echo 'cfg_dir=/etc/nagios/conf.d/' >> /etc/nagios/nagios.cfg + + + + +# Runner +ADD run.sh /root/run.sh + + + +# Declare +VOLUME ["/etc/nagios/", "/usr/local/nagios/var/"] +EXPOSE 80 +EXPOSE 5666 + +CMD ["/root/run.sh"] + diff --git a/README.md b/README.md index b39c41e..31e0abd 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ -Zabbix Server & Web UI -====================== +Nagios +====== Contains: -* Zabbix Server -* Zabbinx Front-end -* Nginx +* Nagios Core +* Nagios Plugins +* Nagios NPRE (Remote Plugin Execution) +* Apache * PHP Processes are managed by supervisor, including cronjobs @@ -15,59 +16,29 @@ Exports ------- * Nginx on `80` -* Zabbix Server on `10051` -* `/etc/zabbix/alert.d/` for Zabbix alertscripts +* Nagios NRPE on `5666` +* `/etc/nagios`: configuration +* `/usr/local/nagios/var/`: nagios runtime Variables --------- -* `ZABBIX_DB_NAME=zabbix`: Database name to work on -* `ZABBIX_DB_USER=zabbix`: MySQL user -* `ZABBIX_DB_PASS=zabbix`: MySQL password -* `ZABBIX_DB_HOST=localhost`: MySQL host to connect to -* `ZABBIX_DB_PORT=3306`: MySQL port - -* `ZABBIX_INSTALLATION_NAME=`: Zabbix installation name - -Linking: - -* `ZABBIX_DB_LINK=`: Database link name. Example: a value of "DB_PORT_3306" will fill in `ZABBIX_DB_HOST/PORT` variables +* `NAGIOS_USER=nagios`: Web UI username +* `NAGIOS_PASS=nagios`: Web UI password Constants in Dockerfile ----------------------- -* `ZABBIX_PHP_TIMEZONE=UTC`: Timezone to use with PHP +* `NAGIOS_PHP_TIMEZONE=UTC`: Timezone to use with PHP +* `NAGIOS_TARBALL`: Nagios tarball URL +* `NAGIOS_PLUGINS_TARBALL`: Nagios Plugins tarball URL +* `NAGIOS_NRPE_TARBALL`: Nagios NRPE tarball URL Example ------- -Launch database container: +Launch Nagios container: - $ docker start zabbix-db || docker run --name="zabbix-db" -d -e MYSQL_ROOT_PASSWORD='root' -e MYSQL_DATABASE='zabbix' -e MYSQL_USER='zabbix' -e MYSQL_PASSWORD='zabbix' -e MYSQL_SET_KEYBUF=64M -p localhost::3306 -v /var/lib/mysql:/var/lib/mysql kolypto/mysql - -Install the required tables: - - $ docker run --rm --link zabbix-db:db -e ZABBIX_DB_LINK=DB_PORT_3306 kolypto/zabbix-server /root/run.sh setup-db - -Launch Zabbix container: - - $ docker start zabbix || docker run --name="zabbix" --link zabbix-db:db -e ZABBIX_DB_LINK=DB_PORT_3306 -p 80:80 -p 10051:10051 kolypto/zabbix-server - -By default, you sign in as Admin:zabbix. + $ docker start nagios || docker run --rm -p 80:80 -p 5666:5666 -e NAGIOS_USER=nagios -e NAGIOS_PASS=nagios -ti kolypto/nagios Enjoy! :) - -Configuration Cheat-Sheet -------------------------- - -Things to do at the beginning: - -* Administration > Users, Users: disable guest access (group), setup user accounts & themes -* Administration > Media types: set up notification methods. For custom alertscripts, see [Custom alertscripts](https://www.zabbix.com/documentation/2.4/manual/config/notifications/media/script) -* Administration > Users, Users, "Media" tab: set up notification destinations -* Configuration > Hosts: create a new host and add items, triggers & stuff - -TODO ----- - -* Create a way to set up and update alertscripts: `/etc/zabbix/alert.d/`. Git? Download? Update? diff --git a/conf/apache2-site.conf b/conf/apache2-site.conf new file mode 100644 index 0000000..b188c4a --- /dev/null +++ b/conf/apache2-site.conf @@ -0,0 +1,24 @@ + + ServerName localhost + DocumentRoot /usr/local/nagios/share/ + + ScriptAlias /cgi-bin/ /usr/local/nagios/sbin/ + + Options +ExecCGI + + + + Options FollowSymLinks + + DirectoryIndex index.php index.html + + AllowOverride AuthConfig + Order Allow,Deny + Allow From All + + AuthName "Nagios Access" + AuthType Basic + AuthUserFile /etc/nagios/htpasswd.users + require valid-user + + diff --git a/conf/nagios.cfg b/conf/nagios.cfg new file mode 100644 index 0000000..e69de29 diff --git a/conf/php.ini b/conf/php.ini new file mode 100644 index 0000000..7caab2a --- /dev/null +++ b/conf/php.ini @@ -0,0 +1,11 @@ +[PHP] +date.timezone={{ NAGIOS_PHP_TIMEZONE }} + +max_execution_time = 300 +memory_limit = 128M + +display_errors = Off + +post_max_size = 16M +upload_max_filesize = 2M +max_input_time = 300 diff --git a/conf/supervisor-all.conf b/conf/supervisor-all.conf new file mode 100644 index 0000000..a35ccba --- /dev/null +++ b/conf/supervisor-all.conf @@ -0,0 +1,10 @@ +[supervisord] +logfile = /var/log/supervisord.log +logfile_backups = 0 + +[program:apache] +command = /bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND" + +[program:nagios] +user = nagios +command = /usr/local/nagios/bin/nagios /etc/nagios/nagios.cfg diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..79f3014 --- /dev/null +++ b/run.sh @@ -0,0 +1,17 @@ +#! /usr/bin/env bash +set -eu # exit on error or undefined variable + +# Variables +export NAGIOS_USER=${NAGIOS_USER:-"nagios"} +export NAGIOS_PASS=${NAGIOS_PASS:-"nagios"} + +# Templating +htpasswd -cb /etc/nagios/htpasswd.users $NAGIOS_USER $NAGIOS_PASS + +# Logging +rm -f /usr/local/nagios/var/nagios.lock /var/run/apache2/apache2.pid +LOGFILES=$(echo /usr/local/nagios/var/nagios.log /var/log/{supervisord,apache2/error}.log) +( umask 0 && truncate -s0 $LOGFILES ) && tail --pid $$ -n0 -F $LOGFILES & + +# Launch +exec /usr/bin/supervisord -n