| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Zenoss; |
|
2
|
1
|
|
|
1
|
|
28918
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
454
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Zenoss::Connector; |
|
6
|
|
|
|
|
|
|
use Zenoss::Router; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.11'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#************************************************************************** |
|
11
|
|
|
|
|
|
|
# Public methods |
|
12
|
|
|
|
|
|
|
#************************************************************************** |
|
13
|
|
|
|
|
|
|
#====================================================================== |
|
14
|
|
|
|
|
|
|
# connect |
|
15
|
|
|
|
|
|
|
#====================================================================== |
|
16
|
|
|
|
|
|
|
sub connect { |
|
17
|
|
|
|
|
|
|
my ($self, $args) = @_; |
|
18
|
|
|
|
|
|
|
return $self->_connect($args); |
|
19
|
|
|
|
|
|
|
} # END connect |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#************************************************************************** |
|
22
|
|
|
|
|
|
|
# Private methods |
|
23
|
|
|
|
|
|
|
#************************************************************************** |
|
24
|
|
|
|
|
|
|
#====================================================================== |
|
25
|
|
|
|
|
|
|
# _connect |
|
26
|
|
|
|
|
|
|
#====================================================================== |
|
27
|
|
|
|
|
|
|
sub _connect { |
|
28
|
|
|
|
|
|
|
my ($self, $args) = @_; |
|
29
|
|
|
|
|
|
|
my $router = Zenoss::Router->new( |
|
30
|
|
|
|
|
|
|
{ |
|
31
|
|
|
|
|
|
|
connector => Zenoss::Connector->new($args), |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$router->_process_login; |
|
36
|
|
|
|
|
|
|
return $router; |
|
37
|
|
|
|
|
|
|
} # END connect |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#************************************************************************** |
|
40
|
|
|
|
|
|
|
# Package end |
|
41
|
|
|
|
|
|
|
#************************************************************************** |
|
42
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
43
|
|
|
|
|
|
|
no Moose; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 NAME |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Zenoss - Perl interface to the Zenoss JSON API |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Zenoss; |
|
56
|
|
|
|
|
|
|
use Data::Dumper; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Create a Zenoss object |
|
59
|
|
|
|
|
|
|
my $api = Zenoss->connect( |
|
60
|
|
|
|
|
|
|
{ |
|
61
|
|
|
|
|
|
|
username => 'admin', |
|
62
|
|
|
|
|
|
|
password => 'zenoss', |
|
63
|
|
|
|
|
|
|
url => 'http://zenossinstance:8080', |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Issue a request to get all devices from Zenoss Monitoring System |
|
68
|
|
|
|
|
|
|
my $response = $api->device_getDevices(); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# $response is now an instance of Zenoss::Response |
|
71
|
|
|
|
|
|
|
# now we can do things like |
|
72
|
|
|
|
|
|
|
print $response->json(); |
|
73
|
|
|
|
|
|
|
print $response->http_code(); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# get the response in a perl reference |
|
76
|
|
|
|
|
|
|
my $ref = $response->decoded(); |
|
77
|
|
|
|
|
|
|
print Dumper $ref; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Query events, with history, and only return |
|
80
|
|
|
|
|
|
|
# events that have a severity of 0,1,2,3,4 or 5 |
|
81
|
|
|
|
|
|
|
my $events = $api->events_query( |
|
82
|
|
|
|
|
|
|
{ |
|
83
|
|
|
|
|
|
|
history => JSON::true, |
|
84
|
|
|
|
|
|
|
params => { |
|
85
|
|
|
|
|
|
|
severity => [0,1,2,3,4,5], |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 PREREQUISITES |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Zenoss version >= 3.0 is required |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The L<Zenoss> Perl module ties components together that are vital to communicating with |
|
97
|
|
|
|
|
|
|
the Zenoss JSON API. This module is a full service implementation that provides access |
|
98
|
|
|
|
|
|
|
to all documented API calls by the Zenoss Monitoring System. Essentially, anything that |
|
99
|
|
|
|
|
|
|
can be accomplished via the Zenoss UI can be done programmatically via Perl. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
To get an idea of what requests can be issued to the Zenoss JSON API, please review |
|
102
|
|
|
|
|
|
|
the documentation for the following modules. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L<Zenoss::Router::DetailNav> |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L<Zenoss::Router::Device> |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
L<Zenoss::Router::Events> |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L<Zenoss::Router::Messaging> |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
L<Zenoss::Router::Mib> |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L<Zenoss::Router::Network> |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L<Zenoss::Router::Process> |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L<Zenoss::Router::Report> |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L<Zenoss::Router::Search> |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L<Zenoss::Router::Service> |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L<Zenoss::Router::Template> |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
L<Zenoss::Router::Tree> |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L<Zenoss::Router::ZenPack> |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=back |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
The documentation for these modules was mostly taken from the Zenoss JSON API docs. Keep in mind |
|
161
|
|
|
|
|
|
|
that their (Zenoss Monitoring System) programming is based around python, so descriptions such as |
|
162
|
|
|
|
|
|
|
dictionaries will be represented as hashes in Perl. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 METHODS |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Available methods provided by this module. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 $obj->connect({}) |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This method instantiates an instance of L<Zenoss>. Currently it accepts the following |
|
171
|
|
|
|
|
|
|
arguments. Note, these arguments are described in detail at L<Zenoss::Connector>. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=over |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item * |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
username |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
password |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
url |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
timeout |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=back |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 NOTES |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Here are some notes regarding this interface. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 Zenoss JSON API Arguments |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head3 Arguments in methods |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
When calling the various router methods available, note that any argument you submit will be |
|
202
|
|
|
|
|
|
|
converted to JSON and transmitted to the Zenoss API. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
For example: |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
$api->device_getDevices( |
|
207
|
|
|
|
|
|
|
{ |
|
208
|
|
|
|
|
|
|
foo => 'bar', |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
); |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
The above code will transmit an argument, in JSON, of foo with a value of bar to the API. |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Its also interesting to point out that each router method has an argument definition hard coded. |
|
215
|
|
|
|
|
|
|
If you attempt to call a method that requires a specific argument, and its omitted, it will croak. |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head3 JSON true, false, null |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Some router methods accept boolean arguments. In the event that you need to use a true, false |
|
220
|
|
|
|
|
|
|
or null, the value can be submitted with: |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=over |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=item * |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
JSON::true |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=item * |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
JSON::false |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item * |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
JSON::null |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=back |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
For sake of clarity, say we need to add a device, but we want to also want to model the device |
|
239
|
|
|
|
|
|
|
after its added. Reading L<Zenoss::Router::Device> states that $obj->device_addDevice() |
|
240
|
|
|
|
|
|
|
has an available argument of 'model', which is a boolean. With that said we can do the following: |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
my $response = $api->device_addDevice( |
|
243
|
|
|
|
|
|
|
{ |
|
244
|
|
|
|
|
|
|
deviceName => 'testdevice', |
|
245
|
|
|
|
|
|
|
deviceClass => '/Server/Linux', |
|
246
|
|
|
|
|
|
|
model => JSON::true, |
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
); |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head2 Error handling |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Some methods Carp, so its always good to always try and trap exceptions. This is mostly limited to |
|
253
|
|
|
|
|
|
|
when attempting to establish connections to the API, API timeouts, and argument checking. Error |
|
254
|
|
|
|
|
|
|
handling of Zenoss API responses can be handled with the available methods in L<Zenoss::Response>. |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 DOCUMENTATION |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Please let me know if there is trouble with the documentation. I attempted to put a vast amount of |
|
259
|
|
|
|
|
|
|
information together all at once, so there may be some mistakes. If you have a question |
|
260
|
|
|
|
|
|
|
about implementing something described in the documentation, let me know so I can clarify. However, |
|
261
|
|
|
|
|
|
|
please do not take advantage of this and only ask a question if you're really stuck. |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=over |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item * |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
L<Zenoss::Response> |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=back |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 BUGS |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Please open bug tickets at L<https://rt.cpan.org> |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head1 AUTHOR |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Patrick Baker E<lt>patricksbaker@gmail.comE<gt> |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
Copyright (C) 2010 by Patrick Baker E<lt>patricksbaker@gmail.comE<gt> |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
This module is free software: you can redistribute it and/or modify |
|
286
|
|
|
|
|
|
|
it under the terms of the Artistic License 2.0. |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
|
289
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
290
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
You can obtain the Artistic License 2.0 by either viewing the |
|
293
|
|
|
|
|
|
|
LICENSE file provided with this distribution or by navigating |
|
294
|
|
|
|
|
|
|
to L<http://opensource.org/licenses/artistic-license-2.0.php>. |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=cut |