5
use_ok('Monitoring::Livestatus::Class::Abstract::Filter');
9
[[{ name => undef }], { name => 'localhost' }, []], ["Filter: name =", "Filter: name = localhost"],
10
{ name => undef }, ["Filter: name ="],
11
{ name => 'localhost' }, ["Filter: name = localhost"],
12
{ name => 'localhost', service => 'ping' }, [ "Filter: name = localhost", "Filter: service = ping" ],
13
{ name => [qw/localhost router/] }, [ "Filter: name = localhost", "Filter: name = router" ],
15
{ name => 'localhost' },
17
], [ "Filter: name = localhost", "Filter: name = router" ],
18
# not supported at the moment
19
{ name => { '-or' => [ qw/localhost router/] } },[ "Filter: name = localhost", "Filter: name = router", "Or: 2" ],
21
scheduled_downtime_depth => { '>' => '0' },
22
host_scheduled_downtime_depth => { '>' => '0'},
24
},['Filter: scheduled_downtime_depth > 0','Filter: host_scheduled_downtime_depth > 0','Or: 2'],
27
'-and' => { state => '2', acknowledged => '1', },
30
},['Filter: acknowledged = 1', 'Filter: state = 2', 'And: 2', 'Filter: state = 0', 'Or: 2'],
33
{ host_has_been_checked => 0, },
37
host_has_been_checked => 1,
43
host_has_been_checked => 1,
47
},['Filter: host_has_been_checked = 0','Filter: host_state = 1','Filter: host_has_been_checked = 1','And: 2','Filter: host_state = 2','Filter: host_has_been_checked = 1','And: 2','Or: 3',],
50
{ host_has_been_checked => 0, },
54
host_has_been_checked => 1,
60
host_has_been_checked => 1,
65
scheduled_downtime_depth => { '>' => '0' },
66
scheduled_downtime_depth => 0,
67
acknowledged => [qw/0 1/],
68
checks_enabled => [qw/0 1/],
69
event_handler_enabled => [qw/0 1/],
70
flap_detection_enabled => [qw/0 1/],
71
is_flapping => [qw/0 1/],
72
notifications_enabled => [qw/0 1/],
73
accept_passive_checks => [qw/0 1/],
76
'Filter: host_has_been_checked = 0',
77
'Filter: host_state = 1',
78
'Filter: host_has_been_checked = 1',
80
'Filter: host_state = 3',
81
'Filter: host_has_been_checked = 1',
84
'Filter: scheduled_downtime_depth > 0',
85
'Filter: scheduled_downtime_depth = 0',
86
'Filter: acknowledged = 0',
87
'Filter: acknowledged = 1',
88
'Filter: checks_enabled = 0',
89
'Filter: checks_enabled = 1',
90
'Filter: event_handler_enabled = 0',
91
'Filter: event_handler_enabled = 1',
92
'Filter: flap_detection_enabled = 0',
93
'Filter: flap_detection_enabled = 1',
94
'Filter: is_flapping = 0',
95
'Filter: is_flapping = 1',
96
'Filter: notifications_enabled = 0',
97
'Filter: notifications_enabled = 1',
98
'Filter: accept_passive_checks = 0',
99
'Filter: accept_passive_checks = 1',
102
# Simple operator tests
103
{ name => { '=' => [ qw/localhost router/] } },[ "Filter: name = localhost", "Filter: name = router" ],
104
{ name => { '~' => [ qw/localhost router/] } },[ "Filter: name ~ localhost", "Filter: name ~ router" ],
105
{ name => { '~=' => [ qw/localhost router/] } },[ "Filter: name ~= localhost", "Filter: name ~= router" ],
106
{ name => { '~~' => [ qw/localhost router/] } },[ "Filter: name ~~ localhost", "Filter: name ~~ router" ],
107
{ name => { '<' => [ qw/localhost router/] } },[ "Filter: name < localhost", "Filter: name < router" ],
108
{ name => { '>' => [ qw/localhost router/] } },[ "Filter: name > localhost", "Filter: name > router" ],
109
{ name => { '<=' => [ qw/localhost router/] } },[ "Filter: name <= localhost", "Filter: name <= router" ],
110
{ name => { '>=' => [ qw/localhost router/] } },[ "Filter: name >= localhost", "Filter: name >= router" ],
111
{ host_scheduled_downtime_depth => { '>' => 0 } },[ "Filter: host_scheduled_downtime_depth > 0" ],
114
for ( my $i = 0 ; $i < scalar @testings ; $i++ ) {
115
my $search = $testings[$i];
116
my $expected_statment = $testings[ ++$i ];
117
my $filter_obj = Monitoring::Livestatus::Class::Abstract::Filter->new();
120
$got_statment = $filter_obj->apply($search);
122
is_deeply( $got_statment, $expected_statment,
123
sprintf( "Test %d - %s", ( $i / 2 ) + 1 , join " ",@{ $expected_statment } ));