This file is indexed.

/usr/share/perl5/Zabbix/API/Action.pm is in libzabbix-api-perl 0.009-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
package Zabbix::API::Action;

use strict;
use warnings;
use 5.010;
use Carp;

use parent qw/Exporter Zabbix::API::CRUDE/;

use constant {
    ACTION_EVENTSOURCE_TRIGGERS => 0,
    ACTION_EVENTSOURCE_DISCOVERY => 1,
    ACTION_EVENTSOURCE_AUTOREGISTRATION => 2,

    ACTION_CONDITION_TYPE_HOST_GROUP => 0,
    ACTION_CONDITION_TYPE_HOST => 1,
    ACTION_CONDITION_TYPE_TRIGGER => 2,
    ACTION_CONDITION_TYPE_TRIGGER_NAME => 3,
    ACTION_CONDITION_TYPE_TRIGGER_SEVERITY => 4,
    ACTION_CONDITION_TYPE_TRIGGER_VALUE => 5,
    ACTION_CONDITION_TYPE_TIME_PERIOD => 6,
    ACTION_CONDITION_TYPE_DHOST_IP => 7,
    ACTION_CONDITION_TYPE_DSERVICE_TYPE => 8,
    ACTION_CONDITION_TYPE_DSERVICE_PORT => 9,
    ACTION_CONDITION_TYPE_DSTATUS => 10,
    ACTION_CONDITION_TYPE_DUPTIME => 11,
    ACTION_CONDITION_TYPE_DVALUE => 12,
    ACTION_CONDITION_TYPE_HOST_TEMPLATE => 13,
    ACTION_CONDITION_TYPE_EVENT_ACKNOWLEDGED => 14,
    ACTION_CONDITION_TYPE_APPLICATION => 15,
    ACTION_CONDITION_TYPE_MAINTENANCE => 16,
    ACTION_CONDITION_TYPE_NODE => 17,
    ACTION_CONDITION_TYPE_DRULE => 18,
    ACTION_CONDITION_TYPE_DCHECK => 19,
    ACTION_CONDITION_TYPE_PROXY => 20,
    ACTION_CONDITION_TYPE_DOBJECT => 21,
    ACTION_CONDITION_TYPE_HOST_NAME => 22,

    ACTION_CONDITION_OPERATOR_EQUAL => 0,
    ACTION_CONDITION_OPERATOR_NOT_EQUAL => 1,
    ACTION_CONDITION_OPERATOR_LIKE => 2,
    ACTION_CONDITION_OPERATOR_NOT_LIKE => 3,
    ACTION_CONDITION_OPERATOR_IN => 4,
    ACTION_CONDITION_OPERATOR_MORE_EQUAL => 5,
    ACTION_CONDITION_OPERATOR_LESS_EQUAL => 6,
    ACTION_CONDITION_OPERATOR_NOT_IN => 7,

    ACTION_OPERATION_TYPE_MESSAGE => 0,
    ACTION_OPERATION_TYPE_COMMAND => 1,
    ACTION_OPERATION_TYPE_HOST_ADD => 2,
    ACTION_OPERATION_TYPE_HOST_REMOVE => 3,
    ACTION_OPERATION_TYPE_GROUP_ADD => 4,
    ACTION_OPERATION_TYPE_GROUP_REMOVE => 5,
    ACTION_OPERATION_TYPE_TEMPLATE_ADD => 6,
    ACTION_OPERATION_TYPE_TEMPLATE_REMOVE => 7,
    ACTION_OPERATION_TYPE_HOST_ENABLE => 8,
    ACTION_OPERATION_TYPE_HOST_DISABLE => 9,

    ACTION_EVAL_TYPE_AND_OR => 0,
    ACTION_EVAL_TYPE_AND => 1,
    ACTION_EVAL_TYPE_OR => 2,
};

our @EXPORT_OK = qw/
ACTION_EVENTSOURCE_TRIGGERS
ACTION_EVENTSOURCE_DISCOVERY
ACTION_EVENTSOURCE_AUTOREGISTRATION
ACTION_CONDITION_TYPE_HOST_GROUP
ACTION_CONDITION_TYPE_HOST
ACTION_CONDITION_TYPE_TRIGGER
ACTION_CONDITION_TYPE_TRIGGER_NAME
ACTION_CONDITION_TYPE_TRIGGER_SEVERITY
ACTION_CONDITION_TYPE_TRIGGER_VALUE
ACTION_CONDITION_TYPE_TIME_PERIOD
ACTION_CONDITION_TYPE_DHOST_IP
ACTION_CONDITION_TYPE_DSERVICE_TYPE
ACTION_CONDITION_TYPE_DSERVICE_PORT
ACTION_CONDITION_TYPE_DSTATUS
ACTION_CONDITION_TYPE_DUPTIME
ACTION_CONDITION_TYPE_DVALUE
ACTION_CONDITION_TYPE_HOST_TEMPLATE
ACTION_CONDITION_TYPE_EVENT_ACKNOWLEDGED
ACTION_CONDITION_TYPE_APPLICATION
ACTION_CONDITION_TYPE_MAINTENANCE
ACTION_CONDITION_TYPE_NODE
ACTION_CONDITION_TYPE_DRULE
ACTION_CONDITION_TYPE_DCHECK
ACTION_CONDITION_TYPE_PROXY
ACTION_CONDITION_TYPE_DOBJECT
ACTION_CONDITION_TYPE_HOST_NAME
ACTION_CONDITION_OPERATOR_EQUAL
ACTION_CONDITION_OPERATOR_NOT_EQUAL
ACTION_CONDITION_OPERATOR_LIKE
ACTION_CONDITION_OPERATOR_NOT_LIKE
ACTION_CONDITION_OPERATOR_IN
ACTION_CONDITION_OPERATOR_MORE_EQUAL
ACTION_CONDITION_OPERATOR_LESS_EQUAL
ACTION_CONDITION_OPERATOR_NOT_IN
ACTION_OPERATION_TYPE_MESSAGE
ACTION_OPERATION_TYPE_COMMAND
ACTION_OPERATION_TYPE_HOST_ADD
ACTION_OPERATION_TYPE_HOST_REMOVE
ACTION_OPERATION_TYPE_GROUP_ADD
ACTION_OPERATION_TYPE_GROUP_REMOVE
ACTION_OPERATION_TYPE_TEMPLATE_ADD
ACTION_OPERATION_TYPE_TEMPLATE_REMOVE
ACTION_OPERATION_TYPE_HOST_ENABLE
ACTION_OPERATION_TYPE_HOST_DISABLE
ACTION_EVAL_TYPE_AND_OR
ACTION_EVAL_TYPE_AND
ACTION_EVAL_TYPE_OR/;

our %EXPORT_TAGS = (
    eventsources => [
        qw/ACTION_EVENTSOURCE_TRIGGERS
        ACTION_EVENTSOURCE_DISCOVERY
        ACTION_EVENTSOURCE_AUTOREGISTRATION/
    ],
    condition_types => [
        qw/ACTION_CONDITION_TYPE_HOST_GROUP
        ACTION_CONDITION_TYPE_HOST
        ACTION_CONDITION_TYPE_TRIGGER
        ACTION_CONDITION_TYPE_TRIGGER_NAME
        ACTION_CONDITION_TYPE_TRIGGER_SEVERITY
        ACTION_CONDITION_TYPE_TRIGGER_VALUE
        ACTION_CONDITION_TYPE_TIME_PERIOD
        ACTION_CONDITION_TYPE_DHOST_IP
        ACTION_CONDITION_TYPE_DSERVICE_TYPE
        ACTION_CONDITION_TYPE_DSERVICE_PORT
        ACTION_CONDITION_TYPE_DSTATUS
        ACTION_CONDITION_TYPE_DUPTIME
        ACTION_CONDITION_TYPE_DVALUE
        ACTION_CONDITION_TYPE_HOST_TEMPLATE
        ACTION_CONDITION_TYPE_EVENT_ACKNOWLEDGED
        ACTION_CONDITION_TYPE_APPLICATION
        ACTION_CONDITION_TYPE_MAINTENANCE
        ACTION_CONDITION_TYPE_NODE
        ACTION_CONDITION_TYPE_DRULE
        ACTION_CONDITION_TYPE_DCHECK
        ACTION_CONDITION_TYPE_PROXY
        ACTION_CONDITION_TYPE_DOBJECT
        ACTION_CONDITION_TYPE_HOST_NAME/
    ],
    condition_operators => [
        qw/ACTION_CONDITION_OPERATOR_EQUAL
        ACTION_CONDITION_OPERATOR_NOT_EQUAL
        ACTION_CONDITION_OPERATOR_LIKE
        ACTION_CONDITION_OPERATOR_NOT_LIKE
        ACTION_CONDITION_OPERATOR_IN
        ACTION_CONDITION_OPERATOR_MORE_EQUAL
        ACTION_CONDITION_OPERATOR_LESS_EQUAL
        ACTION_CONDITION_OPERATOR_NOT_IN/
    ],
    operation_types => [
        qw/ACTION_OPERATION_TYPE_MESSAGE
        ACTION_OPERATION_TYPE_COMMAND
        ACTION_OPERATION_TYPE_HOST_ADD
        ACTION_OPERATION_TYPE_HOST_REMOVE
        ACTION_OPERATION_TYPE_GROUP_ADD
        ACTION_OPERATION_TYPE_GROUP_REMOVE
        ACTION_OPERATION_TYPE_TEMPLATE_ADD
        ACTION_OPERATION_TYPE_TEMPLATE_REMOVE
        ACTION_OPERATION_TYPE_HOST_ENABLE
        ACTION_OPERATION_TYPE_HOST_DISABLE/
    ],
    eval_types => [
        qw/ACTION_EVAL_TYPE_AND_OR
        ACTION_EVAL_TYPE_AND
        ACTION_EVAL_TYPE_OR/
    ],
);

sub id {

    ## mutator for id

    my ($self, $value) = @_;

    if (defined $value) {

        $self->data->{actionid} = $value;
        return $self->data->{actionid};

    } else {

        return $self->data->{actionid};

    }

}

sub prefix {

    my (undef, $suffix) = @_;

    if ($suffix) {

        return 'action'.$suffix;

    } else {

        return 'action';

    }

}

sub extension {

    return ( output => 'extend',
             select_conditions => 'extend',
             select_operations => 'extend' );

}

sub collides {

    my $self = shift;

    return @{$self->{root}->query(method => $self->prefix('.get'),
                                  params => { filter => { name => [ $self->data->{name} ] },
                                              $self->extension })};

}

sub name {

    my $self = shift;

    return $self->data->{name};

}

1;
__END__
=pod

=head1 NAME

Zabbix::API::Action -- Zabbix action objects

=head1 SYNOPSIS

  use Zabbix::API::Action qw/ACTION_EVENTSOURCE_TRIGGERS
      ACTION_EVAL_TYPE_AND
      ACTION_CONDITION_TYPE_TRIGGER_NAME
      ACTION_CONDITION_OPERATOR_LIKE
      ACTION_OPERATION_TYPE_MESSAGE/;

  # Create a new action: every time the trigger 'Another Trigger' toggles (from OK
  # to PROBLEM or from PROBLEM to OK), send a message to the user with a short
  # subject line and a slightly less short body

  my $new_action = Zabbix::API::Action->new(root => $zabber,
                                            data => {
                                                name => 'Another Action',
                                                eventsource => ACTION_EVENTSOURCE_TRIGGERS,
                                                evaltype => ACTION_EVAL_TYPE_AND,
                                                conditions => [ {
                                                    conditiontype => ACTION_CONDITION_TYPE_TRIGGER_NAME,
                                                    operator => ACTION_CONDITION_OPERATOR_LIKE,
                                                    value => 'Another Trigger' } ],
                                                operations => [ {
                                                    operationtype => ACTION_OPERATION_TYPE_MESSAGE,
                                                    shortdata => '{TRIGGER.NAME}: {STATUS}',
                                                    longdata => 'Hey, look: {TRIGGER.NAME} is now {STATUS}' } ]
                                            });

  $new_action->push;

=head1 DESCRIPTION

Handles CRUD for Zabbix action objects.

This is a subclass of C<Zabbix::API::CRUDE>; see there for inherited methods.

=head1 METHODS

=over 4

=item collides()

Returns true if an action exists with this name, false otherwise.

=back

=head1 EXPORTS

Many many constants that don't seem to be documented anywhere; see source for a
complete list.

Nothing is exported by default; you can use the tags C<:eventsources>,
C<:condition_types>, C<:condition_operators>, C<operation_types> and
C<eval_types> (or import by name).

=head1 BUGS AND ODDITIES

The code in the SYNOPSIS works for creating actions, B<but not fetching them>.
I don't know if this is because of the specific data I'm sending; I can't see
any obvious reason to be able to fetch B<some> actions but not all, except
possibly if the API user has no permissions on the triggers or other objects
involved in the conditions.  (Further experimentation reveals that even if I can
pull the trigger set as a condition, I can't pull the action.)

Obviously this is problematic; in C<CRUDE> we assume that if we can create an
object we can also fetch it.  This means we can't fetch back the action's ID,
which in turns borks up the rest of the API.

As a very ugly workaround, you can set your API user as Super Admin (just Admin
doesn't seem to work); apparently this issue then goes away.  Without the
workaround, this class B<will> die with a meaningless exception in certain
cases.  Further input on what these cases are and why this happens is welcome.

Confirmed in 1.8.10.

=head1 SEE ALSO

L<Zabbix::API::CRUDE>.

L<http://www.zabbix.com/documentation/1.8/complete#actions>

=head1 AUTHOR

Fabrice Gabolde <fabrice.gabolde@uperto.com>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2011 Devoteam

This library is free software; you can redistribute it and/or modify it under
the terms of the GPLv3.

=cut