Nagios::StatusLog(3pm) | User Contributed Perl Documentation | Nagios::StatusLog(3pm) |
Nagios::StatusLog, Nagios::(Service|Host|Program)::Status - Perl objects to represent the Nagios status file
Reads the Nagios status log and returns ::Status objects that can be used to get status information about a host. For Nagios version 2.x logs, pass in the Version => 2.0 parameter to new(). And similarly, pass in the Version => 3.0 parameter to new() for Nagios version 3.x logs.
my $log = Nagios::StatusLog->new( Filename => "/var/opt/nagios/status.log", Version => 1.0 ); $localhost = $log->host( "localhost" ); print "status of localhost is now ",$localhost->status(),"\n"; $log->update(); print "status of localhost is now ",$localhost->status(),"\n"; # for Nagios v2.0 my $log = Nagios::StatusLog->new( Filename => "/var/cache/nagios2/status.dat", Version => 2.0 ); # for Nagios v3.0 my $log = Nagios::StatusLog->new( Filename => "/var/cache/nagios3/status.dat", Version => 3.0 );
my $svc_stat = $log->service( "localhost", "SSH" ); my $svc_stat = $log->service( $localhost_ssh_svc_object );
Nagios::Service::Status has the following accessor methods
(For V1):
host_name
description
status
current_attempt
state_type
last_check next_check
check_type
checks_enabled
accept_passive_service_checks
event_handler_enabled
last_state_change
problem_has_been_acknowledged
last_hard_state
time_ok
current_notification_number
time_warning
time_critical
process_performance_data
notifications_enabled
latency
scheduled_downtime_depth
is_flapping
plugin_output
percent_state_change
execution_time
time_unknown
failure_prediction_enabled
last_notification
obsess_over_service
flap_detection_enabled
my @all_services = $log->list_services;
my @host_services = $log->list_services_on_host($hostname); my @host_services = $log->list_services_on_host($nagios_object);
my %serviceproblems = $log->serviceproblems();
my $hst_stat = $log->host( 'localhost' ); my $hst_stat = $log->host( $host_object ); my $hst_stat = $log->host( $svc_object );
Nagios::Host::Status has the following accessor methods (for
V1):
host_name
status
last_check
last_state_change
problem_has_been_acknowledged
time_up
time_down
time_unreachable
last_notification
current_notification_number
notifications_enabled
event_handler_enabled
checks_enabled
flap_detection_enabled
is_flapping
percent_state_change
scheduled_downtime_depth
failure_prediction_enabled
process_performance_data
plugin_output
my @hosts = $log->list_hosts;
my @hostdowntimes = $log->list_hostdowntime;
my $i = $log->info; printf "Logfile created at %s unix epoch time for Nagios verion %s\n", $i->created, $i->version;
my $c = $log->contact( 'john' ); my $c = $log->contact( $contact_object );
Nagios::Contact::Status has the following accessor methods
(for v3):
contact_name
modified_attributes
modified_host_attributes
modified_service_attributes
host_notification_period
service_notification_period
last_host_notification
last_service_notification
host_notifications_enabled
service_notifications_enabled
my $c = $log->hostcomment( 'localhost' ); my $c = $log->hostcomment( $localhost_object ); my $c = $log->hostcomment( $localhost_service_object ); foreach my $id (sort keys %$c) { printf "Host %s has a comment[$id] made by %s on %s: %s", $c->{$id}->host_name, $c->{$id}->author, scalar localtime $c->{$id}->entry_time, $c->{$id}->comment_data; }
Nagios::Hostcomment::Status is a perl HASH, keyed with the
Nagios comment IDs, where each ID has the following accessor methods
(for v3):
host_name
entry_type
comment_id
source
persistent
entry_time
expires
expire_time
author
comment_data
my $c = $log->servicecomment( 'localhost', 'SSH' ); my $c = $log->servicecomment( $localhost_object, $localhost_ssh_svc_object ); my $c = $log->servicecomment( $localhost_ssh_svc_object ); foreach my $id (sort keys %$c) { printf "Service %s on %s has a comment[$id] made by %s on %s: %s", $c->{$id}->service_description, $c->{$id}->host_name, $c->{$id}->author, scalar localtime $c->{$id}->entry_time, $c->{$id}->comment_data; }
Nagios::Servicecomment::Status is a perl HASH, keyed with the
Nagios comment IDs, where each ID has the following accessor methods
(for v3):
host_name
service_description
entry_type
comment_id
source
persistent
entry_time
expires
expire_time
author
comment_data
my $d = $log->hostdowntime( 'localhost' ); my $d = $log->hostdowntime( $localhost_object ); my $d = $log->hostdowntime( $localhost_service_object ); foreach my $id (sort keys %$d) { printf "Host %s has scheduled downtime[$id] made by %s on %s for %.1f hours [%s - %s]: %s", $d->{$id}->host_name, $d->{$id}->author, scalar localtime $d->{$id}->entry_time, ($d->{$id}->duration)/3600.0, scalar localtime $d->{$id}->start_time, scalar localtime $d->{$id}->end_time, $d->{$id}->comment; }
Nagios::Hostdowntime::Status is a perl HASH, keyed with the
Nagios downtime IDs, where each ID has the following accessor methods
(for v3):
host_name
downtime_id
entry_time
start_time
end_time
triggered_by
fixed
duration
author
comment
my $c = $log->servicedowntime( 'localhost', 'SSH' ); my $c = $log->servicedowntime( $localhost_object, $localhost_ssh_svc_object ); my $c = $log->servicedowntime( $localhost_ssh_svc_object ); foreach my $id (sort keys %$d) { printf "Service %s on %s has scheduled downtime[$id] made by %s on %s for %.1f hours [%s - %s]: %s", $d->{$id}->service_description, $d->{$id}->host_name, $d->{$id}->author, scalar localtime $d->{$id}->entry_time, ($d->{$id}->duration)/3600.0, scalar localtime $d->{$id}->start_time, scalar localtime $d->{$id}->end_time, $d->{$id}->comment; }
Nagios::Servicedowntime::Status is a perl HASH, keyed with the
Nagios downtime IDs, where each ID has the following accessor methods
(for v3):
host_name
service_description
downtime_id
entry_time
start_time
end_time
triggered_by
fixed
duration
author
comment
my $prog_st = $log->program;
Nagios::Program::Status has the following accessor methods
(For V1):
program_start
nagios_pid
daemon_mode
last_command_check
last_log_rotation
enable_notifications
execute_service_checks
accept_passive_service_checks
enable_event_handlers
obsess_over_services
enable_flap_detection
enable_failure_prediction
process_performance_data
This module contains 4 packages: Nagios::StatusLog, Nagios::Host::Status, Nagios::Service::Status, and Nagios::Program::Status. The latter 3 of them are mostly generated at compile-time in the BEGIN block. The accessor methods are real subroutines, not AUTOLOAD, so making a ton of calls to this module should be fairly quick. Also, update() is set up to only do what it says - updating from a fresh logfile should not invalidate your existing ::Status objects.
Al Tobey <tobeya@tobert.org>
Nagios::Host Nagios::Service
2022-06-16 | perl v5.34.0 |