****************
Nagios migration
****************

Centreon Engine is compatible with Nagios. This means that it will
recognize Nagios's configuration files and behave just like Nagios
would. However some subtle differences arise when migrating from an
existing Nagios setup. This document will explain what this differences
are and how to modify them.

All example path in this documentation is based on CentOS i386. You
probably need to change these path with you own configuration.

Prerequisites
=============

Centreon Engine is assumed to have been properly installed in your
nagios monitoring server.

Startup file
------------

SysV init script (default)
^^^^^^^^^^^^^^^^^^^^^^^^^^

By default, Centreon Engine do not usually use the same files as Nagios
does. This can cause issues when interfacing with Centreon. Modify
``/etc/init.d/centengine``, replace the following variables, so that
Centreon Engine use the exact same files and directories as Nagios.

::

    var_dir=/var/log/nagios
    config_file=/etc/nagios/nagios.cfg
    command_file=$var_dir/rw/nagios.cmd
    user=nagios
    group=nagios

Upstart configuration file
^^^^^^^^^^^^^^^^^^^^^^^^^^

On systems with Upstart installed (such as recent Ubuntu versions),
Centreon Engine provides a configuration file to control it. Modify it
like below.

::

    env HOME=/etc/nagios
    env CFG_FILE="$HOME/nagios.cfg"

Nagios configuration file
-------------------------

Be sure you have defined all file paths in the Nagios configuration
file. All these variables can be found in Centreon 2.3.5 and above. You
need to modify these variables, because Centreon Engine (just like
Nagios) use default values for variables that are not defined. This can
cause issues when interfacing with Centreon.

::

    log_file=/var/log/nagios/nagios.log
    temp_file=/var/log/nagios/nagios.tmp
    p1_file=/usr/sbin/p1.pl
    log_archive_path=/var/log/nagios/archives
    command_file=/var/log/nagios/rw/nagios.cmd
    lock_file=/var/log/nagios/nagios.lock
    state_retention_file=/var/log/nagios/status.sav
    object_cache_file=/var/log/nagios/objects.cache
    precached_object_file=/var/log/nagios/objects.precache
    debug_file=/var/log/nagios/nagios.debug

Commands and notification
-------------------------

Centreon Engine is very fast compared to Nagios. The downside is, some
rarely used features were deactivated. For example, commands are not
processed by a shell before execution (Nagios did that). So if some of
your commands use shell syntax (pipes, globbing, ...) you have to modify
them.

For check or notification commands with multiple commands like this::

    $ cat /etc/nagios/commands.cfg
    define command{
      command_name host-notify-by-email
      command_line printf "Message..." | mail -s "Subject..." $CONTACTEMAIL$
    }

The solution is to add 'sh -c' on the command line, so that the shell
(sh) will execute and parse your command::

    $ cat /etc/nagios/commands.cfg
    define command{
      command_name host-notify-by-email
      command_line sh -c 'printf "Message..." | mail -s "Subject..." $CONTACTEMAIL$'
    }

.. warning::
   the new command obeys Nagios syntax. So if your old command contains
   single quotes ('), they need to be escaped.

External commands
-----------------

Centreon Engine by itself does not need any system to control it. This
is why we decided to extract the external commands system from the core.
For Centreon Engine, this is now a broker module, like NDOUtils or
Centreon Broker. However, Centreon uses it for some tasks (scheduled
downtimes, comments, acknowledgement, ...) and is therefore required in
such setups.

In Centreon, go to *Configuration -> Monitoring Engine -> main.cfg*.
Choose your poller and go to the Data tab. Add a new Broker Module with
the following configuration line::

    /usr/lib/centreon-engine/externalcmd.so

The module does not need any configuration as Centreon Engine handle all
the parsing process.

Centreon
--------

Centreon needs to control Centreon Engine to perform tasks such as
configuration checks. At time of writing, Centreon Engine it not a
specific monitoring engine but will work as "Nagios".

In Centreon go to *Configuration -> Centreon -> Pollers*. Choose
your poller and modify Scheduler Information.

SysV init script (default)
^^^^^^^^^^^^^^^^^^^^^^^^^^

::

    Engine: Centreon-Engine (with centreon >= 2.3.5)
    Nagios Init Script: /etc/init.d/centengine
    Scheduler Binary: /usr/sbin/centengine
    Nagios Statistics Binary: /usr/sbin/centenginestats

Upstart configuration file
^^^^^^^^^^^^^^^^^^^^^^^^^^

::

    Engine: Centreon-Engine (with centreon >= 2.3.5)
    Nagios Init Script: service centengine
    Scheduler Binary: /usr/sbin/centengine
    Nagios Statistics Binary: /usr/sbin/centenginestats

Sudoers
-------

SysV init script (default)
^^^^^^^^^^^^^^^^^^^^^^^^^^

Add these lines into /etc/sudoers::

    # Centengine Restart
    CENTREON   ALL = NOPASSWD: /etc/init.d/centengine restart
    # Centengine stop
    CENTREON   ALL = NOPASSWD: /etc/init.d/centengine start
    # Centengine stop
    CENTREON   ALL = NOPASSWD: /etc/init.d/centengine stop
    # Centengine reload
    CENTREON   ALL = NOPASSWD: /etc/init.d/centengine reload
    # Centengine test config
    CENTREON   ALL = NOPASSWD: /usr/sbin/centengine -v *
    # Centengine test for optim config
    CENTREON   ALL = NOPASSWD: /usr/sbin/centengine -s *

Upstart configuration file
^^^^^^^^^^^^^^^^^^^^^^^^^^

Add these lines into /etc/sudoers::

    # Centengine Restart
    CENTREON   ALL = NOPASSWD: service centengine restart
    # Centengine stop
    CENTREON   ALL = NOPASSWD: service centengine start
    # Centengine stop
    CENTREON   ALL = NOPASSWD: service centengine stop
    # Centengine reload
    CENTREON   ALL = NOPASSWD: service centengine reload
    # Centengine test config
    CENTREON   ALL = NOPASSWD: /usr/sbin/centengine -v *
    # Centengine test for optim config
    CENTREON   ALL = NOPASSWD: /usr/sbin/centengine -s *

Stop/Start
----------

To finish the migration you need to stop nagios and start
centreon-engine.

