X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=nagios%2FAutomaticConfig%2FGetConfig.py;fp=nagios%2FAutomaticConfig%2FGetConfig.py;h=d876fe24c6ca5e3ad11f89c441806a9239e4d448;hb=7ec36a95ef5d1d46e7a49af26b4d1dbfb7247661;hp=0000000000000000000000000000000000000000;hpb=2d3e1f103563afe8599e29c91a4f82ff276686ca;p=infrastructure.git diff --git a/nagios/AutomaticConfig/GetConfig.py b/nagios/AutomaticConfig/GetConfig.py new file mode 100644 index 0000000..d876fe2 --- /dev/null +++ b/nagios/AutomaticConfig/GetConfig.py @@ -0,0 +1,101 @@ +import os, sys, time, string +from optparse import OptionParser +import xmlrpclib + + +class GetConfig: + + subversion_id = "$Id$" + + def __init__ (self): + self.url="https://localhost:443/PLCAPI/" + self.server=xmlrpclib.Server(self.url,allow_none=True) + self.path="/etc/nagios/config-sample/" + self.path1="/etc/nagios/" + + def create_hostgroup(self, file, nodes_infos): + f1=open(file,"a") + i=0 + j=0 + memberhost="" + alias=[] + list=[] + site_name=nodes_infos[0]['Site_name']##initialize the first site name + + while 1: + if(i=len(nodes_infos)): + alias.append(site_name) + list.append(memberhost) + break + + + print list + print alias + while (j < len(list)): + f1.write("\ndefine hostgroup { \n") + f1.write("hostgroup_name "+str(j)+"\n") + f1.write("alias %s\n"%alias[j]) + f1.write("members %s\n } \n"%list[j]) + j=j+1 + f1.close() + + def generate_file(self,sample_file, file,login,nodes_infos): + + f1=open(self.path+sample_file,"rb") + f2=open(self.path1+file,"wb") + f2.write(f1.read()) + f1.close() + f2.close() + if (login=="h"): + self.create_host(self.path1+file,nodes_infos) + elif (login=="s"): + self.create_service(self.path1+file,nodes_infos) + elif (login=="g"): + self.create_hostgroup(self.path1+file, nodes_infos) + + + + def create_host(self,file,nodes_infos): + f1=open(file,"a") + i=0 + while (i