Hi Matt 🙂
The nagios.log file contains alerts and notifications etc but the performance data is logged to a separate file, either:
"service-perfdata" to be ingested into splunk with a sourcetype of "nagiosserviceperf"
or
"splunk-nagios-perfdata" to be ingested into splunk with a sourcetype of "nagiosperfdata"
Use the latter if using pnp4nagios 🙂
You'll need to update the pnp4nagios script to output the performance data to an additional log file and ingested the new file into splunk with a new sourcetype. This way the performance data log format does not need to change and your rrd graphs will continue to work.
1/ Update the 'Bulk Mode' section within "process_perfdata.pl" as follows:
print_log( "reading $pdfile for bulk update", 2 );
open (SPLUNK, '>>/opt/nagios/var/splunk-nagios-perfdata');
open( PDFILE, "< $pdfile" );
my $count = 0;
while (<PDFILE>) {
$count++;
print_log( "Processing Line $count", 2 );
my @LINE = split(/\t/);
%ENV = (); # cleaning ENV
foreach my $k (@LINE) {
$k =~ /([A-Z 0-9_]+)::(.*)$/;
$ENV{ 'NAGIOS_' . $1 } = $2 if ($2);
}
print SPLUNK "$_\n";
if ( $ENV{NAGIOS_SERVICEPERFDATA} || $ENV{NAGIOS_HOSTPERFDATA} ) {
parse_env();
process_perfdata();
}
else {
print_log( "No Perfdata. Skipping line $count", 2 );
}
}
print_log( "$count Lines processed", 1 );
if ( unlink("$pdfile") == 1 ) {
print_log( "$pdfile deleted", 1 );
}
else {
print_log( "Could not delete $pdfile:$!", 1 );
}
}
else {
print_log( "ERROR: File $opt_b not found", 1 );
}
close (SPLUNK);
}
Note: only the following three new lines should be added to your existing script:
open (SPLUNK, '>>/opt/nagios/var/splunk-nagios-perfdata');
print SPLUNK "$_\n";
close (SPLUNK);
Replace /opt/nagios with the relevant path for your installation 🙂
2/ Update "$SPLUNK_HOME/etc/apps/SplunkForNagios/default/props.conf" with the following new sourcetype:
[nagiosperfdata]
EXTRACT-datatype = DATATYPE::(?P<datatype>[^\t]*)
EXTRACT-src_host = HOSTNAME::(?P<src_host>[^\t]*)
EXTRACT-name = SERVICEDESC::(?P<name>[^\t]*)
EXTRACT-result = SERVICEPERFDATA::(?P<result>[^\t]*)
EXTRACT-process = SERVICECHECKCOMMAND::(?P<process>[^\t]*)
EXTRACT-hoststate = HOSTSTATE::(?P<hoststate>[^\t]*)
EXTRACT-hoststatetype = HOSTSTATETYPE::(?P<hoststatetype>[^\t]*)
EXTRACT-state = SERVICESTATE::(?P<state>[^\t]*)
EXTRACT-statetype = SERVICESTATETYPE::(?P<statetype>\w+)
SHOULD_LINEMERGE = false
TIME_PREFIX = TIMET::
3/ Add the new file "splunk-nagios-perfdata" to be ingested into splunk with a sourcetype of "nagiosperfdata"
4/ Update the dashboards in "$SPLUNK_HOME/etc/apps/SplunkForNagios/default/data/ui/views" and change any occurance of sourcetype="nagiosserviceperf" to sourcetype="nagiosperfdata"
All the best,
Luke 🙂
P.S. The 'CURRENT SERVICE STATE' events are logged to nagios.log at midnight everyday, ie. as they are only logged just once per day they cannot be used for creating performance graphs, hence the requirement to ingest the performance data from the specific log file.
... View more