add default /etc/monitor.conf to monitor-server.init
[monitor.git] / zabbix / zabbixsync.py
index 8c078e7..fd2126e 100755 (executable)
@@ -37,39 +37,30 @@ def add_loginbase(loginbase):
        zabbixsite.setup_site(loginbase, techs, pis, iplist)
 
 if __name__=="__main__":
-       #sites = api.GetSites({'peer_id' : None}, ['login_base'])
-       for loginbase in ['princeton', 'princetondsl', 'monitorsite']:
-               add_loginbase(loginbase)
 
-       session.flush()
+       from monitor import parser as parsermodule
+       parser = parsermodule.getParser()
+       parser.set_defaults( setupglobal=False, syncsite=True, site=None)
+       parser.add_option("", "--setupglobal", action="store_true", dest="setupglobal",
+                                               help="Setup global settings.")
+       parser.add_option("", "--nosite", action="store_true", dest="syncsite",
+                                               help="Do not sync sites.")
+       parser.add_option("", "--site", dest="site",
+                                               help="Sync only given site name.")
+       opts = parsermodule.parse_args(parser)
 
-## Scripts : includes external scripts to: 
-#                - reboot.py
-#                - nmap
+       if opts.setupglobal:
+               zabbixsite.setup_global()
 
-## UserGroups
-# define technical contact, principal investigator groups
-# define a Group for every site
+       if opts.syncsite:
+               query = {'peer_id' : None}
+               if opts.site:
+                       query.update({'login_base' : opts.site})
 
-## Users
-# define a User for every user with admin/tech/pi roles
-#              get passwords from a combination of site&name, perhaps?
-#              I'm guessing we could use the grpid or userid as part of the passwd,
-#              so that it varies in general, and can be guessed from the templates
-# add user to groups
+               sites = api.GetSites(query, ['login_base'])
+               for site in sites:
+                       add_loginbase(site['login_base'])
+                       session.flush()
 
-## Discovery Rules and Actions
-# define a discovery rule for every site's hosts.
-# define discovery action for online hosts.
+       # TODO: for any removed site that is in the db, call zabbixsite.delete_site()
 
-## Messages & Escalations
-# define actions and escellations for trigger sources:
-#              - unreachable host,
-
-## HostGroups
-# add host group for every site
-# add host group for global network (PLC name)
-
-## Hosts & Templates
-# no need to define hosts?
-# add template?  It appears that the xml-based tempate system is sufficient.