Nagios Core 4 on CentOS 7: Part 2 – Installation and Configuration of PNP4Nagios

A quick foreword, I am not a native Linux SA. If there are corrections to terminology needed or if I have mislabeled something, please, let me know so I can update this page. It took me quite a while to figure out how to allow things to work properly without having to disable SELinux. Thank you!

Beginning from a fresh installation of Nagios Core 4 from Part 1.

Note: Any time you modify a Nagios configuration file, you can restart that Nagios service with command below to see if that step is where something broke.

service nagios restart

Now that that has been established, we’ll temporarily enable Root SSH Access by editing the SSH config file.

vi /etc/ssh/sshd_config

Press the I key to begin editing. Note: for the rest of this document, if edits are required, you will likely need to remember this.

Remove the # from before PermitRootLogin Yes.

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

Next, you’ll write quite. Note: to do this you wil need to ress the Escape key and then type “:wq!” without the quotes to save and exit. (As above with the I key, you will need to remember this.)

:wq!

Restart SSH.

service sshd restart

Open Putty or your favorite SSH method and connect to the device and login as root. If you’re using DHCP, you may need to run the command below to get the IP Address.

ip addr show

Now, to start, we’ll install dependencies.

yum install gd gd-devel php-gd rrdtool rrdtool-perl ruby xorg-x11-fonts-Type1 -y

4. Download or SFTP necessary file, the version I successfully used is listed below.

pnp4nagios-0.6.26.tar.gz

Now, we’ll extract and install PNP4Nagios.

tar zxfv pnp4nagios-0.6.26.tar.gz
cd pnp4nagios-0.6.26
./configure
make all
make fullinstall
make install-init

Now we’ll prep and restart the web service.

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

Browse to the PNP4Nagios web page and make sure it passed the checks.

https://serverip/pnp4nagios/

Now, we’ll rename the file mentioned on the web page if all checks were passed.

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

Now, we’re going to need to modify the Nagios configuration files.

vi /usr/local/nagios/etc/nagios.cfg

Press the I key to begin editing and update each item as seen below.

host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
process_performance_data=1
enable_environment_macros=1
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
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

Next, you’ll write quite. Press the Escape key and then type “:wq!” without the quotes. (You may want to restart the Nagios service to see if you broke anything.)

:wq!

Now, we’ll need to append the commands configuration file for Bulk with NPCD Mode.

vi /usr/local/nagios/etc/objects/commands.cfg

Press the I key to begin editing and add this to the bottom.

#
# 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$
}

Press the Escape key and then type “:wq!” without the quotes to save and exit. (You may want to restart the Nagios service to see if you broke anything.)

:wq!

Now, we’ll need to append the templates configuration file. These will be the link identifiers for future monitoring. (Adds graph icons next to either the host or service depending on how it’s implemented later in this documentation.)

vi /usr/local/nagios/etc/objects/templates.cfg

These new host and service objects need to be appended to this configuration file. (Press the I key to begin editing.)

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
}

Press the Escape key and then type “:wq!” without the quotes to save and exit. (You may want to restart the Nagios service to see if you broke anything.)

:wq!

Option 1: Configure all hosts and/or services to be monitored. (Skip to Option 2 for individual host or server configuration.)

a. Configuration of All Hosts Example:

For implementing this, we’ll need to edit the core templates configuration file.

vi /usr/local/nagios/etc/objects/templates.cfg

You will need to make sure that under the “generic-host” host definition template, you add the “use host-pnp” line as seen below.

define host{
        name                            generic-host    ; The name of this host template
        use                             host-pnp
        notifications_enabled           1               ; Host notifications are enabled
        event_handler_enabled           1               ; Host event handler is enabled
        flap_detection_enabled          1               ; Flap detection is enabled
        process_perf_data               1               ; Process performance data
        retain_status_information       1               ; Retain status information across program restarts
        retain_nonstatus_information    1               ; Retain non-status information across program restarts
        notification_period             24x7            ; Send host notifications at any time
        register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

Now, you’ll press Escape, followed by “:wq!” to save and quit vi. (You may want to restart the Nagios service to see if you broke anything.)

:wq!

For any update to a configuration file to take effect, you will need to restart the Nagios service.

service nagios restart

b. Configuration of All Services Example:

For implementing this, we’ll need to edit the core templates configuration file.

vi /usr/local/nagios/etc/objects/templates.cfg

You will need to make sure that under the “generic-service” service definition template, you add the “use srv-pnp” line as seen below.

define service{
        name                            generic-service         ; The 'name' of this service template
        use                             srv-pnp                 ; <----
        active_checks_enabled           1                       ; Active service checks are enabled
        passive_checks_enabled          1                       ; Passive service checks are enabled/accepted
        parallelize_check               1                       ; Active service checks should be parallelized (disabling this can lead to major performance problems)
        obsess_over_service             1                       ; We should obsess over this service (if necessary)
        check_freshness                 0                       ; Default is to NOT check service 'freshness'
        notifications_enabled           1                       ; Service notifications are enabled
        event_handler_enabled           1                       ; Service event handler is enabled
        flap_detection_enabled          1                       ; Flap detection is enabled
        process_perf_data               1                       ; Process performance data
        retain_status_information       1                       ; Retain status information across program restarts
        retain_nonstatus_information    1                       ; Retain non-status information across program restarts
        is_volatile                     0                       ; The service is not volatile
        check_period                    24x7                    ; The service can be checked at any time of the day
        max_check_attempts              3                       ; Re-check the service up to 3 times in order to determine its final (hard) state
        check_interval                  2                       ; Check the service every 10 minutes under normal conditions
        retry_interval                  2                       ; Re-check the service every two minutes until a hard state can be determined
        contact_groups                  admins                  ; Notifications get sent out to everyone in the 'admins' group
        notification_options            w,u,c,r                 ; Send notifications about warning, unknown, critical, and recovery events
        notification_interval           60                      ; Re-notify about service problems every hour
        notification_period             24x7                    ; Notifications can be sent out at any time
        register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}

Now, you’ll press Escape, followed by “:wq!” to save and quit vi. (You may want to restart the Nagios service to see if you broke anything.)

:wq!

For any update to a configuration file to take effect, you will need to restart the Nagios service.

service nagios restart

Option 2: Configure a single host and/or single service to be monitored. (Return to Option 1 for monitoring of all hosts or all services.)

a. Individual Host Configuration Example:

For this example, we’ll be using the Nagios localhost monitoring configuration file.

vi /usr/local/nagios/etc/objects/localhost.cfg

You’ll press the I key and append “,host-pnp” after “linux-server” to add host monitoring as seen below.

define host{
        use                     linux-server,host-pnp
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }

Now, you’ll press Escape, followed by “:wq!” to save and quit vi. (You may want to restart the Nagios service to see if you broke anything.)

:wq!

For any update to a configuration file to take effect, you will need to restart the Nagios service.

service nagios restart

b. Individual Service Configuration Example:

For this example, we’ll be using the Nagios localhost monitoring configuration file.

vi /usr/local/nagios/etc/objects/localhost.cfg

You’ll press the I key and append “,srv-pnp” after “local-service” to add service monitoring as seen below.

define service{
        use                             local-service,srv-pnp
        host_name                       localhost
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }

Now, you’ll press Escape, followed by “:wq!” to save and quit vi. (You may want to restart the Nagios service to see if you broke anything.)

:wq!

For any update to a configuration file to take effect, you will need to restart the Nagios service.

service nagios restart

Next, we’ll copy ssi files then restart NPCD and Nagios.

cd /root/pnp4nagios-0.6.26/
cp contrib/ssi/status-header.ssi /usr/local/nagios/share/ssi/
service npcd restart && service nagios restart

Remove PNP4Nagios Installer

cd ~
rm -rf pnp4nagios-0.6.26*

And now you should be ready to start using PNP4Nagios on your server.

If everything worked well, you should return and disable root SSH access.

vi /etc/ssh/sshd_config

Add # before PermitRootLogin yes.

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

Save and quit vi.

:wq!

Restart SSH.

service sshd restart

This post is only one part of a series of Nagios documentation I am be preparing.

Nagios Core 4 on CentOS 7: Part 1 – Installation

Nagios Core 4 on CentOS 7: Part 2 – Installation and Configuration of PNP4Nagios

Nagios Core 4 on CentOS 7: Part 3 – Installation and Configuration of Grafana over HTTPS

Nagios Core 4 on CentOS 7: Part 4 – Installation of V-Shell 2