From: amine Date: Fri, 3 Aug 2007 14:54:05 +0000 (+0000) Subject: Automatic creation:creates nagios config from a set of sites and monitor their nodes X-Git-Tag: foo~435 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=7ec36a95ef5d1d46e7a49af26b4d1dbfb7247661;p=infrastructure.git creation:creates nagios config from a set of sites and monitor their nodes --- 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" + for node in nodes_infos: + print "------------>",node + + + + res=os.system("nagios -v /etc/nagios/nagios.cfg") + if (not res): + os.system("service nagios reload") + + + ###################### + ########end options + ################## + + + except Exception, e: + print str(e) + sys.exit(1) + +if __name__ == "__main__": + GetMonitoring().main() diff --git a/nagios/AutomaticConfig/ServiceName b/nagios/AutomaticConfig/ServiceName new file mode 100644 index 0000000..dd67613 --- /dev/null +++ b/nagios/AutomaticConfig/ServiceName @@ -0,0 +1,2 @@ +check_ssh +check-host-alive