Petrb has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/110968

Change subject: Fixed lot of stuff in nagios builder
......................................................................

Fixed lot of stuff in nagios builder

* The ignored hosts are now in separate file instead of being hardcoded, that 
makes it easier to maintain, the default template should be included (now is 
missing in git repo, but filename is ignored.host)
* Implemented some default files that must not be removed from icinga objects 
like ido2db, if you remove them, icinga will not start
* Don't create config files for empty groups, which makes faulty config

Whole this commit is uggly and messy piece of shit but it's 6:40 pm, I am still 
sitting here in the office, despite I should have been home already, working on 
this python nightmare (the code is surely cute, but anything written in python 
gives me creeps) so I really need to commit it anyway, so that I can go home 
finally :-)

If you don't like anything in this patch, fix it <3

Change-Id: Ib0a51c39a246855fc8240dddba500a5c751c4fa3
---
M labsnagiosbuilder/build.py
1 file changed, 17 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/nagios-builder 
refs/changes/68/110968/1

diff --git a/labsnagiosbuilder/build.py b/labsnagiosbuilder/build.py
index a0d6b07..0338e7f 100755
--- a/labsnagiosbuilder/build.py
+++ b/labsnagiosbuilder/build.py
@@ -31,6 +31,7 @@
 nagios_config_dir = "/etc/nagios3/conf.d"
 
 # Instances to ignore
+'''
 ignored_fqdns = [
     # Suspended instances
     'wikiversity-sandbox-frontend.pmtpa.wmflabs',
@@ -57,6 +58,9 @@
     'nova-precise1.pmtpa.wmflabs',
     'labs-nfs1.pmtpa.wmflabs',
 ]
+'''
+
+ignored_fqdns = [line.strip() for line in open('ignored.host')]
 
 # How much to spam
 logging_level = logging.INFO
@@ -280,6 +284,9 @@
 
     template = jinja2_env.get_template('group.cfg')
     for group in groups.keys():
+        if len(groups[group]['hosts']) == 0:
+           logger.info('Skipping group %s because it doesn\'t contain any 
hosts', group)
+           continue
         file_path = os.path.join(nagios_config_dir, 'group-%s.cfg' % group)
         with open(file_path, 'w') as fh:
             logger.debug('Writing out group %s to %s' % (group, file_path))
@@ -303,7 +310,14 @@
     '''
     Simple function to remove old instances
     '''
-    ok_hosts = []
+    ok_hosts = [ 'localhost_icinga',
+                'services_icinga',
+                'ido2db_check_proc',
+                'hostgroups_icinga',
+                'extinfo_icinga',
+                'contacts_icinga',
+                'timeperiods_icinga' ]
+
     remove_files = []
 
     for host in hosts:
@@ -314,7 +328,7 @@
         cfg = file_path[:-4]
 
         # Old instances
-        if not cfg.startswith('group-') and cfg not in ok_hosts:
+        if not cfg.startswith('group-') and not cfg.startswith('generic') and 
cfg not in ok_hosts:
             remove_files.append(file_path)
 
         # Old groups
@@ -331,7 +345,7 @@
     '''
     Simple function to reload nagios
     '''
-    if subprocess.call("nagios3 -v /etc/nagios3/nagios.cfg", shell=True) != 0:
+    if subprocess.call("icinga -v /etc/icinga/icinga.cfg", shell=True) != 0:
         logger.error('Nagios config validation failed')
         return
 

-- 
To view, visit https://gerrit.wikimedia.org/r/110968
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib0a51c39a246855fc8240dddba500a5c751c4fa3
Gerrit-PatchSet: 1
Gerrit-Project: labs/nagios-builder
Gerrit-Branch: master
Gerrit-Owner: Petrb <benap...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to