Nagios Core 4 + PNP4Nagios + Check_mk + Nagvis in CentOS 7 – Redhat 7 24


Notice, 12/10/2015. If you don’t need Nagios 4 and you are happy with Nagios 3 version I think the best option today is test and use Check_MK Raw Edition (CRE). This free edition is easy to install and includes all software in this post updated. The only reason to continue with this post in my opinion is that CRE not include Nagios 4 to date.

Introduction.

This post is a tranlate from original in spanish from www.eldespistado.com

To date from this post there is not RPM packages in distributions and common repositories for Nagios 4 so this requires to install compiling. We saw in a previous article how to install Nagios Core 4 and pnp4nagios in Centos 6.X. Check_mk Livestatus was not available for Nagios 4 a now is available. We will see how to install all the essential pack in Centos 7 (Redhat 7), Nagios Core 4 + Check_mk + pnp4nagios + Nagvis. Install everything in their latest versions to this post date.

We start from an installation of Centos 7 installed with the “minimal” option and with SELinux disabled. We need configured EPEL repositories. Additionally we install some required packages.

yum install perl wget httpd php
yum groupinstall "Development Tools"

 

Software required.

  • Nagios Core 4, Core DIY Source edition. In this moment, v.4.0.8.
  • Nagios Plugins. We can choose nagios.org plugins or monitoring-plugins that were denominated nagios plugins until a few months ago. If you are interested in knowing why this different plugins look at this article. We will use the monitoring-plugins but both are similar actually.
  • PNP4Nagios. Download last version used in this post, v, 0.6.24
  • Check_mk. In downloads pages always have available for download two versions. The stable version and the innovate version that becomes the latest alpha / beta version with improvements . To test, I usually use the innovate. It is updated very often with interesting news features and usually works very well.
  • Nagvis. We will use last available avalilable version 1.8rc2.

Update (06/09/2015): The recent check_mk “free” versions are called Check_MK Raw Edition (CRE). These versions incorporate check_mk and additional software (pack previously called OMD). For the source package of check_mk mentioned in this article you must download the CRE version, untar and localize the tar.gz package check_mk in packages/check_mk/

User and groups accounts.

Create accounts for Nagios. We create a “nagcmd” group which we’ll use for external commands and get into that group to nagios user and apache user.

useradd nagios && passwd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

Installing Nagios Core 4.

Previously we install usual packages needed to Nagios.

yum install wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp libpng-devel libjpeg-turbo-devel

At the install time, there was no package available in EPEL for gd-devel so we got and installed the RPM package for Centos 7 from rpmfind.

Unzip the gz Nagios Core and run the installation.

tar zxfv nagios-4.X.X.tar.gz
cd nagios-4.X.X
./configure -with-command-group=nagcmd

End summary

….
*** Configuration summary for nagios 4.0.8 08-12-2014 ***:
General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Install ${includedir}: /usr/local/nagios/include/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
IOBroker Method: epoll
Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):

We continue with usual steps:

make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf

Copy some files from dir sources and change some permissions that are pending at installing.

cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

We check for valid config and create user from apache access. Starting Apache and Nagios and configured them to start after reboot.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
systemctl restart httpd.service && systemctl restart httpd.service
chkconfig --add nagios && chkconfig --level 35 nagios on
systemctl enable httpd.service

Sample to configure Firewall to access Apache on port 80

firewall-cmd --zone=public --permanent –add-port=80/tcp
systemctl restart firewalld.service

Test URI access: http://server/nagios/

Installing Nagios Plugins.

Two options are shown for installing Nagios plugins.

Option1. Installing from EPEL repository packages .

Easier to install and maintain, less current plugins version.

yum install nagios-plugins-all nagios-plugins-nrpe

Plugin are installed in/usr/lib64/nagios/plugins/ directory. Nagios expects to find plugins in /usr/local/nagios/libexec

The simplest is to change in /usr/local/nagios/etc/resource.cfg the location of these.

#$USER1$=/usr/local/nagios/libexec
$USER1$=//usr/lib64/nagios/plugins

 

Opción 2. Compile and install.

More complicated?. We have the latest plugin version and we can choose between nagios plugins or monitoringexchange plugins.

Previously we will install some packages needed for some plugins:

yum install bind-utils net-snmp net-snmp-devel net-snmp-utils net-snmp-perl perl-Net-SNMP

And other packages necessary only if we are going to use some concrete plugins (samba, mysql, …). Optional.

yum install mariadb-libs mariadb-devel samba-client samba-common postgresql-devel openldap-devel

Unzip the file and compile nagios plugins pass as parameter nagios user and group (on of two options):

tar zxfv monitoring-plugins-2.X.X.tar.gz
cd monitoring-plugins-2.1.1
# If install nagios-plugins
./configure -with-nagios-user=nagios -with-nagios-group=nagios
# If you want install monitoring-plugins
./configure -with-nagios-user=nagios -with-nagios-group=nagios --prefix=/usr/local/nagios
make
make install

Accessing to Nagios to test plugins are working.

NagiosCore4.main

Every time we change the Nagios configuration files we should check it (and we need to reload configuration). I usually create some alias in user .bashrc.

# ALIAS PARA NAGIOS
alias q1='/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg'
alias q2='/etc/init.d/nagios reload'

PNP4Nagios

We must install pnp4nagios compiling because if you install it using EPEL packages, dependencies attempt to install full Nagios 3. We not need Nagios 3.

Some required packages

yum install rrdtool perl-Time-HiRes rrdtool-perl php-gd

Installation.

At the time of the installation does not exist in repositories rrdtool-perl package. Locate the equivalent for Centos 7 in rpmfind.net . Download and install locally.

yum localinstall rrdtool-perl-1.4.8-8.el7.x86_64.rpm

And then install compiling pnp4nagios

tar zxfv pnp4nagios-0.6.XX.tar.gz
cd pnp4nagios-0.6.XX
./configure
make all
make fullinstall

Configure the daemon NPCD of pnp4nagios to automatically start and began:

chkconfig --add npcd && chkconfig --level 35 npcd on
systemctl reload httpd.service

If you access the interface URI of pnp4nagios: http://server/pnp4nagios/ should see all checks in green.

pnp4nagios-ok-install

 

We proceed as indicated and rename /usr/local/pnp4nagios/share/install.php file to acknowledge that is properly installed.

mv  /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/install.php.ORI

Reloading pnp4nagios found an error: Please check the documentation for information about the following error. perfdata directory “/usr/local/pnp4nagios/var/perfdata/” is empty. Please check your Nagios config. Read FAQ online

At this time is normal error, we must continue configuring full integration with nagios.

Integration with Nagios.

PNP4nagios has several ways to configure integration with Nagios. We will use the bulk-mode method. If you are thinking of using the simplest and as effective “Bulk Mode With npcdmod” forget it for now. Nagios Core 4 API “event broker” has changed from the previous version, the broker nocdmod will not work (at least not the last version tested in this article – pnp4nagios 0.6.24 – on page pnp4nagios documentation clearly indicates “pnp4nagios npcdmod.o Broker Module is not Compatible with Nagios Core 4.x”).

Nagios.cfg-sample file copy the following settings to the file /usr/local/nagios/etc/nagios.cfg

In the /usr/local/pnp4nagios/etc directory have two example files to copy / paste.

From file nagios.cfg-sample copy next text (ONLY) to /usr/local/nagios/etc/nagios.cfg

#
# Bulk / NPCD mode
#
process_performance_data=1
# *** the template definition differs from the one in the original nagios.cfg
#
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file
# *** the template definition differs from the one in the original nagios.cfg
#
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file

From file misccommands.cfg-sample copy next text to /usr/local/nagios/etc/objects/commands.cfg

#
# Bulk with NPCD mode
#
define command {
command_name process-service-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}
define command {
command_name process-host-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}

Restart nagios and pnp4nagios npcd daemons.

service npcd restart && service nagios restart

We can connect now to the pnp4nagios URI and see the previous error disappears after a while and it starts to paint graphs.

One more important thing. To access directly from the Host / Service Nagios to the corresponding graphs of this without going to the pnp4nagios URI. We follow the instructions in the documentation to configure popups too. We are going to create some templates and apply them to objects.

In file /usr/local/nagios/etc/objects/templates.cfg (i.e.) add

define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
register 0
}
define service {
name srv-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}

And we modify our Host / Services objects to inherit the template, I.e.

define host{
use linux-server,host-pnp
host_name localhost
alias localhost
address 127.0.0.1
}
define service{
use local-service,srv-pnp
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}

We can add the template to all those host / services you want to have graphic. Strategies may be different; one by one service definition assigned to host groups instead of hosts (normal), assign the template to another template (local-service pe), ….

Attention! We need copy a file to the Nagios web directory to work pnp4nagios popups. Copy the file correctly from sources pnp4nagios:

cp contrib/ssi/status-header.ssi /usr/local/nagios/share/ssi/

Restart nagios and ncpd daemons.

service npcd restart && service nagios restart

If we just mouse over the icon and shows a popup with the graph and click in icon go to pnp4nagios service graph.

pnp4nagios-popup

Check_mk

We continue with the installation of check_mk.

Prerequisites

We need an Apache module form EPEL repository. The problem is that this module will no longer be available in EPEL more as there is another python module for Apache with similar functionality and it seems that much better (mod_wgsi). Until CMK migrate to this module we need it. At install moment you must try first to locate a RPM in EPEL or other rpm package repository. If you do not find a package you’ll have to compile. Check post “Compile Apache mod_python module for Centos 7 / Redhat 7” to compile and install it.

Instalación de check_mk y Livestatus

Unzip and launch the installation based on a script.

tar zxfv check_mk-1.X.XiX.tar.gz
cd check_mk-1.X.XiX
./setup.sh

 

During installation script ask questions about file locations and facilitates the task by offering a valid default value usually-

We must rectify only following values:

Nagios command pipe

( default –> /var/log/nagios/rw/nagios.cmd): /usr/local/nagios/var/rw/nagios.cmd

Path to check_icmp (It depends selected option to install plugins previosly)

( autodetected –> /usr/lib64/nagios/plugins/check_icmp): /usr/local/libexec/check_icmp

HTTP authentication file

( default –> /etc/nagios/htpasswd.users): /usr/local/nagios/etc/htpasswd.users

PNP4Nagios templates

( default –> /usr/share/check_mk/pnp-templates): /usr/local/pnp4nagios/share/templates

RRD files

( default –-> /var/lib/nagios/rrd): /usr/local/pnp4nagios/var/perfdata

If something goes wrong you can repeat the installation all times as you want and rectify. CMK remember the previous answers as save them to a file “.check_mk_setup.conf” in our home. In fact when we update check_mk will be as easy as running the new version and accept all and correct values from the previous installation.

Once finished restart the services.

systemctl restart httpd.service && service nagios restart

And test to go to CMK interface → http://server_nagios/check_mk

check_mk_localhost

Everything should work fine. If not, you can verify that the installation added to nagios.cfg broker cmk Livestatus module load.

# Load Livestatus Module
broker_module=/usr/lib/check_mk/livestatus.o /usr/local/nagios/var/rw/live
event_broker_options=-1
# added by setup.sh of check_mk
cfg_dir=/usr/local/nagios/etc/check_mk.d

And then check the nagios.log file to verify that the restart Nagios there are no problems with loading the broker cmk Livestatus.

 

Nagvis.

Prerequisites.

Instalamos los paquetes necesarios que nos instalarán a su vez bastantes dependencias.

Installing the packages needed and dependencies.

yum install php-mbstring php-pdo graphviz

Installation.

Unzip and install. Nagvis is also installed with a script.

tar zxfv nagvis-1.8xx.tar.gz
cd nagvis-1.8xx
./install.sh

The installation takes us questions about our software paths, users, Backends to use (select only mklivestatus-for default-). If you have followed step by step this article, defaults are valid.

Finally edit the configuration file that create for apache in /etc/httpd/conf.d/nagvis.conf and make a couple of changes to work properly in this apache version(2.4):

#AllowOverride None
Require all granted

 

Restart Apache and Go to Nagvis → http://server_nagios/nagvis. (admin / admin)

nagvis_initial_screen

 

The first thing we must do is prove than Nagvis can access to data through our nagios mklivestatus broker.

Go to an existing map (i.e. “Demo1. Datacenter Hamburg”).

  • Menu Edit map / lock-unlock all /
  • Menu Edit Map / Map Options / listbox “backend_id” and select live_1 (save).
  • Menu Edit Map / Add Icon / Host, point to map, select a host in listbox (have at least your localhost) and go.
  • Menu Edut map / lock-unlock all to exit from edit mode.

Now we can create new maps using uploades images and start to put objects in them. By creating our map will use the backend “live_1”

Nagvis includes many maps that are good to test initially but generate much confusion so best to delete maps that not going to use.

Download this post.  

 


Leave a comment

Your email address will not be published. Required fields are marked *

*

24 thoughts on “Nagios Core 4 + PNP4Nagios + Check_mk + Nagvis in CentOS 7 – Redhat 7

  • ArDark

    Thanks! Great tutorial.
    I have already installed Nagios with some hand configuration host.
    Too bad that i should add all from start to use it in Check_MK :\

  • Nurtekin429

    Hi,

    Thanks for great tutorial.
    I cannot see graphs ?
    When i click on it i get this on the webpage.

    PNP4Nagios Version 0.6.25
    Please check the documentation for information about the following error.

    perfdata directory “/usr/local/pnp4nagios/var/perfdata/localhost” for host “localhost” does not exist. Read FAQ online

    file [line]:

    application/models/data.php [148]:

    back

  • MisterIX

    Hey there, thank you for the excellent tutorial. I found it a bit confusing, that you mention Bulk-Mode + NPCD is not compatible to Nagios4 but you still offer a configuration example for the exact mode.

    I only configured nagios and pnp4nagios for bulk mode then. My problem is at the moment, that although the directories /usr/share/check_mk/agents and the respective subfolders are populated, I cannot download and deploy any agents from the website.

    It says: The requested URL /check_mk/agents/check_mk_caching_agent.linux was not found on this server.

    Also I’m not able to “Activate Changes” or “Discard changes”. I’ve checked the folder permissions several times and nagcmd has full access. Any ideas what might go wrong? Best regards!

    • distractedman1 Post author

      There are some configurations in CMK malfunctioning outside of OMD / Check_MK Raw Edition (CRE) integrated setup.
      “Discard changes” is an example. If you solve the problems of folder permissions will end up causing another problems. I do not use “Discard changes” (yo can search an delete “pending.log” file). The problem page “download agents” is surely an Apache configuration problem. I’ve never set it.

  • John Huy

    I installed everything successfully, but I cannot configure Event Console. I got below message when I would try out start mkeventd and Activate Changes on Check MK.
    Cannot start mkeventd: “Checking status of mkeventd…not running (PID file missing)”
    Error message on check_mk: “Error: Cannot connect to event daemon via /usr/local/nagios/var/rw/mkeventd/status: [Errno 111] Connection refused”

    How was the troubles solved by you?

  • John Huy

    My environment: Nagios 4.1.1, pnp4nagios 0.6.25, check-mk-1.2.8p9. After run setup ./setup.sh

    ERROR compiling livestatus! .
    Logfile is in ./livestatus.log.

    I got this error, please help me!
    This is contents log file:
    ***
    /usr/bin/ld: cannot find -lstdc++
    collect2: error: ld returned 1 exit status
    make[2]: *** [livestatus.o] Error 1
    make[2]: *** Waiting for unfinished jobs….
    ranlib livestatus.so
    make[2]: Leaving directory `/tmp/check_mk-1.2.8b9/livestatus.src/src’
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/tmp/check_mk-1.2.8b9/livestatus.src’
    make: *** [all] Error 2
    ***

  • Ali

    Hi that is really great help. THanks you and GOD bless you , Just one think need up date.

    When we copy paste this step we need to remove the space and make space again ‘ and class &srv=_HOST_’ class=’tips . I don’t why but it fixed my problem . all the remaining installation is perfect :)

    In file /usr/local/nagios/etc/objects/templates.cfg (i.e.) add

    define host {
    name host-pnp
    action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_’ class=’tips’ rel=’/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
    register 0
    }
    define service {
    name srv-pnp
    action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$’ class=’tips’ rel=’/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
    register 0
    }

  • Kiran Patel

    I followed this link and able install check_mk successfully. But not able to login using web interface. Always getting error “Invalid credentials”.

    Trying hard since one week but not getting any clue…

    Is something missing?

    • distractedman1 Post author

      The key is in sentence “htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin”
      nagiosadmin is user and system ask for password. You can repeat for new password (“-c” is clean file, for aditional users is without “-c”).
      You must test if check_mk apache config file is using this Apache password file to.