Pièce jointe « parser.py »
Téléchargement 1 import csv
2 import sys
3 #import pdb
4 from socket import gethostbyname
5 from Cheetah.Template import Template
6 # import des classes generees par Cheetah
7 from host import host
8 #from healthlinux import healthlinux
9 from healthswitch import healthswitch
10 from healthwindows import healthwindows
11 from process import process
12 from disquesDEH import disquesDEH
13 from disquesCEH import disquesCEH
14 from disquesCDE import disquesCDE
15 from disquesCDEH import disquesCDEH
16 from disquesS import disquesS
17 from raidlinux import raidlinux
18 from healthlinuxavecswap import healthlinuxavecswap
19 from healthlinuxsansswap import healthlinuxsansswap
20 from beanscounters import beanscounters
21 from logcheck import logcheck
22 #from disquesCDE import disquesCDE
23
24 class GenNagios:
25 def genHost(this, hostname, contactgroup, ip, parent):
26 file = open("../auto.d/"+hostname+".cfg", "w")
27 hosttmpl = host()
28 hosttmpl.hostname = hostname
29 hosttmpl.contactgroup = contactgroup
30 hosttmpl.ip = ip
31 if parent == "":
32 parent = "localhost"
33 hosttmpl.parent = parent
34 file.write(hosttmpl.respond())
35 file.close()
36
37 def genServices(this, hostname, contact, check, type):
38 file = open("../auto.d/"+hostname+"-"+check+".cfg", "w")
39 print hostname + " " + check
40
41 if check == "Logcheck" and type == "Linux":
42 tmpl = logcheck()
43 tmpl.hostname = hostname
44 tmpl.contact = contact
45 file.write(tmpl.respond())
46 elif check == "Beanscounters" and type == "Linux":
47 tmpl = beanscounters()
48 tmpl.hostname = hostname
49 tmpl.contact = contact
50 file.write(tmpl.respond())
51 elif check == "Health" and type == "Windows":
52 tmpl = healthwindows()
53 tmpl.hostname = hostname
54 tmpl.contact = contact
55 file.write(tmpl.respond())
56 elif check == "Health" and type == "Switch":
57 tmpl = healthswitch()
58 tmpl.hostname = hostname
59 tmpl.contact = contact
60 file.write(tmpl.respond())
61 elif check == "Process300":
62 tmpl = process()
63 tmpl.hostname = hostname
64 tmpl.contact = contact
65 tmpl.warn = 300
66 tmpl.crit = 500
67 file.write(tmpl.respond())
68 elif check == "Process200":
69 tmpl = process()
70 tmpl.hostname = hostname
71 tmpl.contact = contact
72 tmpl.warn = 200
73 tmpl.crit = 400
74 file.write(tmpl.respond())
75 elif check == "Process150":
76 tmpl = process()
77 tmpl.hostname = hostname
78 tmpl.contact = contact
79 tmpl.warn = 150
80 tmpl.crit = 300
81 file.write(tmpl.respond())
82 elif check == "Process350":
83 tmpl = process()
84 tmpl.hostname = hostname
85 tmpl.contact = contact
86 tmpl.warn = 350
87 tmpl.crit = 500
88 file.write(tmpl.respond())
89 elif check == "disquesDEH":
90 tmpl = disquesDEH()
91 tmpl.hostname = hostname
92 tmpl.contact = contact
93 file.write(tmpl.respond())
94 elif check == "disquesCEH":
95 tmpl = disquesCEH()
96 tmpl.hostname = hostname
97 tmpl.contact = contact
98 file.write(tmpl.respond())
99 elif check == "disquesCDE":
100 tmpl = disquesCDE()
101 tmpl.hostname = hostname
102 tmpl.contact = contact
103 file.write(tmpl.respond())
104 elif check == "disquesCDEH":
105 tmpl = disquesCDEH()
106 tmpl.hostname = hostname
107 tmpl.contact = contact
108 file.write(tmpl.respond())
109 elif check == "disquesS":
110 tmpl = disquesS()
111 tmpl.hostname = hostname
112 tmpl.contact = contact
113 file.write(tmpl.respond())
114 elif check == "Raid" and type == "Linux":
115 tmpl = raidlinux()
116 tmpl.hostname = hostname
117 tmpl.contact = contact
118 file.write(tmpl.respond())
119 elif check == "Healthlinuxavecswap" and type == "Linux":
120 tmpl = healthlinuxavecswap()
121 tmpl.hostname = hostname
122 tmpl.contact = contact
123 file.write(tmpl.respond())
124 elif check == "Healthlinuxsansswap" and type == "Linux":
125 tmpl = healthlinuxsansswap()
126 tmpl.hostname = hostname
127 tmpl.contact = contact
128 file.write(tmpl.respond())
129
130 # elif check == "disquesCDE":
131 # tmpl = disquesCDE()
132 # tmpl.hostname = hostname
133 # tmpl.contact = contact
134 # file.write(tmpl.respond())
135 else:
136 print "template ou OS inexistant : " + check
137 file.close()
138
139 def main(this):
140 reader = csv.reader(open("liste.csv", "r"))
141 this.path = "../auto.d/"
142 # dmzreflets,10.36.0.253,zeus,Switch,Health,contactgroup1
143 try:
144 prev = ""
145 for row in reader:
146 hostname = row[0]
147 ip = row[1]
148 parent = row[2]
149 type = row[3]
150 check = row[4]
151 contactgroup = row[5:]
152 contacts = ""
153 for i in range(len(contactgroup)):
154 contacts += contactgroup[i] + ","
155 contacts = contacts[:len(contacts)-1]
156 current = hostname
157 if current != prev:
158 this.genHost(hostname, contacts, ip, parent)
159 prev = hostname
160 this.genServices(hostname, contacts, check, type)
161
162
163
164
165 except csv.Error, e:
166 sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
167
168 if __name__ == "__main__":
169 a = GenNagios()
170 a.main()
Fichiers joints
Pour vous référer aux pièces jointes d'une page, utilisez attachment:filename, comme indiqué ci-dessous dans la liste de fichiers. N'utilisez pas l'URL du lien [get], car elle peut changer et donc être facilement cassée.Vous n'êtes pas autorisé à joindre un fichier à cette page.