gossamer has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I'm a relative perl novice. I have the latest version of nagios running on a fc16 server with some legacy nagios scripts from many years ago. I'd like to continue to be able to use these scripts. I believe they are from version v1.0, so the file format for the status.dat file has changed completely.
It used to look something like this:
[1342359584] HOST;gambit;UP;1342120231;1338841399;0;128690206;774112;6 +3789;0;0;1;1;1;1;0;0.00;0;1;1;(Host assumed to be up)
As you probably know, it's now in a form with one value per line, like:
hoststatus { host_name=gambit modified_attributes=0 check_command=check-host-alive check_period= notification_period=24x7 check_interval=5.000000 retry_interval=1.000000 event_handler= has_been_checked=1 should_be_scheduled=1 check_execution_time=0.008 check_latency=0.102 check_type=0 current_state=0 last_hard_state=0 last_event_id=0 current_event_id=0 current_problem_id=0 last_problem_id=0 plugin_output=PING OK - Packet loss = 0%, RTA = 0.31 ms long_plugin_output= performance_data=rta=0.305000ms;3000.000000;5000.000000;0.0000 +00 pl=0%;80;100;0 last_check=1342363276 next_check=1342363586 check_options=0 current_attempt=1 max_attempts=10 state_type=1 last_state_change=1342285983 last_hard_state_change=1342285983 last_time_up=1342363286 last_time_down=0 last_time_unreachable=0 last_notification=0 next_notification=0 no_more_notifications=0 current_notification_number=0 current_notification_id=0 notifications_enabled=1 ...
I've looked through CPAN, but have been unable to find something that can write the nagios log file in its old format so I can continue to use my old perl scripts. Many of the modules there are also very old and probably don't even support the current format.
Does anyone know of a perl module or nagios configuration that can write out the nagios host and service status in the old format? I believe my scripts may be too complex for me to rewrite them to parse the new format.
Otherwise, how do I parse the current log format to tokenize it into their corresponding variables so I can just print out the format I need?
My old scripts look something like this:
sub process_log($) { my $file = shift || NAGIOS_STATUS_LOG; my $rv = { }; open FILE, $file or return $rv; while (my $l = <FILE>) { chomp $l; next if ($l =~ m/^#/); if ($l =~ m/^\[([^\]]+)\]\s+(.+)$/) { my $ts = $1; my $statusline = $2; my @fields = split /\;/, $statusline; my $numfields = @fields; if ($numfields == 21) { my $host = $fields[1]; next unless (want($host)); $rv->{$host}->{' HOSTCHECK'} = { 'status' => $fields[2], 'last_check_time' => $fields[3], 'last_state_change' => $fields[4], 'acknowledged' => $fields[5], 'time_up' => $fields[6], 'time_down' => $fields[7], 'time_unreachable' => $fields[8], 'last_notification_time' => $fields[9], 'current_notification_number' => $fields[10], 'notifications_enabled' => $fields[11], 'event_handlers_enabled' => $fields[12], 'checks_enabled' => $fields[13], 'flap_detection_enabled' => $fields[14], 'host_is_flapping' => $fields[15], 'percent_state_change' => $fields[16], 'scheduled_dd' => $fields[17], 'failure_prediction_enabled' => $fields[18], 'process_perf_data' => $fields[19], 'plugin_output' => $fields[20], } } elsif ($numfields == 32) { my $host = $fields[1]; my $service = $fields[2]; next unless (want($host)); $rv->{$host}->{$service} = { 'status' => $fields[3], 'retry_number' => $fields[4], 'state_type' => $fields[5], 'last_check_time' => $fields[6], 'next_check_time' => $fields[7], 'check_type' => $fields[8], 'checks_enabled' => $fields[9], 'accept_passive_checks' => $fields[10], 'event_handlers_enabled' => $fields[11], 'last_state_change' => $fields[12], 'acknowledged' => $fields[13], 'last_hard_state' => $fields[14], 'time_ok' => $fields[15], 'time_unknown' => $fields[16], 'time_warning' => $fields[17], 'time_critical' => $fields[18], 'last_notification_time' => $fields[19], 'current_notification_number' => $fields[20], 'notifications_enabled' => $fields[21], 'latency' => $fields[22], 'execution_time' => $fields[23], 'flap_detection_enabled' => $fields[24], 'service_is_flapping' => $fields[25], 'percent_state_change' => $fields[26], 'scheduled_dd' => $fields[27], 'failure_prediction_enabled' => $fields[28], 'process_perf_data' => $fields[29], 'obsess_over' => $fields[30], 'plugin_output' => $fields[31], } } } } close FILE; return $rv;
Any help would be greatly appreciated.
Thanks,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing nagios status.dat file
by aitap (Curate) on Jul 15, 2012 at 17:02 UTC |