---
name: "Nagios::StatusLog"
section: "3pm"
platform: "linux"
package: "libnagios-object-perl"
version: "0.21.20-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Nagios::StatusLog"
---

# Nagios::StatusLog(3pm)

Perl objects to represent the Nagios status file

## NAME

Nagios::StatusLog, Nagios::(Service\|Host\|Program)::Status - Perl objects to represent the Nagios status file

## DESCRIPTION

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
           );
```

## METHODS

- **new()**

  Create a new Nagios::StatusLog instance.  The object will be initialized for you (using `$self`-\>**update()**).\
    Nagios::StatusLog-\>new( "/var/opt/nagios/status.log" );

- **update()**

  Updates the internal data structures from the logfile.\
    `$log`-\>**update()**;

- **service()**

  Returns a Nagios::Service::Status object.  Input arguments can be a host\_name and description list, or a Nagios::Service object.

  ```
   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

- **list\_services()**

  Returns an array of all service descriptions in the status log.  Services that may be listed on more than one host are only listed once here.

  ```
   my @all_services = $log->list_services;
  ```

- **list\_services\_on\_host()**

  Returns an array of services descriptions for a given host.

  ```
   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 services that are not in an OK state

  ```
   my %serviceproblems = $log->serviceproblems();
  ```

- **host()**

  Returns a Nagios::Host::Status object.  Input can be a simple host\_name, a Nagios::Host object, or a Nagios::Service object.

  ```
   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

- **list\_hosts()**

  Returns a simple array of host names (no objects).

  ```
   my @hosts = $log->list_hosts;
  ```

- **list\_hostdowntime()**

  Returns a simple array of host downtimes (no objects)

  ```
   my @hostdowntimes = $log->list_hostdowntime;
  ```

- **info()** \[Nagios v2 & v3 logs only\]

  Returns a Nagios::Info::Status object.   It only has two methods, **created()** and **version()**.

  ```
   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.  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\_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

- **hostcomment()** \[Nagios v3 logs only\]

  Returns a Nagios::Hostcomment::Status object.  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\_name\
    entry\_type\
    comment\_id\
    source\
    persistent\
    entry\_time\
    expires\
    expire\_time\
    author\
    comment\_data

- **servicecomment()** \[Nagios v3 logs only\]

  Returns a Nagios::Servicecomment::Status object.  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->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

- **hostdowntime()** \[Nagios v3 logs only\]

  Returns a Nagios::Hostdowntime::Status object.  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\_name\
    downtime\_id\
    entry\_time\
    start\_time\
    end\_time\
    triggered\_by\
    fixed\
    duration\
    author\
    comment

- **servicedowntime()** \[Nagios v3 logs only\]

  Returns a Nagios::Servicedowntime::Status object.  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\_name\
    service\_description\
    downtime\_id\
    entry\_time\
    start\_time\
    end\_time\
    triggered\_by\
    fixed\
    duration\
    author\
    comment

- **program()**

  Returns a Nagios::Program::Status object. No arguments.

  ```
   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

## STRUCTURE

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.

## AUTHOR

Al Tobey \<tobeya@tobert.org\>

## SEE ALSO

Nagios::Host Nagios::Service
