Nagios Complete Monitoring System with Check_mk and pnp4nagios and mrtg

by Ras 14. November 2012 21:47






As we all know, nagios is one of the best and biggest open source moniroting systems available. With lots of extensions and modules, nagios is the most popular monitoring software.


I have been working on Nagios for the last couple of years and the combination of Nagios, pnp4nagios, mrtg and check_mk will give you a very nice complete monitoring solution.


pnp4nagios provides a nice history trend report for the services and check_mk is one of the strongest plugins for service monitoring. MRTG as we know it provides snmp monitoring and graphs.


Below are the installation steps:

1- Required packages on Linux are:

php, python, apache, mod_python, httpd-devel

nagios and nagios plugins

check_mk (need python,apache,xinetd,nagios)

pnp4nagios (requires rrdtools)

mrtg, snmp, snmp-utils


2- Install all the packages with yum or apt-get.


3- I am not going to explain the basic nagios installation and configuration as you can find it everywhere, but what you need to do to get the pnp4nagios working:



# You need to add configuration of nagios.conf from its sample configuration to the nagios configuraiton file.
(From /usr/local/pnp4nagios/etc/nagios.cfg to  /usr/local/nagios/etc/nagios.cfg)


# At the end of /usr/local/nagios/etc/objects/commands.cfg, add the command definitions:

define command{
command_name process-service-perfdata-file
command_line $USER1$/process_perfdata.pl --bulk=/usr/local/nagios/var/serviceperfdata
}
define command{
command_name process-host-perfdata-file
command_line $USER1$/process_perfdata.pl --bulk=/usr/local/nagios/var/hostperfdata
}


# There is one more step to complete the setup. We need to enable extended info in Nagios so that links
to the graphs are created for each applicable host and service.
Append two entries to /usr/local/nagios/etc/objects/templates.cfg:


define host {
name host-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$
}
define service {
name srv-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
}



# These are templates that you add to each host and service definition with graphs:

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


4- After installing nagios and its configuration and pnp4nagios, now it is time for check_mk installation and congfiguration.



Example of configuration for check_mk main configuration file:

/etc/check_mk/main.mk

all_hosts = [
 "xyzabc1|muc",
 'xyzabc2|ber',
 "xyzabc3|ber|test|some|other|tag",
 "xyzabc4|tcp",
 "10.0.34.35",
]

ipaddresses = {
  "xzyabc1" : "10.0.34.18",
  "xyzcba2" : "192.168.0.17",
}

Optional:    # if you want to ignore checking some services
ignored_checktypes = [ "systemtime", "logwatch", ]


and run the below commands to recreate the inventory and add nagios templates and objects.

check_mk -II
check_mk -O


If you don't know the checks and services names of check_mk:

cmk -L to view check_types
cmk -D to view services

main.mk (9.54 kb)

5- Now it is time to install mrtg for network monitoring.

Install mrtg and snmp and snmp-utils

create mrtg cfg files:

# cfgmake public@10.1.1.1 >> /var/lib/mrtg/10.1.1.1
# cat 10.1.1.1 >> /etc/mrtg/mrtg.cfg


# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

create a bash file for above command and add it to crontab for every 5 min (if it is not in there already by default)


This will create log files on /var/lib/mrtg/*.log

use the log files for switch.cfg on nagios (you need check_mrtgtraf plugin installed)


##############################################
define service{

    use            generic-service,srv-pnp; Inherit values from a template

    host_name        Cisco-Switch

    service_description    Port 1 Bandwidth Usage

    check_command        check_local_mrtgtraf!/var/lib/mrtg/10.1.1.1_1.log!AVG!1000000,2000000!5000000,5000000!10

    }
##############################################




Enjoy!

Tags: , , , , ,

Monitoring

About the author

Ras is a network/Security professional working on multiple areas with multiple certificates like CCNP, CCIP, CCSP, CCSA, CCSE, LPI, PM, IPv6, ..

Month List