[omd-commits] OMD Git: omd: omd: "omd status" exits with 2 when only some of the sites are running / partially running

git version control git at mathias-kettner.de
Tue Jul 1 10:26:44 CEST 2014


Module:   omd
Branch:   master
Commit:   4dac1e8cafec3b1105b91335174b828cd0c738f9
URL:      http://omdistro.org/projects/omd/repository/revisions/4dac1e8cafec3b1105b91335174b828cd0c738f9

Author:   Lars Michelsen <lm at mathias-kettner.de>
Date:     Tue Jul  1 10:26:27 2014 +0200
Commiter: Lars Michelsen <lm at mathias-kettner.de>
Date:     Tue Jul  1 10:26:27 2014 +0200

omd: "omd status" exits with 2 when only some of the sites are running / partially running

---

 Changelog        |    2 ++
 packages/omd/omd |   16 +++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index 495dac1..61187d5 100644
--- a/Changelog
+++ b/Changelog
@@ -15,6 +15,8 @@ This file documents the revision history for the Open Monitoring Distribution
               reload of the system apache instead of a restart
             - Added nagios/icinga reload init hooks
             - FIX: Providing correct exit codes when running "omd status"
+            - FIX: exit with 2 (partially running) when only some of the
+              sites are running or partially running using "omd status"
           - diskspace: Fixed error messages in syslog which were caused by
             exit codes of 3 when diskspace cleanup has not been configured
           - Check_MK/MK Livestatus: new version 1.2.4p4
diff --git a/packages/omd/omd b/packages/omd/omd
index 75dfe9f..c502d69 100644
--- a/packages/omd/omd
+++ b/packages/omd/omd
@@ -2850,7 +2850,7 @@ def main_init_action(command, args, options={}):
 
     # if no site is selected, all sites are affected
     if not g_sitename:
-        exit_status = 0
+        exit_states = []
         for site in all_sites():
             if only_version and site_version(site) != only_version:
                 continue
@@ -2873,10 +2873,20 @@ def main_init_action(command, args, options={}):
 	    else:
 		sys.stdout.write("%sDoing '%s' on site %s:%s\n" % (tty_bold, command, site, tty_normal))
 	    sys.stdout.flush()
-            exit_status = max(exit_status, os.system("%s %s %s %s %s" %
-			(sys.argv[0], command, "bare" in options and "--bare" or "", site, " ".join(args))) >> 8)
+            exit_states.append(os.system("%s %s %s %s %s" % (sys.argv[0], command,
+                                         "bare" in options and "--bare" or "", site, " ".join(args))) >> 8)
 	    if not bare:
 		sys.stdout.write("\n")
+
+        # Do not simply take the highest exit code from the single sites.
+        # We want to be able to output the fact that either none of the
+        # sites is running or just some of the sites. For this we transform
+        # the sites states 1 (not running) to 2 (partially running) if at least
+        # one other site has state 0 (running) or 2 (partially running).
+        if 1 in exit_states and (0 in exit_states or 2 in exit_states):
+            exit_status = 2 # not all sites running, but at least one
+        else:
+            exit_status = max(exit_states)
     else:
         exit_status = init_action(command, args, options)
     sys.exit(exit_status)



More information about the omd-commits mailing list