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

Gerhard Lausser gerhard.lausser at consol.de
Tue Feb 28 22:15:59 UTC 2012


The following commit has been merged in the debian/master branch:
commit 930f0d93167ca37d6eb73e51a2366947dc3922b1
Author: Gerhard Lausser <gerhard.lausser at consol.de>
Date:   Mon Jan 23 23:00:22 2012 +0100

    Fix servicesbyhostgroup and num_services_* attributes for servicegroups in livestatus

diff --git a/shinken/modules/livestatus_broker/livestatus_query.py b/shinken/modules/livestatus_broker/livestatus_query.py
index 4ee69c6..46011d4 100644
--- a/shinken/modules/livestatus_broker/livestatus_query.py
+++ b/shinken/modules/livestatus_broker/livestatus_query.py
@@ -513,11 +513,11 @@ class LiveStatusQuery(object):
                                 # ([host, host, ...], hostgroup), ([host, host, host, ...], hostgroup), ...  sorted by host_name
                                 (sorted(hg1.members, key = lambda k: k.host_name), hg1) for hg1 in   # ([host, host], hg), ([host], hg),... hostgroup.members->explode->sort
                                     # hostgroups, sorted by hostgroup_name
-                                    sorted([hg0 for hg0 in self.hostgroups.values() if hg0.members], key = lambda k: k.hostgroup_name)
+                                    sorted([hg0 for hg0 in self.datamgr.rg.hostgroups if hg0.members], key = lambda k: k.hostgroup_name)
                             ) for item0 in inner_list0[0] if item0.services
                         ) for item1 in inner_list1[0]
                     )
-                ) if (cs.without_filter or cs.filter_func(self.create_output(cs.filter_map, svc)))
+                ) if (cs.without_filter or cs.filter_func(svc))
             )]
         return res
 
diff --git a/shinken/modules/livestatus_broker/mapping.py b/shinken/modules/livestatus_broker/mapping.py
index 2f930c9..ec7cef9 100644
--- a/shinken/modules/livestatus_broker/mapping.py
+++ b/shinken/modules/livestatus_broker/mapping.py
@@ -1583,58 +1583,58 @@ livestatus_attribute_map = {
         },
         'num_services': {
             'description': 'The total number of services in the group',
-            'function': lambda item, req: "",  # REPAIRME
-            'datatype': list,
+            'function': lambda item, req: len(item.members),
+            'datatype': int,
         },
         'num_services_crit': {
             'description': 'The number of services in the group that are CRIT',
-            'function': lambda item, req: "",  # REPAIRME
-            'datatype': list,
+            'function': lambda item, req: len([x for x in item.members if x.state_id == 2]),
+            'datatype': int,
         },
         'num_services_hard_crit': {
             'description': 'The number of services in the group that are CRIT',
-            'function': lambda item, req: "",  # REPAIRME
-            'datatype': list,
+            'function': lambda item, req: len([x for x in item.members if x.state_id == 2 and x.state_type_id == 1]),
+            'datatype': int,
         },
         'num_services_hard_ok': {
             'description': 'The number of services in the group that are OK',
-            'function': lambda item, req: "",  # REPAIRME
-            'datatype': list,
+            'function': lambda item, req: len([x for x in item.members if x.state_id == 0 and x.state_type_id == 1]),
+            'datatype': int,
         },
         'num_services_hard_unknown': {
             'description': 'The number of services in the group that are UNKNOWN',
-            'function': lambda item, req: "",  # REPAIRME
-            'datatype': list,
+            'function': lambda item, req: len([x for x in item.members if x.state_id == 3 and x.state_type_id == 1]),
+            'datatype': int,
         },
         'num_services_hard_warn': {
             'description': 'The number of services in the group that are WARN',
-            'function': lambda item, req: "",  # REPAIRME
-            'datatype': list,
+            'function': lambda item, req: len([x for x in item.members if x.state_id == 1 and x.state_type_id == 1]),
+            'datatype': int,
         },
         'num_services_ok': {
             'description': 'The number of services in the group that are OK',
-            'function': lambda item, req: "",  # REPAIRME
-            'datatype': list,
+            'function': lambda item, req: len([x for x in item.members if x.state_id == 0]),
+            'datatype': int,
         },
         'num_services_pending': {
             'description': 'The number of services in the group that are PENDING',
-            'function': lambda item, req: "",  # REPAIRME
-            'datatype': list,
+            'function': lambda item, req: len([x for x in item.members if x.has_been_checked == 0]),
+            'datatype': int,
         },
         'num_services_unknown': {
             'description': 'The number of services in the group that are UNKNOWN',
-            'function': lambda item, req: "",  # REPAIRME
-            'datatype': list,
+            'function': lambda item, req: len([x for x in item.members if x.state_id == 3]),
+            'datatype': int,
         },
         'num_services_warn': {
             'description': 'The number of services in the group that are WARN',
-            'function': lambda item, req: "",  # REPAIRME
-            'datatype': list,
+            'function': lambda item, req: len([x for x in item.members if x.state_id == 1]),
+            'datatype': int,
         },
         'worst_service_state': {
             'description': 'The worst soft state of all of the groups services (OK <= WARN <= UNKNOWN <= CRIT)',
-            'function': lambda item, req: "",  # REPAIRME
-            'datatype': list,
+            'function': lambda item, req: reduce(worst_service_state, (x.state_id for x in item.members), 0),
+            'datatype': int,
         },
     },
     'Contact': {
@@ -4691,6 +4691,12 @@ for objtype in ['Host', 'Service']:
             setattr(cls, 'lsm_servicegroup_'+attribute, servicegroup_redirect_factory('lsm_'+attribute.replace('servicegroup_', '')))
             getattr(cls, 'lsm_servicegroup_'+attribute).im_func.description = getattr(Servicegroup, 'lsm_'+attribute).im_func.description
             getattr(cls, 'lsm_servicegroup_'+attribute).im_func.datatype = getattr(Servicegroup, 'lsm_'+attribute).im_func.datatype
+        # in LivestatusQuery.get_service_by_hostgroup, (copied) Service objects get an extra "hostgroup" attribute
+        # and Service objects get an extra "servicegroup" attribute. Here we set the lsm-attributes for them
+        for attribute in livestatus_attribute_map['Hostgroup']:
+            setattr(cls, 'lsm_hostgroup_'+attribute, hostgroup_redirect_factory('lsm_'+attribute.replace('hostgroup_', '')))
+            getattr(cls, 'lsm_hostgroup_'+attribute).im_func.description = getattr(Hostgroup, 'lsm_'+attribute).im_func.description
+            getattr(cls, 'lsm_hostgroup_'+attribute).im_func.datatype = getattr(Hostgroup, 'lsm_'+attribute).im_func.datatype
 
 # Finally set some default values for the different datatypes
 for objtype in ['Host', 'Service', 'Contact', 'Command', 'Timeperiod', 'Downtime', 'Comment', 'Hostgroup', 'Servicegroup', 'Contactgroup', 'SchedulerLink', 'PollerLink', 'ReactionnerLink', 'BrokerLink', 'Problem', 'Logline', 'Config']:

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list