8c078e78f9748302785acd6ed63e1134de80a3c1
[monitor.git] / zabbix / zabbixsync.py
1 #!/usr/bin/python
2
3 import sys
4 import site
5 from monitor.wrapper import plc
6 from monitor import database
7
8 import zabbixsite
9 from monitor.database.dborm import session
10
11 print "test"
12
13 plcdb = database.dbLoad("l_plcsites")
14 netid2ip = database.dbLoad("plcdb_netid2ip")
15 lb2hn = database.dbLoad("plcdb_lb2hn")
16
17 def get_site_iplist(loginbase):
18         node_list = lb2hn[loginbase]
19
20         # TODO: ip_list string cannot be longer than 255 characters.
21         # TODO: if it is, then we need to break up the discovery rule.
22         ip_list = ""
23         for node in node_list:
24                 ip = netid2ip[node['nodenetwork_ids'][0]]
25                 if len(ip_list) > 0: ip_list += ","
26                 ip_list += ip
27
28         return ip_list
29         
30 def add_loginbase(loginbase):
31         
32         techs = plc.getTechEmails(loginbase)
33         pis = plc.getPIEmails(loginbase)
34         iplist = get_site_iplist(loginbase)
35
36         print "zabbixsite.setup_site('%s', %s, %s, '%s')" % (loginbase,techs, pis, iplist)
37         zabbixsite.setup_site(loginbase, techs, pis, iplist)
38
39 if __name__=="__main__":
40         #sites = api.GetSites({'peer_id' : None}, ['login_base'])
41         for loginbase in ['princeton', 'princetondsl', 'monitorsite']:
42                 add_loginbase(loginbase)
43
44         session.flush()
45
46 ## Scripts : includes external scripts to: 
47 #                 - reboot.py
48 #                 - nmap
49
50 ## UserGroups
51 # define technical contact, principal investigator groups
52 # define a Group for every site
53
54 ## Users
55 # define a User for every user with admin/tech/pi roles
56 #               get passwords from a combination of site&name, perhaps?
57 #               I'm guessing we could use the grpid or userid as part of the passwd,
58 #               so that it varies in general, and can be guessed from the templates
59 # add user to groups
60
61 ## Discovery Rules and Actions
62 # define a discovery rule for every site's hosts.
63 # define discovery action for online hosts.
64
65 ## Messages & Escalations
66 # define actions and escellations for trigger sources:
67 #               - unreachable host,
68
69 ## HostGroups
70 # add host group for every site
71 # add host group for global network (PLC name)
72
73 ## Hosts & Templates
74 # no need to define hosts?
75 # add template?  It appears that the xml-based tempate system is sufficient.