3 ##must before run this script to check the nagios service installation and run
6 from optparse import OptionParser
8 from GetConfig import *
12 subversion_id = "$Id$"
15 self.url="https://localhost:443/PLCAPI/"
16 self.server=xmlrpclib.Server(self.url,allow_none=True)
18 #self.path=os.path.dirname(sys.argv[0])
21 return {'Username':self.args[0],
22 'AuthMethod':'password',
23 'AuthString':self.args[1],
29 #################################
30 ###############################
32 def GetSiteNodes(self,sites_names):
35 tab_node_infos=[]##its an array containing struct of Site,nodes hostname and ip for each nodes
37 while (i< len(sites_names)):
38 filter_site={'abbreviated_name':sites_names[i]}
39 return_value=['site_id']
40 ##Getting the site_id from the given site name args
41 site_id=self.server.GetSites(self.auth_root(),filter_site,return_value)
43 print "Site Not found or duplicated Site Name please check your Site's Name::",sites_names[i]
46 ##Getting nodes_id relative to the site to be monitored
47 filter_node={'site_id':site_id[0]['site_id']}
48 node_ids =self.server.GetNodes(self.auth_root(),filter_node,['node_id','hostname'])
49 ##Getting information for nodes to be monitored
51 while(j < len(node_ids)):
53 sn_info={'Site_name':None,
57 sn_info['Site_name']=sites_names[i]
59 filter=node_ids[j]['node_id']
60 node_infos=self.server.GetNodeNetworks(self.auth_root(),filter,['ip'])
61 sn_info['node_hostname']=node_ids[j]['hostname']
62 #tab_node_infos.append(self.sn_info['node_hostname'])
63 sn_info['node_ip']=node_infos[0]['ip']
64 tab_node_infos.append(sn_info)
71 #######################################
72 ######################################
80 usage = """usage: %prog [options] UserName(email) passwd Sites Names [-h for help]"""
81 parser=OptionParser(usage=usage,version=self.subversion_id)
83 parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False,
84 help="Run in verbose mode")
86 (self.options, self.args) = parser.parse_args()
94 if (len (self.args) < 3 ):
95 print "please check your command"
100 while (i < len(self.args)) :
101 site_name.append(self.args[i])
104 nodes_infos=self.GetSiteNodes(site_name)
105 getConfig.generate_file("services-sample.cfg","services.cfg","s",nodes_infos)
106 getConfig.generate_file("hosts-sample.cfg","hosts.cfg","h",nodes_infos)
107 getConfig.generate_file("hostgroups-sample.cfg","hostgroups.cfg","g",nodes_infos)
109 print "Info on what will be monitored grouped by Site:-------->"
110 for node in nodes_infos:
111 print "------------>",node
115 res=os.system("nagios -v /etc/nagios/nagios.cfg")
117 os.system("service nagios reload")
120 ######################
129 if __name__ == "__main__":
130 GetMonitoring().main()