[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a

Gerhard Lausser gerhard.lausser at consol.de
Tue Feb 28 22:07:52 UTC 2012


The following commit has been merged in the debian/master branch:
commit 3e9cd573a98861df72de5d4a1945f0072879da05
Author: Gerhard Lausser <gerhard.lausser at consol.de>
Date:   Mon Dec 5 01:59:30 2011 +0100

    fix a bug in livestatus (worst_service_status)

diff --git a/shinken/modules/livestatus_broker/livestatus.py b/shinken/modules/livestatus_broker/livestatus.py
index 4e50180..2a5a5bf 100644
--- a/shinken/modules/livestatus_broker/livestatus.py
+++ b/shinken/modules/livestatus_broker/livestatus.py
@@ -34,42 +34,6 @@ from livestatus_request import LiveStatusRequest
 
 
 
-def join_with_separators(prop, ref, request, *args):
-    if request.response.outputformat == 'csv':
-        return request.response.separators[3].join([str(arg) for arg in args])
-    elif request.response.outputformat == 'json' or request.response.outputformat == 'python':
-        return args
-    else:
-        return None
-    pass
-
-
-
-
-def worst_host_state(state_1, state_2):
-    """Return the worst of two host states."""
-    #lambda x: reduce(lambda g, c: c if g == 0 else (c if c == 1 else g), (y.state_id for y in x), 0),
-    if state_2 == 0:
-        return state_1
-    if state_1 == 1:
-        return state_1
-    return state_2
-
-
-def worst_service_state(state_1, state_2):
-    """Return the worst of two service states."""
-    #reduce(lambda g, c: c if g == 0 else (c if c == 2 else (c if (c == 3 and g != 2) else g)), (z.state_id for y in x for z in y.services if z.state_type_id == 1), 0),
-    if state_2 == 0:
-        return state_1
-    if state_1 == 2:
-        return state_1
-    if state_1 == 3 and state_2 != 2:
-        return state_1
-    return state_2
-
-
-
-
 class LiveStatus(object, Hooker):
     """A class that represents the status of all objects in the broker
     
diff --git a/shinken/modules/livestatus_broker/mapping.py b/shinken/modules/livestatus_broker/mapping.py
index cd70f89..c040908 100644
--- a/shinken/modules/livestatus_broker/mapping.py
+++ b/shinken/modules/livestatus_broker/mapping.py
@@ -8,6 +8,39 @@ from shinken.util import from_bool_to_int, from_float_to_int, to_int, to_split,
 
 
 
+def join_with_separators(prop, ref, request, *args):
+    if request.response.outputformat == 'csv':
+        return request.response.separators[3].join([str(arg) for arg in args])
+    elif request.response.outputformat == 'json' or request.response.outputformat == 'python':
+        return args
+    else:
+        return None
+    pass
+
+
+def worst_host_state(state_1, state_2):
+    """Return the worst of two host states."""
+    #lambda x: reduce(lambda g, c: c if g == 0 else (c if c == 1 else g), (y.state_id for y in x), 0),
+    if state_2 == 0:
+        return state_1
+    if state_1 == 1:
+        return state_1
+    return state_2
+
+
+def worst_service_state(state_1, state_2):
+    """Return the worst of two service states."""
+    #reduce(lambda g, c: c if g == 0 else (c if c == 2 else (c if (c == 3 and g != 2) else g)), (z.state_id for y in x for z in y.services if z.state_type_id == 1), 0),
+    if state_2 == 0:
+        return state_1
+    if state_1 == 2:
+        return state_1
+    if state_1 == 3 and state_2 != 2:
+        return state_1
+    return state_2
+
+
+
 def find_pnp_perfdata_xml(name, ref, request):
     """Check if a pnp xml file exists for a given host or service name."""
     if request.pnp_path_readable:
@@ -528,12 +561,16 @@ out_map = {
                 'type' : 'int',
             },
             'worst_service_hard_state' : {
+                'depythonize' : lambda y: reduce(worst_service_state, (z.state_id for z in y if z.state_type_id == 1), 0),
                 'description' : 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
-                'type' : 'list',
+                'prop' : 'services',
+                'type' : 'int',
             },
             'worst_service_state' : {
+                'depythonize' : lambda y: reduce(worst_service_state, (z.state_id for z in y), 0),
                 'description' : 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
-                'type' : 'list',
+                'prop' : 'services',
+                'type' : 'int',
             },
             'x_3d' : {
                 'description' : '3D-Coordinates: X',
diff --git a/test/test_livestatus.py b/test/test_livestatus.py
index d9924ed..6a59ac6 100755
--- a/test/test_livestatus.py
+++ b/test/test_livestatus.py
@@ -2254,6 +2254,85 @@ class TestConfigBig(TestConfig):
         self.livestatus_broker = None
 
 
+    def test_worst_service_state(self):
+        # test_host_005 is in hostgroup_01
+        # 20 services   from  400 services
+        hostgroup_01 = self.sched.hostgroups.find_by_name("hostgroup_01")
+        host_005 = self.sched.hosts.find_by_name("test_host_005")
+        test_ok_00 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_00")
+        test_ok_01 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_01")
+        test_ok_04 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_04")
+        test_ok_16 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_16")
+        objlist = []
+        for service in [svc for host in hostgroup_01.get_hosts() for svc in host.services]:
+            objlist.append([service, 0, 'OK'])
+        self.scheduler_loop(2, objlist)
+        self.update_broker()
+        #h_request = """GET hosts\nColumns: name num_services_ok num_services_warn num_services_crit num_services_unknown worst_service_state worst_service_hard_state\nFilter: name = test_host_005\nColumnHeaders: on\nResponseHeader: fixed16"""
+        h_request = """GET hosts\nColumns: num_services_warn num_services_crit num_services_unknown worst_service_state worst_service_hard_state\nFilter: name = test_host_005\nColumnHeaders: off\nResponseHeader: off"""
+        #hg_request = """GET hostgroups\nColumns: name num_services_ok num_services_warn num_services_crit num_services_unknown worst_service_state worst_service_hard_state\nFilter: name = hostgroup_01\nColumnHeaders: on\nResponseHeader: fixed16"""
+        hg_request = """GET hostgroups\nColumns: num_services_warn num_services_crit num_services_unknown worst_service_state worst_service_hard_state\nFilter: name = hostgroup_01\nColumnHeaders: off\nResponseHeader: off"""
+
+        # test_ok_00
+        # test_ok_01
+        # test_ok_04
+        # test_ok_16
+        h_response, keepalive = self.livestatus_broker.livestatus.handle_request(h_request)
+        hg_response, keepalive = self.livestatus_broker.livestatus.handle_request(hg_request)
+        self.assert_(h_response == hg_response)
+        self.assert_(h_response == """0;0;0;0;0
+""")
+
+        # test_ok_00
+        # test_ok_01 W(S)
+        # test_ok_04
+        # test_ok_16
+        self.scheduler_loop(1, [[test_ok_01, 1, 'WARN']])
+        self.update_broker()
+        h_response, keepalive = self.livestatus_broker.livestatus.handle_request(h_request)
+        hg_response, keepalive = self.livestatus_broker.livestatus.handle_request(hg_request)
+        self.assert_(h_response == hg_response)
+        self.assert_(h_response == """1;0;0;1;0
+""")
+
+        # test_ok_00
+        # test_ok_01 W(S)
+        # test_ok_04 C(S)
+        # test_ok_16
+        self.scheduler_loop(1, [[test_ok_04, 2, 'CRIT']])
+        self.update_broker()
+        h_response, keepalive = self.livestatus_broker.livestatus.handle_request(h_request)
+        hg_response, keepalive = self.livestatus_broker.livestatus.handle_request(hg_request)
+        self.assert_(h_response == hg_response)
+        self.assert_(h_response == """1;1;0;2;0
+""")
+
+        # test_ok_00
+        # test_ok_01 W(H)
+        # test_ok_04 C(S)
+        # test_ok_16
+        self.scheduler_loop(2, [[test_ok_01, 1, 'WARN']])
+        self.update_broker()
+        h_response, keepalive = self.livestatus_broker.livestatus.handle_request(h_request)
+        hg_response, keepalive = self.livestatus_broker.livestatus.handle_request(hg_request)
+        self.assert_(h_response == hg_response)
+        self.assert_(h_response == """1;1;0;2;1
+""")
+
+        # test_ok_00
+        # test_ok_01 W(H)
+        # test_ok_04 C(H)
+        # test_ok_16
+        self.scheduler_loop(2, [[test_ok_04, 2, 'CRIT']])
+        self.update_broker()
+        h_response, keepalive = self.livestatus_broker.livestatus.handle_request(h_request)
+        hg_response, keepalive = self.livestatus_broker.livestatus.handle_request(hg_request)
+        self.assert_(h_response == hg_response)
+        self.assert_(h_response == """1;1;0;2;2
+""")
+
+
+
     def test_stats(self):
         self.print_header()
         if self.nagios_installed():

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list