9
use Zabbix::API::Trigger;
12
use Zabbix::API::TestUtils;
14
if ($ENV{ZABBIX_SERVER}) {
20
plan skip_all => 'Needs an URL in $ENV{ZABBIX_SERVER} to run tests.';
24
use_ok('Zabbix::API::Action');
25
use Zabbix::API::Action qw/ACTION_EVENTSOURCE_TRIGGERS ACTION_CONDITION_TYPE_TRIGGER_NAME ACTION_CONDITION_OPERATOR_LIKE ACTION_OPERATION_TYPE_MESSAGE ACTION_EVAL_TYPE_AND/;
27
my $zabber = Zabbix::API::TestUtils::canonical_login;
29
my $actions = $zabber->fetch('Action', params => { search => { name => 'Auto discovery. Linux servers.' } });
31
is(@{$actions}, 1, '... and an action known to exist can be fetched');
33
my $action = $actions->[0];
35
isa_ok($action, 'Zabbix::API::Action',
36
'... and that action');
39
'... and it returns true to existence tests');
41
my $new_trigger = Zabbix::API::Trigger->new(root => $zabber,
42
data => { description => 'Another Trigger',
43
expression => '{Zabbix Server:system.uptime.last(0)}<600', });
47
my $new_action = Zabbix::API::Action->new(root => $zabber,
48
data => { name => 'Another Action',
49
eventsource => ACTION_EVENTSOURCE_TRIGGERS,
50
evaltype => ACTION_EVAL_TYPE_AND,
51
conditions => [ { conditiontype => ACTION_CONDITION_TYPE_TRIGGER_NAME,
52
operator => ACTION_CONDITION_OPERATOR_LIKE,
53
value => $new_trigger->data->{description} } ],
54
operations => [ { operationtype => ACTION_OPERATION_TYPE_MESSAGE,
55
shortdata => '{TRIGGER.NAME}: {STATUS}',
56
longdata => '{TRIGGER.NAME}: {STATUS}' } ]
59
isa_ok($new_action, 'Zabbix::API::Action',
60
'... and an action created manually');
62
eval { $new_action->push };
64
if ($@) { diag "Caught exception: $@" };
66
ok($new_action->created,
67
'... and pushing it to the server creates a new action');
69
my $actions_again = $zabber->fetch('Action', params => { search => { name => 'Another Action' } });
71
is(@{$actions_again}, 1, '... and the just-created action can be fetched');
73
eval { $new_action->delete };
76
if ($@) { diag "Caught exception: $@" };
78
ok(!$new_action->created,
79
'... and calling its delete method removes it from the server');
81
eval { $zabber->logout };