Nagios...atusLog(3pm)
πΈ NAME πΈ
Nagios::StatusLog, Nagios::(Service|Host|Program)::Status β Perl objects that represent the Nagios status file. π
(also hi, this is the Nagios...atusLog(3pm) page, straight out of User Contributed Perl Documentation, and it ate, fr fr)
π¦ DESCRIPTION π¦
Okay so bestie, here's the whole vibe: this thing reads the Nagios status log and hands you back ::Status objects, which you then use to pull status info about a host. That's it, that's the gig. π«Ά
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. No cap. π
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
);
β¨ METHODS β¨
π
new()
Creates a brand new Nagios::StatusLog instance, and it's already initialized for you (it does this using $self->update()), so you literally don't have to do anything else. π
Nagios::StatusLog->new( "/var/opt/nagios/status.log" );
π
update()
Refreshes the internal data structures from the logfile. Glow-up for your in-memory data. β¨
$log->update();
π
service()
Returns a Nagios::Service::Status object. The input arguments can be a host_name and description list, or a Nagios::Service object. Either way, we got you. π
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_namedescriptionstatuscurrent_attemptstate_typelast_check next_checkcheck_typechecks_enabledaccept_passive_service_checksevent_handler_enabledlast_state_changeproblem_has_been_acknowledgedlast_hard_statetime_okcurrent_notification_numbertime_warningtime_criticalprocess_performance_datanotifications_enabledlatencyscheduled_downtime_depthis_flappingplugin_outputpercent_state_changeexecution_timetime_unknownfailure_prediction_enabledlast_notificationobsess_over_serviceflap_detection_enabled
π
list_services()
Returns an array of all service descriptions in the status log. Heads up though: services that might be listed on more than one host are only listed once here. Not me duplicating entries, couldn't be her. π
my @all_services = $log->list_services;
π
list_services_on_host()
Returns an array of service descriptions for a given host. Iconic behaviour, honestly. π
my @host_services = $log->list_services_on_host($hostname);
my @host_services = $log->list_services_on_host($nagios_object);
π
serviceproblems()
Returns a hash of all the services that are not in an OK state. The drama list. π
my %serviceproblems = $log->serviceproblems();
π
host()
Returns a Nagios::Host::Status object. The input can be a simple host_name, a Nagios::Host object, or a Nagios::Service object β she's flexible like that. πββοΈ
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_namestatuslast_checklast_state_changeproblem_has_been_acknowledgedtime_uptime_downtime_unreachablelast_notificationcurrent_notification_numbernotifications_enabledevent_handler_enabledchecks_enabledflap_detection_enabledis_flappingpercent_state_changescheduled_downtime_depthfailure_prediction_enabledprocess_performance_dataplugin_output
π
list_hosts()
Returns a simple array of host names β no objects, just the names, keepin' it lowkey. π
my @hosts = $log->list_hosts;
π
list_hostdowntime()
Returns a simple array of host downtimes β again, no objects. Just vibes. πΈ
my @hostdowntimes = $log->list_hostdowntime;
π
info() [Nagios v2 & v3 logs only]
Returns a Nagios::Info::Status object. She's minimal β only two methods, created() and version(). Small but mighty. π
my $i = $log->info;
printf "Logfile created at %s unix epoch time for Nagios verion %s\n",
$i->created,
$i->version;
π
contact() [Nagios v3 logs only]
Returns a Nagios::Contact::Status object. The input can be a simple contact_name, or a Nagios::Contact object. π«Ά
my $c = $log->contact( 'john' );
my $c = $log->contact( $contact_object );
Nagios::Contact::Status has the following accessor methods (for v3):
contact_namemodified_attributesmodified_host_attributesmodified_service_attributeshost_notification_periodservice_notification_periodlast_host_notificationlast_service_notificationhost_notifications_enabledservice_notifications_enabled
π
hostcomment() [Nagios v3 logs only]
Returns a Nagios::Hostcomment::Status object. The input can be a simple host_name, or a Nagios::Host or Nagios::Service object. β¨
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_nameentry_typecomment_idsourcepersistententry_timeexpiresexpire_timeauthorcomment_data
π
servicecomment() [Nagios v3 logs only]
Returns a Nagios::Servicecomment::Status object. The input can be a simple host_name or Nagios::Host object with a service description or Nagios::Service object, or just a Nagios::Service object all by itself. Main character energy. π
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_nameservice_descriptionentry_typecomment_idsourcepersistententry_timeexpiresexpire_timeauthorcomment_data
π
hostdowntime() [Nagios v3 logs only]
Returns a Nagios::Hostdowntime::Status object. The input can be a simple host_name, or a Nagios::Host or Nagios::Service object. π
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_namedowntime_identry_timestart_timeend_timetriggered_byfixeddurationauthorcomment
π
servicedowntime() [Nagios v3 logs only]
Returns a Nagios::Servicedowntime::Status object. The input can be a simple host_name or Nagios::Host object with a service description or Nagios::Service object, or just a Nagios::Service object by itself. π¦
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_nameservice_descriptiondowntime_identry_timestart_timeend_timetriggered_byfixeddurationauthorcomment
π
program()
Returns a Nagios::Program::Status object. No arguments, she needs nothing from you. π
my $prog_st = $log->program;
Nagios::Program::Status has the following accessor methods (For V1):
program_startnagios_piddaemon_modelast_command_checklast_log_rotationenable_notificationsexecute_service_checksaccept_passive_service_checksenable_event_handlersobsess_over_servicesenable_flap_detectionenable_failure_predictionprocess_performance_data
π§ STRUCTURE π§
So 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. And here's the slay part: 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. Bestie behaviour, honestly. π«Ά
π AUTHOR π
Al Tobey <tobeya@tobert.org>
π SEE ALSO π
okay bestie, if you wanna go further down the rabbit hole (and you know you do πβ¨), these are the sibling modules you're gonna want in your tabs:
Nagios::Hostβ for when the thing you're obsessing over is a host π₯οΈNagios::Serviceβ for when it's a service, obviously π
that's it. that's the whole cross-reference section. go read them, they're right there, they match this one's energy fr fr π«Ά
and that's a wrap on the whole page, bestie!! π you made it to the end, which is honestly iconic of you π
quick lil receipts for the record: this was rendered by perl v5.34.0, dated 2022-06-16, and the module itself is Nagios::StatusLog(3pm) β the page that lives in the User Contributed Perl Documentation section π¦
now go check your status logs and slay πβ¨πΈ
π¦ where this page comes from
- debian bookworm: libnagios-object-perl 0.21.20-3 Β· GPL-2.0-or-later
- debian trixie: libnagios-object-perl 0.21.20-3 Β· GPL-2.0-or-later
- ubuntu noble: libnagios-object-perl 0.21.20-3 Β· GPL-2.0-or-later
- ubuntu resolute: libnagios-object-perl 0.21.20-3 Β· GPL-2.0-or-later
- ubuntu stonking: libnagios-object-perl 0.21.20-3 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms