-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
73 lines (60 loc) · 3.24 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
# nagrestconf-python
python API binding for mclarkson/nagrestconf
Aim: Can be used as a standalone tool to run REST commands or included in Python code and use a APi binding
* CLI usage:
# usage: nagrestconf.py [-h] [-s SERVER] [-r REQUEST] [-p] [-j] [-d DATA] [-v|vv|vvv|vvvv] [-D DELIMITER] [-f FILTER]
NagRESTConf API
optional arguments:
-h, --help show this help message and exit
-s SERVER, --server SERVER
Server URI to connect to. It may include HTTP auth
data. Ex: https://user:password@restserver/rest Server
argument can be saved in ~/.nagrestconf in form
[client] \n server=http://xxx/rest
-r REQUEST, --request REQUEST
Request to run: show/hosts, apply/nagiosconfig, etc.
OR shortcuts: cn => check/nagiosconfig , sh =>
show/hosts , ss => show/services , sn => show/contacts
, sm => show/commands , mh => modify/hosts , ms =>
modify/services , mn => modify/contacts , mm =>
modify/commands , dh => delete/hosts , ds =>
delete/services , dn => delete/contacts , dm =>
delete/commands , ah => add/hosts , as => add/services
, an => add/contacts , am => add/commands , rn =>
restart/nagios , nc => apply/nagiosconfig , nl =>
apply/nagioslastgoodconfig
-p, --post Run POST request. Needed for all calls except for
check and show. Shortcut calls does not need this.
-j, --json Show result in JSON format
-d DATA, --data DATA Request data pairs (name=value) separated by comma
with no spaces. Ex:
name=monitoredhost1,svcdesc=ssh,command=check_ssh
-v, --verbose Verbose level. Default verbosity is ERROR. Each -v
increases the log level by one step
-D DELIMITER, --delimiter DELIMITER
Delimiter for the pipe output
-f FILTER, --filter FILTER
Filter rule pairs (name=value) separated by comma with
no spaces. Ex:
name=monitoredhost1,svcdesc=ssh,command=check_ssh
-F FOLDER, --folder FOLDER
Folder to target. Default:local
Examples:
# nagrestconf.py -s https://user:[email protected]/rest -r show/hosts
# nagrestconf.py -s https://user:[email protected]/rest -r mh -d name=host1,ipaddress=10.10.10.10
# nagrestconf.py -s https://user:[email protected]/rest -r sh -f name=host1
# nagrestconf.py -s https://user:[email protected]/rest -r sh -f name=host1 -D'\t'
* Python usage example:
from nagrestconf import nagrestconf
import logging
def objSeek(obj,name):
for ind,val in enumerate(obj):
if name in val:
return val[name]
return None
nrc=nagrestconf('https://user:[email protected]/rest')
res,naghosts=nrc.showhosts()
if not res:
logging.exception('Failed to get list of hosts from nagrestconf with error: %s',naghosts)
for naghid,nagh in enumerate(naghosts):
print objSeek(nagh, 'name'), objSeek(nagh, 'ipaddress')