Subject: | Function to return all hosts |
There should be a method of returning all hosts at once, independent of
host status. I've attached a small patch against v0.01 that adds all
hosts to an array and adds an accessor to return all hosts -- along with
necessary POD updates.
Subject: | patch.diff |
diff -r 18519838cafa lib/Nagios/Status/HostStatus.pm
--- a/lib/Nagios/Status/HostStatus.pm Sun Feb 12 12:21:08 2012 -0800
+++ b/lib/Nagios/Status/HostStatus.pm Sun Feb 12 13:39:29 2012 -0800
@@ -27,6 +27,9 @@
# OR
my $status = Nagios::Status::HostStatus->new($nagios_status_log_path, $host1, $host2, ...);
+ # Get all hosts
+ my $hosts = $status->hosts;
+
# Get hosts that are up.
my $up = $status->check_up;
@@ -63,6 +66,7 @@
status_log => shift,
};
+ $self->{hosts} = ();
$self->{up} = ();
$self->{down} = ();
$self->{unreachable} = ();
@@ -87,6 +91,7 @@
my $host = Nagios::Status::Host->new($self->{status_log}, $_);
if (defined $host) {
+ push @{$self->{hosts}}, $host;
if ($host->is_down) {
push @{ $self->{down} }, $host;
} elsif ($host->is_unreachable) {
@@ -117,6 +122,7 @@
} # if
if ($found and $line =~ /}/) {
+ push @{$self->{hosts}}, $host;
if ($host->is_down) {
push @{ $self->{down} }, $host;
} elsif ($host->is_unreachable) {
@@ -147,6 +153,27 @@
=over 4
+=item hosts
+
+ my $hosts = $status->hosts;
+
+This method takes no parameters. It returns an array reference
+to all hosts found. Otherwise, it returns undefined.
+
+=cut
+
+sub hosts {
+ my ($self) = @_;
+
+ if ($self->{hosts}) {
+ return $self->{hosts};
+ } else {
+ return undef;
+ }
+}
+
+=pod
+
=item check_up
my $hosts_up = $status->check_up;