├── Dockerfile ├── README.md ├── apache.init ├── nagios.init ├── postfix.init ├── postfix.stop └── start.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cpuguy83/ubuntu 2 | ENV NAGIOS_HOME /opt/nagios 3 | ENV NAGIOS_USER nagios 4 | ENV NAGIOS_GROUP nagios 5 | ENV NAGIOS_CMDUSER nagios 6 | ENV NAGIOS_CMDGROUP nagios 7 | ENV NAGIOSADMIN_USER nagiosadmin 8 | ENV NAGIOSADMIN_PASS nagios 9 | ENV APACHE_RUN_USER nagios 10 | ENV APACHE_RUN_GROUP nagios 11 | ENV NAGIOS_TIMEZONE UTC 12 | 13 | RUN sed -i 's/universe/universe multiverse/' /etc/apt/sources.list 14 | RUN apt-get update && apt-get install -y iputils-ping netcat build-essential snmp snmpd snmp-mibs-downloader php5-cli apache2 libapache2-mod-php5 runit bc postfix bsd-mailx 15 | RUN ( egrep -i "^${NAGIOS_GROUP}" /etc/group || groupadd $NAGIOS_GROUP ) && ( egrep -i "^${NAGIOS_CMDGROUP}" /etc/group || groupadd $NAGIOS_CMDGROUP ) 16 | RUN ( id -u $NAGIOS_USER || useradd --system $NAGIOS_USER -g $NAGIOS_GROUP -d $NAGIOS_HOME ) && ( id -u $NAGIOS_CMDUSER || useradd --system -d $NAGIOS_HOME -g $NAGIOS_CMDGROUP $NAGIOS_CMDUSER ) 17 | 18 | ADD http://downloads.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.1/nagios-3.5.1.tar.gz?r=http%3A%2F%2Fwww.nagios.org%2Fdownload%2Fcore%2Fthanks%2F%3Ft%3D1398863696&ts=1398863718&use_mirror=superb-dca3 /tmp/nagios.tar.gz 19 | RUN cd /tmp && tar -zxvf nagios.tar.gz && cd nagios && ./configure --prefix=${NAGIOS_HOME} --exec-prefix=${NAGIOS_HOME} --enable-event-broker --with-nagios-command-user=${NAGIOS_CMDUSER} --with-command-group=${NAGIOS_CMDGROUP} --with-nagios-user=${NAGIOS_USER} --with-nagios-group=${NAGIOS_GROUP} && make all && make install && make install-config && make install-commandmode && cp sample-config/httpd.conf /etc/apache2/conf.d/nagios.conf 20 | ADD http://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz /tmp/ 21 | RUN cd /tmp && tar -zxvf nagios-plugins-1.5.tar.gz && cd nagios-plugins-1.5 && ./configure --prefix=${NAGIOS_HOME} && make && make install 22 | 23 | RUN sed -i.bak 's/.*\=www\-data//g' /etc/apache2/envvars 24 | RUN export DOC_ROOT="DocumentRoot $(echo $NAGIOS_HOME/share)"; sed -i "s,DocumentRoot.*,$DOC_ROOT," /etc/apache2/sites-available/default 25 | 26 | RUN ln -s ${NAGIOS_HOME}/bin/nagios /usr/local/bin/nagios && mkdir -p /usr/share/snmp/mibs && chmod 0755 /usr/share/snmp/mibs && touch /usr/share/snmp/mibs/.foo 27 | 28 | RUN echo "use_timezone=$NAGIOS_TIMEZONE" >> ${NAGIOS_HOME}/etc/nagios.cfg && echo "SetEnv TZ \"${NAGIOS_TIMEZONE}\"" >> /etc/apache2/conf.d/nagios.conf 29 | 30 | RUN mkdir -p ${NAGIOS_HOME}/etc/conf.d && mkdir -p ${NAGIOS_HOME}/etc/monitor && ln -s /usr/share/snmp/mibs ${NAGIOS_HOME}/libexec/mibs 31 | RUN echo "cfg_dir=${NAGIOS_HOME}/etc/conf.d" >> ${NAGIOS_HOME}/etc/nagios.cfg 32 | RUN echo "cfg_dir=${NAGIOS_HOME}/etc/monitor" >> ${NAGIOS_HOME}/etc/nagios.cfg 33 | RUN download-mibs && echo "mibs +ALL" > /etc/snmp/snmp.conf 34 | 35 | RUN sed -i 's,/bin/mail,/usr/bin/mail,' /opt/nagios/etc/objects/commands.cfg && \ 36 | sed -i 's,/usr/usr,/usr,' /opt/nagios/etc/objects/commands.cfg 37 | RUN cp /etc/services /var/spool/postfix/etc/ 38 | 39 | RUN mkdir -p /etc/sv/nagios && mkdir -p /etc/sv/apache && rm -rf /etc/sv/getty-5 && mkdir -p /etc/sv/postfix 40 | ADD nagios.init /etc/sv/nagios/run 41 | ADD apache.init /etc/sv/apache/run 42 | ADD postfix.init /etc/sv/postfix/run 43 | ADD postfix.stop /etc/sv/postfix/finish 44 | 45 | ADD start.sh /usr/local/bin/start_nagios 46 | 47 | ENV APACHE_LOCK_DIR /var/run 48 | ENV APACHE_LOG_DIR /var/log/apache2 49 | 50 | EXPOSE 80 51 | 52 | VOLUME /opt/nagios/var 53 | VOLUME /opt/nagios/etc 54 | VOLUME /opt/nagios/libexec 55 | VOLUME /var/log/apache2 56 | VOLUME /usr/share/snmp/mibs 57 | 58 | CMD ["/usr/local/bin/start_nagios"] 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Docker-Nagios [![Docker Build Status](http://72.14.176.28/cpuguy83/nagios)](https://registry.hub.docker.com/u/cpuguy83/nagios) 2 | 3 | Basic Docker image for running Nagios.
4 | This is running Nagios 3.5.1 5 | 6 | You should either link a mail container in as "mail" or set MAIL_SERVER, otherwise 7 | mail will not work. 8 | 9 | ### Knobs ### 10 | - NAGIOSADMIN_USER=nagiosadmin 11 | - NAGIOSAMDIN_PASS=nagios 12 | 13 | ### Web UI ### 14 | The Nagios Web UI is available on port 80 of the container
15 | -------------------------------------------------------------------------------- /apache.init: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | . /etc/default/apache2 3 | 4 | exec /usr/sbin/apache2 -D FOREGROUND 5 | -------------------------------------------------------------------------------- /nagios.init: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | exec ${NAGIOS_HOME}/bin/nagios ${NAGIOS_HOME}/etc/nagios.cfg 4 | -------------------------------------------------------------------------------- /postfix.init: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | : ${MAIL_SERVER=$MAIL_PORT_25_TCP_ADDR} 4 | 5 | 6 | sed -i "s/relayhost =.*/relayhost = ${MAIL_SERVER}/" /etc/postfix/main.cf 7 | sed -i "s/myhostname =.*/myhostname = `hostname`/" /etc/postfix/main.cf 8 | 9 | exec /usr/lib/postfix/master -d -c /etc/postfix 10 | -------------------------------------------------------------------------------- /postfix.stop: -------------------------------------------------------------------------------- 1 | postfix stop 2 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -f ${NAGIOS_HOME}/etc/htpasswd.users ] ; then 4 | htpasswd -c -b -s ${NAGIOS_HOME}/etc/htpasswd.users ${NAGIOSADMIN_USER} ${NAGIOSADMIN_PASS} 5 | chown -R nagios.nagios ${NAGIOS_HOME}/etc/htpasswd.users 6 | fi 7 | 8 | exec runsvdir /etc/sv 9 | 10 | /etc/init.d/apache2 start 11 | --------------------------------------------------------------------------------