(self, entity)
return sane
Make given entity 'sane' for further use.
Make given entity 'sane' for further use.
Make given entity sane for further use .
def _sanitize_entity(self, entity):
        """
        Make given entity 'sane' for further use.
        """
        aliases = {
            "current_state": "state",
            "is_flapping": "flapping",
            "scheduled_downtime_depth": "in_downtime",
            "has_been_checked": "checked",
            "should_be_scheduled": "scheduled",
            "active_checks_enabled": "active_checks",
            "passive_checks_enabled": "passive_checks",
        }
        sane = {}
        for akey in aliases.keys():
            sane[aliases[akey]] = None

        aliases_keys = aliases.keys()
        for key in entity.keys():
            if key not in aliases_keys:
                continue

            alias = aliases[key]
            try:
                sane[alias] = int(entity[key])
            except Exception:
                sane[alias] = None

        if sane["active_checks"] not in [0, 1]:
            sane["active_checks"] = 0
        elif sane["active_checks"] == 1:
            sane["passive_checks"] = 0

        if sane["passive_checks"] not in [0, 1]:
            sane["passive_checks"] = 0

        return sane
def _sanitize_entity ( self , entity ) : aliases = { "current_state" : "state" , "is_flapping" : "flapping" , "scheduled_downtime_depth" : "in_downtime" , "has_been_checked" : "checked" , "should_be_scheduled" : "scheduled" , "active_checks_enabled" : "active_checks" , "passive_checks_enabled" : "passive_checks" , } sane = { } for akey in aliases . keys ( ) : sane [ aliases [ akey ] ] = None aliases_keys = aliases . keys ( ) for key in entity . keys ( ) : if key not in aliases_keys : continue alias = aliases [ key ] try : sane [ alias ] = int ( entity [ key ] ) except Exception : sane [ alias ] = None if sane [ "active_checks" ] not in [ 0 , 1 ] : sane [ "active_checks" ] = 0 elif sane [ "active_checks" ] == 1 : sane [ "passive_checks" ] = 0 if sane [ "passive_checks" ] not in [ 0 , 1 ] : sane [ "passive_checks" ] = 0 return sane