-
Notifications
You must be signed in to change notification settings - Fork 3
/
README
257 lines (167 loc) · 6.4 KB
/
README
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
NAME
Opsview::REST - Interface to the Opsview REST API
SYNOPSIS
use Opsview::REST;
my $ops = Opsview::REST->new(
base_url => 'http://opsview.example.com/rest',
user => 'username',
pass => 'password',
);
# Check status
my $status = $ops->status(
'hostgroup',
'hostgroupid' => [1, 2],
'filter' => 'unhandled',
);
# Configuration methods
my $host1 = $ops->create_host(
ip => '192.168.0.1',
name => 'monitoring-slave',
hostgroup => { name => 'Monitoring Servers' },
notification_period => { name => '24x7' },
);
$ops->clone_host(
$host1->{object}->{id},
name => 'another-host',
ip => '192.168.0.2',
);
# Search methods support complex SQL::Abstract queries
my $hosts = $ops->get_hosts(
-or => [
name => { -like => '%.example.com' },
ip => { -like => '10.25.%' },
],
);
# Update several objects at once
map { $_->{check_attempts} = 4 } @{ $hosts->{list} };
my $response = $ops->create_or_update_hosts($hosts->{list});
# ... or only one
my $response = $ops->create_or_update_host(
name => 'host1.example.com',
snmp_version => '2c',
);
# Reload after make changes in config
$ops->reload;
DESCRIPTION
Opsview::REST is a set of modules to access the Opsview REST API, which
is the recommended method for scripting configuration changes or any
other form of integration since version 3.9.0
METHODS
new
Return an instance of the Opsview::REST.
Required Arguments
base_url
Base url where the REST API resides. By default it is under /rest.
user
Username to login as.
Other Arguments
pass
auth_tkt
Either the pass or the auth_tkt MUST be passed. It will die horribly
if none of these are found.
ua
A user agent object can be provided here. It should be an HTTP::Tiny
subclass.
get($url)
Makes a "GET" request to the API. The response is properly deserialized
and returned as a Perl data structure.
status( $endpoint, [ %args ] )
Convenience method to request the "status" part of the API. $endpoint
is the endpoint to send the query to. %args is a hash which will get
properly translated to URL arguments.
More info:
http://docs.opsview.com/doku.php?id=opsview-core:restapi:status
downtimes
create_downtime( %args )
delete_downtime( [ %args ] )
Downtime related methods.
More info:
http://docs.opsview.com/doku.php?id=opsview-core:restapi:downtimes
events( [ %args ] )
Get events. An event is considered to be either:
* a host or service changing state
* a host or service result during soft failures
* a host or service in a failure state where 'alert every failure' is
enabled
More info:
http://docs.opsview.com/doku.php?id=opsview-core:restapi:event
acknowledge( [ %args ] )
Acknowledge problems.
More info:
http://docs.opsview.com/doku.php?id=opsview-core:restapi:acknowledge
acknowledge_list
Lists the problems which the current logged in user has permission to
acknowledge.
reload
Initiates a synchronous reload. Be careful: if your opsview reload
takes more than 60 seconds to run, this call will time out. The
returned data contains the info of the reload.
More info:
http://docs.opsview.com/doku.php?id=opsview-core:restapi#initiating_an_opsview_reload
reload_info
Get status of reload.
More info:
http://docs.opsview.com/doku.php?id=opsview-core:restapi#initiating_an_opsview_reload
recheck( [ %args ] )
Recheck services or hosts asynchronously. It returns info about the
number of hosts and services that will be rechecked.
More info:
http://docs.opsview.com/doku.php?id=opsview-core:restapi:recheck
Config methods for single objects
get_*
create_*
clone_*
create_or_update_*
delete_*
This methods will be generated for the following types of objects:
contact, role, servicecheck, hosttemplate, attribute, timeperiod,
hostgroup, servicegroup, notificationmethod, hostcheckcommand, keyword,
monitoringserver.
They all except create, require the object's id. Additionally, create,
clone and create_or_update accept a list of key-value pairs:
my $host1 = $ops->create_host(
name => 'host1',
ip => '192.168.10.27',
);
$ops->clone_host(
$host1->{object}->{id},
name => 'host2',
ip => '192.168.10.28',
);
$host->delete($id);
Config methods for multiple objects
get_*
create_*
create_or_update_*
This methods will be generated for the following types of objects:
contacts, roles, servicechecks, hosttemplates, attributes, timeperiods,
hostgroups, servicegroups, notificationmethods, hostcheckcommands,
keywords, monitoringservers.
get accepts complex queries in SQL::Abstract format.
create_or_update is specially useful when you want to update several
objects with a single call:
# First get a list of objects you want to modify
my $dbhosts = $ops->get_hosts(
name => { -like => 'db%' },
);
# $dbhosts = {
# summary => { ... },
# list => [ { name => 'db1.example.com , ... }, ... ],
# };
# Modify them as you need
map { $_->{check_attempts} = 4 } @{ $dbhosts->{list} };
# Make the call
$ops->create_or_update($dbhosts->{list});
To know which fields are accepted for each type of object, the format
of the responses, and additional info:
http://docs.opsview.com/doku.php?id=opsview-core:restapi:config
SEE ALSO
* http://www.opsview.org/
* Opsview REST API Documentation
<http://docs.opsview.com/doku.php?id=opsview-core:restapi>
AUTHOR
* Miquel Ruiz <[email protected]>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Miquel Ruiz.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.