-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
94 lines (62 loc) · 2.25 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
Python interface to Nagios object and status files. Parses configuration files,
status.dat (status file) and represents information as collection of objects
with corresponding obj_type and attributes. Objects may be changed and saved.
nagdata package contains following modules:
nagdata -- main module, interface to nagios object and status files,
also provides class with simpler api
exceptions -- exceptions used by nagdata
parser -- parsers of nagios configuration and status files (parses list
of lines)
cparser_fmt -- parse file and keep format
cparser_fast -- just parse file and don't save format
nagfile -- links together files and parsers, so we can parse files
collection -- collection of Nagios objects
factory -- factories to produce different Nagios objects
model -- Nagios objects (hoststatus, servicestatus, service definition,
etc)
fields -- Types of Nagios object attributes
fmt -- "Imaginary" format object helping to keep nagios file format and
structure
Both cparser_fmt and cparser_fast are produced from the same cparser.c (and symlink
to it cparser2.c)
Some little examples:
# update status:
from nagdata import nagdata
n = nagdata.NagData()
n.update_status()
# retrieve some objects:
from nagdata.nagdata import *
n = NagData()
for o in n.filter(obj_type='servicestatus', host_name='c6509'):
print o
hg = n.get('hostgroup', hostgroup_name='servers_corp')
print hg
sg = n.get('servicegroup', servicegroup_name='mailq_group')
print sg
# simpler api
from nagdata import nagdata
n = nagdata.NagDataSimpleApi()
# get host by address
h0 = n.get_host('172.16.1.1')
# get host by name
h1 = n.get_host('router1')
# statuses
print n.get_hoststatus('router1')
print n.get_servicestatus('PING', 'router1')
hg = n.get_hostgroup('servers_corp')
# change address
h0['address'] = 'router2'
# and save to file
n.save(h0)
# create and add object
from nagdata import nagdata
n = nagdata.NagDataSimpleApi()
#create and add config object
svc = n.new('service',
service_description='PING',
host_name='localhost')
# just create
svc = n.factory('service', service_description='PING')
svc['host_name'] = 'router1'
# add to config
n.config.add(svc)