aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-10-05 09:03:52 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-10-05 09:03:52 +1300
commit1bfee940dee1eec591700877318b4caadc3c9502 (patch)
tree30b9162cfe60e8ed36ef2894c4f12bf30bbfae41
parentRemove a doubled "the" (diff)
downloadList-Breakdown-1bfee940dee1eec591700877318b4caadc3c9502.tar.gz
List-Breakdown-1bfee940dee1eec591700877318b4caadc3c9502.zip
Add another example
Needs to be tested
-rw-r--r--lib/List/Breakdown.pm77
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/List/Breakdown.pm b/lib/List/Breakdown.pm
index 5814a9c..aab5afb 100644
--- a/lib/List/Breakdown.pm
+++ b/lib/List/Breakdown.pm
@@ -134,6 +134,83 @@ This puts the following structure in C<%filtered>:
has_ba => ['bar', 'baz'],
)
+=head1 EXAMPLES
+
+=head2 Monitoring system check results
+
+Suppose you ran a list of checks with your monitoring system, and you have a
+list of hashrefs describing each check and its outcome:
+
+ my @checks = (
+ {
+ hostname => 'webserver1',
+ status => 'OK',
+ },
+ {
+ hostname => 'webserver2',
+ status => 'CRITICAL',
+ },
+ {
+ hostname => 'webserver3',
+ status => 'WARNING',
+ },
+ {
+ hostname => 'webserver4',
+ status => 'OK',
+ }
+ );
+
+You would like to break the list down by status. Using C<List::Breakdown>, you
+would lay out your buckets like so:
+
+ my %buckets = (
+ ok => sub { $_->{status} eq 'OK' },
+ problem => {
+ warning => sub { $_->{status} eq 'WARNING' },
+ critical => sub { $_->{status} eq 'CRITICAL' },
+ unknown => sub { $_->{status} eq 'UNKNOWN' },
+ },
+ );
+
+And apply them like so:
+
+ my %results = breakdown \%buckets, $checks;
+
+For our sample data above, this would yield the following structure in
+C<%results>:
+
+ (
+ ok => [
+ {
+ hostname => 'webserver1',
+ status => 'OK'
+ },
+ {
+ hostname => 'webserver4',
+ status => 'OK'
+ }
+ ],
+ problem => {
+ warning => [
+ {
+ hostname => 'webserver3',
+ status => 'WARNING'
+ }
+ ],
+ critical => [
+ {
+ hostname => 'webserver2',
+ status => 'CRITICAL'
+ }
+ },
+ unknown => []
+ }
+ )
+
+Notice that some of the check results appear in more than one list, and the
+hash buckets are arranged the same way they were in the spec, including an
+extra level of hash references.
+
=head1 SUBROUTINES/METHODS
=head2 B<breakdown(\%spec, @items)>