1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#!perl -T
use strict;
use warnings;
use utf8;
use Test::More tests => 1;
use List::Breakdown 'breakdown';
our $VERSION = '0.25';
my @checks = (
{
hostname => 'webserver1',
status => 'OK',
},
{
hostname => 'webserver2',
status => 'CRITICAL',
},
{
hostname => 'webserver3',
status => 'WARNING',
},
{
hostname => 'webserver4',
status => 'OK',
},
);
my %buckets = (
ok => sub { $_->{status} eq 'OK' },
problem => {
warning => sub { $_->{status} eq 'WARNING' },
critical => sub { $_->{status} eq 'CRITICAL' },
unknown => sub { $_->{status} eq 'UNKNOWN' },
},
);
my %results = breakdown \%buckets, @checks;
my %expected = (
ok => [
{
hostname => 'webserver1',
status => 'OK',
},
{
hostname => 'webserver4',
status => 'OK',
},
],
problem => {
warning => [
{
hostname => 'webserver3',
status => 'WARNING',
},
],
critical => [
{
hostname => 'webserver2',
status => 'CRITICAL',
},
],
unknown => [],
},
);
is_deeply( \%results, \%expected, 'monitoring' );
|