~ubuntu-branches/ubuntu/vivid/libzabbix-api-perl/vivid

« back to all changes in this revision

Viewing changes to t/actions.t

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-08-11 04:26:46 UTC
  • Revision ID: package-import@ubuntu.com-20120811042646-le16xahtf2pjzxuv
Tags: upstream-0.004+git20120629
ImportĀ upstreamĀ versionĀ 0.004+git20120629

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use strict;
 
2
use warnings;
 
3
 
 
4
use Test::More;
 
5
use Test::Exception;
 
6
use Data::Dumper;
 
7
 
 
8
use Zabbix::API;
 
9
use Zabbix::API::Trigger;
 
10
 
 
11
use lib 't/lib';
 
12
use Zabbix::API::TestUtils;
 
13
 
 
14
if ($ENV{ZABBIX_SERVER}) {
 
15
 
 
16
    plan tests => 8;
 
17
 
 
18
} else {
 
19
 
 
20
    plan skip_all => 'Needs an URL in $ENV{ZABBIX_SERVER} to run tests.';
 
21
 
 
22
}
 
23
 
 
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/;
 
26
 
 
27
my $zabber = Zabbix::API::TestUtils::canonical_login;
 
28
 
 
29
my $actions = $zabber->fetch('Action', params => { search => { name => 'Auto discovery. Linux servers.' } });
 
30
 
 
31
is(@{$actions}, 1, '... and an action known to exist can be fetched');
 
32
 
 
33
my $action = $actions->[0];
 
34
 
 
35
isa_ok($action, 'Zabbix::API::Action',
 
36
       '... and that action');
 
37
 
 
38
ok($action->created,
 
39
   '... and it returns true to existence tests');
 
40
 
 
41
my $new_trigger = Zabbix::API::Trigger->new(root => $zabber,
 
42
                                            data => { description => 'Another Trigger',
 
43
                                                      expression => '{Zabbix Server:system.uptime.last(0)}<600', });
 
44
 
 
45
$new_trigger->push;
 
46
 
 
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}' } ]
 
57
                                                    });
 
58
 
 
59
isa_ok($new_action, 'Zabbix::API::Action',
 
60
       '... and an action created manually');
 
61
 
 
62
eval { $new_action->push };
 
63
 
 
64
if ($@) { diag "Caught exception: $@" };
 
65
 
 
66
ok($new_action->created,
 
67
   '... and pushing it to the server creates a new action');
 
68
 
 
69
my $actions_again = $zabber->fetch('Action', params => { search => { name => 'Another Action' } });
 
70
 
 
71
is(@{$actions_again}, 1, '... and the just-created action can be fetched');
 
72
 
 
73
eval { $new_action->delete };
 
74
$new_trigger->delete;
 
75
 
 
76
if ($@) { diag "Caught exception: $@" };
 
77
 
 
78
ok(!$new_action->created,
 
79
   '... and calling its delete method removes it from the server');
 
80
 
 
81
eval { $zabber->logout };