Pnp4nagios Pi – Configuring Nagios Commands

Pnp4nagios Pi – Configuring Nagios Commands

Configure Nagios to process performance data

Following the successful installation of pnp4nagios the next step is to configure Nagios to process performance data as well as send the data to pnp4nagios. The configuration for this piece is performed by editing the main nagios.cfg file to first enable processing of performance data, then configure the performance data file settings for hosts and services.

To modify configure Nagios to process performance data and configure the performance data file settings for hosts and services perform the following steps:

  • Logon to the Raspberry Pi and execute the following command to become root:
sudo -i
  • Backup the existing /usr/local/nagios/etc/nagios.cfg file (Optional step)
cp /usr/local/nagios/etc/nagios.cfg /usr/local/nagios/etc/nagios.cfg-beforepnp4nagios
  • Edit /usr/local/nagios/etc/nagios.cfg using the editor of your choice
  • Locate the line process_performance_date=0 to process_performance_date=1 as shown below:
# PROCESS PERFORMANCE DATA OPTION
# This determines whether or not Nagios will process performance
# data returned from service and host checks. If this option is
# enabled, host performance data will be processed using the
# host_perfdata_command (defined below) and service performance
# data will be processed using the service_perfdata_command (also
#defined below). Read the HTML docs for more information on
#performance data.
#Values: 1 = process performance data, 0 = do not process performance data

process_performance_data=1
  • Next locate the line starting with #host_perfdata_file= and add in the two lines in bold as shown below to set the performance data file locations to pnp4nagios:
# HOST AND SERVICE PERFORMANCE DATA FILES
# These files are used to store host and service performance data.
# Performance data is only written to these files if the
# enable_performance_data option (above) is set to 1.

#host_perfdata_file=/usr/local/nagios/var/host-perfdata
#service_perfdata_file=/usr/local/nagios/var/service-perfdata

host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
  • Next locate the line starting with #host_perfdata_file_template= and add in the two lines in bold as shown below to set the data file templates:
# HOST AND SERVICE PERFORMANCE DATA FILE TEMPLATES
# These options determine what data is written (and how) to the
# performance data files. The templates may contain macros, special
# characters (\t for tab, \r for carriage return, \n for newline)
# and plain text. A newline is automatically added after each write
# to the performance data file. Some examples of what you can do are
# shown below.

#host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
#service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$

host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
  • Next locate the line starting with #host_perfdata_file_mode=a and add the two lines in bold as shown below:
# HOST AND SERVICE PERFORMANCE DATA FILE MODES
# This option determines whether or not the host and service
# performance data files are opened in write ("w") or append ("a")
# mode. If you want to use named pipes, you should use the special
# pipe ("p") mode which avoid blocking at startup, otherwise you will
# likely want the default append ("a") mode.

#host_perfdata_file_mode=a
#service_perfdata_file_mode=a

host_perfdata_file_mode=a
service_perfdata_file_mode=a
  • Next locate the line starting with #host_perfdata_file_processing_interval= and add the two lines in bold as shown below:
# HOST AND SERVICE PERFORMANCE DATA FILE PROCESSING INTERVAL
# These options determine how often (in seconds) the host and service
# performance data files are processed using the commands defined
# below. A value of 0 indicates the files should not be periodically
# processed.

#host_perfdata_file_processing_interval=0
#service_perfdata_file_processing_interval=0

host_perfdata_file_processing_interval=15
service_perfdata_file_processing_interval=15
  • Next locate the line starting with #host_perfdata_file_processing_command= and add the two lines in bold as shown below:
# HOST AND SERVICE PERFORMANCE DATA FILE PROCESSING COMMANDS
# These commands are used to periodically process the host and
# service performance data files. The interval at which the
# processing occurs is determined by the options above.

#host_perfdata_file_processing_command=process-host-perfdata-file
#service_perfdata_file_processing_command=process-service-perfdata-file

host_perfdata_file_processing_command=process-host-perfdata-file-bulk-npcd
service_perfdata_file_processing_command=process-service-perfdata-file-bulk-npcd
  • Save and exit the file

Configure the Nagios commands

The next step in the process is to add the commands to Nagios which will be used to process the performance data with pnp4nagios by performing the following steps:

  • Backup the existing /usr/local/nagios/etc/objects/commands.cfg file (Optional step)
cp /usr/local/nagios/etc/objects/commands.cfg /usr/local/nagios/etc/objects/commands.cfg-beforepnp4nagios
  • Edit /usr/local/nagios/etc/objects/commands.cfg using the editor of your choice
  • Go to the end of the file and add the command definitions below:
define command {
    command_name    process-service-perfdata-file-bulk-npcd
    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-bulk-npcd
    command_line    /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
    }
  • Save and exit the file

Validate the Nagios config and restart Nagios

Once the configuration has been applied to Nagios it needs to be validated and restarted by performing the following steps:

  • Validate the Nagios configuration by executing the following command:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  • Next restart Nagios by executing the following command:
systemctl restart nagios

Next, proceed on to the next article in the series to integrate with the Nagios Core Web Interface.

Leave a Reply

Your email address will not be published.