4 from optparse import OptionParser
6 from GetConfig import *
10 subversion_id = "$Id$"
13 self.url="https://localhost:443/PLCAPI/"
14 self.server=xmlrpclib.Server(self.url,allow_none=True)
16 #self.path=os.path.dirname(sys.argv[0])
19 return {'Username':self.args[0],
20 'AuthMethod':'password',
21 'AuthString':self.args[1],
27 #################################
28 ###############################
30 def GetSiteNodes(self,sites_names):
33 tab_node_infos=[]##its an array containing struct of Site,nodes hostname and ip for each nodes
35 while (i< len(sites_names)):
36 filter_site={'abbreviated_name':sites_names[i]}
37 return_value=['site_id']
38 ##Getting the site_id from the given site name args
39 site_id=self.server.GetSites(self.auth_root(),filter_site,return_value)
41 print "Site Not found or duplicated Site Name please check your Site's Name::",sites_names[i]
44 ##Getting nodes_id relative to the site to be monitored
45 filter_node={'site_id':site_id[0]['site_id']}
46 node_ids =self.server.GetNodes(self.auth_root(),filter_node,['node_id','hostname'])
47 ##Getting information for nodes to be monitored
49 while(j < len(node_ids)):
51 sn_info={'Site_name':None,
55 sn_info['Site_name']=sites_names[i]
57 filter=node_ids[j]['node_id']
58 node_infos=self.server.GetNodeNetworks(self.auth_root(),filter,['ip'])
59 sn_info['node_hostname']=node_ids[j]['hostname']
60 #tab_node_infos.append(self.sn_info['node_hostname'])
61 sn_info['node_ip']=node_infos[0]['ip']
62 tab_node_infos.append(sn_info)
69 #######################################
70 ######################################
78 usage = """usage: %prog [options] UserName(email) passwd Sites Names [-h for help]"""
79 parser=OptionParser(usage=usage,version=self.subversion_id)
81 parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False,
82 help="Run in verbose mode")
84 (self.options, self.args) = parser.parse_args()
92 if (len (self.args) < 3 ):
93 print "please check your command"
98 while (i < len(self.args)) :
99 site_name.append(self.args[i])
102 nodes_infos=self.GetSiteNodes(site_name)
103 getConfig.generate_file("services-sample.cfg","services.cfg","s",nodes_infos)
104 getConfig.generate_file("hosts-sample.cfg","hosts.cfg","h",nodes_infos)
105 getConfig.generate_file("hostgroups-sample.cfg","hostgroups.cfg","g",nodes_infos)
107 print "Info on what will be monitored grouped by Site:-------->"
108 for node in nodes_infos:
109 print "------------>",node
113 res=os.system("nagios -v /etc/nagios/nagios.cfg")
115 os.system("service nagios reload")
118 ######################
127 if __name__ == "__main__":
128 GetMonitoring().main()