How to export Nagios data into CSV?

Fiqah Sapnan picture Fiqah Sapnan · Nov 11, 2015 · Viewed 18.3k times · Source

I am a newbie and I am doing this for my project. I am able to install and monitor nagios successfully. But I am required to export these data into csv. Can anyone help me in this?

Thank you so much xx

Answer

Joe Young picture Joe Young · Nov 11, 2015

You can set the host_perfdata_file and service_perfdata_file directives in your nagios.cfg configuration file to output performance data to the specified file path in the format specified by the host_perfdata_file_template and service_perfdata_file_template directive.

Writing Performance Data To Files

You can have Nagios write all host and service performance data directly to text files using the host_perfdata_file and service_perfdata_file options. The format in which host and service performance data is written to those files is determined by the host_perfdata_file_template and service_perfdata_file_template options.

An example file format template for service performance data might look like this:

service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$

By default, the text files will be opened in "append" mode. If you need to change the modes to "write" or "non-blocking read/write" (useful when writing to pipes), you can use the host_perfdata_file_mode and service_perfdata_file_mode options.

Additionally, you can have Nagios periodically execute commands to periocially process the performance data files (e.g. rotate them) using the host_perfdata_file_processing_command and service_perfdata_file_processing_command options. The interval at which these commands are executed are governed by the host_perfdata_file_processing_interval and service_perfdata_file_processing_interval options, respectively.

Source: https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/perfdata.html

Performance Data Processing Option

Format:   process_performance_data=<0/1>
Example:  process_performance_data=1
This value determines whether or not Nagios will process host and service check performance data.

0 = Don't process performance data (default)
1 = Process performance data

Host Performance Data Processing Command

Format:   host_perfdata_command=<command>
Example:  host_perfdata_command=process-host-perfdata

This option allows you to specify a command to be run after every host check to process host performance data that may be returned from the check. The command argument is the short name of a command definition that you define in your object configuration file. This command is only executed if the process_performance_data option is enabled globally and if the process_perf_data directive in the host definition is enabled.

Service Performance Data Processing Command

Format:   service_perfdata_command=<command>
Example:  service_perfdata_command=process-service-perfdata

This option allows you to specify a command to be run after every service check to process service performance data that may be returned from the check. The command argument is the short name of a command definition that you define in your object configuration file. This command is only executed if the process_performance_data option is enabled globally and if the process_perf_data directive in the service definition is enabled.

Host Performance Data File

Format:   host_perfdata_file=<file_name>
Example:  host_perfdata_file=/usr/local/nagios/var/host-perfdata.dat

This option allows you to specify a file to which host performance data will be written after every host check. Data will be written to the performance file as specified by the host_perfdata_file_template option. Performance data is only written to this file if the process_performance_data option is enabled globally and if the process_perf_data directive in the host definition is enabled.

Service Performance Data File

Format:   service_perfdata_file=<file_name>
Example:  service_perfdata_file=/usr/local/nagios/var/service-perfdata.dat

This option allows you to specify a file to which service performance data will be written after every service check. Data will be written to the performance file as specified by the service_perfdata_file_template option. Performance data is only written to this file if the process_performance_data option is enabled globally and if the process_perf_data directive in the service definition is enabled.

Host Performance Data File Template

Format:   host_perfdata_file_template=<template>
Example:  host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$

This option determines what (and how) data is written to the host performance data file. The template 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.

Service Performance Data File Template

Format:   service_perfdata_file_template=<template>
Example:  service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$

This option determines what (and how) data is written to the service performance data file. The template 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.

Source: https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/configmain.html#process_performance_data

NOTE: If you've followed the directions to setup pnp4nagios in "Bulk Mode", you've probably already done this. In that case, you just need to refer to the path you specified in host_perfdata_file and service_perfdata_file. But if not, here's how you do it for pnp4nagios:

Processing of performance data has to be enabled in nagios.cfg

 process_performance_data=1

Additionally some new directives are required

#
# service performance data
#
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 performance data starting with Nagios 3.0
# 
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

Source: https://docs.pnp4nagios.org/pnp-0.6/config#bulk_mode

EDIT: Here's an easier way to get generate CSV data on-demand.

  • Browse to http:///nagios/cgi-bin/avail.cgi
  • Fill out the steps of the wizard.
  • Be sure to check the "Output in CSV Format" checkbox on the 3rd screen.
  • Click "Create Availability Report!" button.
  • CSV file will be generated and downloaded in your browser.

enter image description here enter image description here enter image description here