Subject: | Function to return all services |
Similar to #74901, a function should exist to return all services. I've
attached a patch that adds and accessor to return all services.
Subject: | patch.diff |
diff -r 8817b9807ede lib/Nagios/Status/ServiceStatus.pm
--- a/lib/Nagios/Status/ServiceStatus.pm Sun Feb 12 12:12:10 2012 -0800
+++ b/lib/Nagios/Status/ServiceStatus.pm Sun Feb 12 14:28:17 2012 -0800
@@ -27,6 +27,9 @@
# OR
my $status = Nagios::Status::ServiceStatus->new($nagios_status_log_path, $serv1, $serv2, ...);
+ # Get all services.
+ my $services = $status->services;
+
# Get services that are up.
my $ok = $status->check_ok;
@@ -65,7 +68,8 @@
my $self = {
status_log => shift,
};
-
+
+ $self->{services} = ();
$self->{ok} = ();
$self->{warning} = ();
$self->{unknown} = ();
@@ -91,6 +95,7 @@
my $service = Nagios::Status::Service->new($self->{status_log}, $_);
if (defined $service) {
+ push @{$self->{services}}, $service;
if ($service->is_warning) {
push @{ $self->{warning} }, $service;
} elsif ($service->is_unknown) {
@@ -123,6 +128,7 @@
} # if
if ($found and $line =~ /}/) {
+ push @{$self->{services}}, $service;
if ($service->is_warning) {
push @{ $self->{warning} }, $service;
} elsif ($service->is_unknown) {
@@ -155,6 +161,25 @@
=over 4
+=item services
+
+ my $servs = $status->services;
+
+This method takes no parameters. It returns an array reference
+to all services. Otherwise, it returns undefined.
+
+=cut
+
+sub services {
+ my ($self) = @_;
+
+ if ($self->{services}) {
+ return $self->{services};
+ } else {
+ return undef;
+ } # if/else
+}
+
=item check_ok
my $servs_ok = $status->check_ok;