FROM debian:9
MAINTAINER Jean Gabes <naparuba@gmail.com>

RUN        apt-get update && apt-get install -y python
# Setup test env, "standard" installation is test with other tests ^^
RUN        apt-get install -y python-pip
RUN        pip install jinja2
RUN        pip install leveldb
RUN        pip install pyOpenSSL
RUN        pip install pycrypto
RUN        pip install requests
RUN        pip install Crypto
RUN        pip install pygments
RUN        pip install coveralls
RUN        pip install nose-cov
RUN        pip install unittest2
RUN        apt-get install -y python-cherrypy3
RUN        pip install rsa
# The internal yaml seems to not be used, thanks nose
RUN        pip install ruamel.yaml==0.11.15
RUN        apt-get install -y sysstat
RUN        apt-get install -y nagios-plugins-standard


# Setup nagios
RUN       apt-get -y install build-essential openssl perl make  libgd2-xpm-dev  libperl-dev libssl-dev daemon wget  unzip

RUN       useradd nagios

WORKDIR   /root/
RUN       wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.2.tar.gz
RUN       tar -zxvf nagios-4.3.2.tar.gz;
WORKDIR   /root/nagios-4.3.2/
RUN       ./configure --with-nagios-group=nagios --with-command-group=nagios
RUN       make all -j8
RUN       make install
RUN       make install-init
RUN       make install-config
RUN       make install-commandmode

# Be sure to create the icinga/nagios directory
RUN       mkdir /usr/local/nagios/etc/objects/agent
#I don't care about the default localhost give by nagios, I only want mine
#RUN       > /usr/local/nagios/etc/objects/localhost.cfg
RUN       echo "cfg_dir=/usr/local/nagios/etc/objects/agent" >> /usr/local/nagios/etc/nagios.cfg


ADD        . /root/opsbro-oss
WORKDIR       /root/opsbro-oss

RUN       python setup.py install

# We will modify a pack, so overload it first
RUN        opsbro  packs overload global.shinken

# Then copy our files to the new pack overloaded (monitoring plugin + parameters)
# TODO: remove the parameter copy, should be with CLI calls
ADD        test/test-files/test-nagios-connector   /var/lib/opsbro/local-configuration/packs/shinken/


# Change module parameters for Nagios
RUN        opsbro  packs parameters set local.shinken.enabled               true
RUN        opsbro  packs parameters set local.shinken.cfg_path              /usr/local/nagios/etc/objects/agent
RUN        opsbro  packs parameters set local.shinken.external_command_file /usr/local/nagios/var/rw/nagios.cmd
RUN        opsbro  packs parameters set local.shinken.reload_command        "/etc/init.d/nagios reload"
RUN        opsbro  packs parameters set local.shinken.monitoring_tool       nagios


ENTRYPOINT     test/test_nagios_connector.sh
