Пример #1
0
    def _get_status(self):
        self.new_hosts = dict()

        try:
            events = self._get_all_events()
            for event in events:
                event_check = event['check']
                event_client = event['client']

                new_service = GenericService()
                new_service.event_id = event['id']
                new_service.host = event_client['name']
                new_service.name = event_check['name']
                # Uchiwa needs the 'dc' for re_check; Sensu does not
                if 'dc' in event:
                    new_service.site = event['dc']
                else:
                    new_service.site = None
                new_service.status = None
                try:
                    new_service.status = self.SEVERITY_CODE_TEXT_MAP.get(
                        event_check['status'])
                except KeyError:
                    new_service.status = 'UNKNOWN'
                last_check_time = datetime.utcfromtimestamp(
                    int(event['timestamp']))
                new_service.last_check = self._aslocaltimestr(last_check_time)
                new_service.duration = HumanReadableDurationFromTimestamp(
                    int(event['last_state_change']))
                new_service.status_information = event_check['output']
                # needs a / with a number on either side to work
                new_service.attempt = str(event['occurrences']) + '/1'
                new_service.passiveonly = False
                new_service.notifications_disabled = event['silenced']
                new_service.flapping = False
                new_service.acknowledged = event['silenced']
                new_service.scheduled_downtime = False

                self._insert_service_to_hosts(new_service)
        except:
            self.isChecking = False
            result, error = self.Error(sys.exc_info())
            print(traceback.format_exc())
            return Result(result=result, error=error)

        return Result(error="")
Пример #2
0
 def _parse_event_to_service(self, event):
     service = GenericService()
     namespace_host = event['entity']['metadata'][
         'namespace'] + NAMESPACE_SEPARATOR + event['entity']['metadata'][
             'name']
     service.hostid = namespace_host
     service.host = namespace_host
     service.name = event['check']['metadata']['name']
     service.status = SensuGoAPI.parse_check_status(
         event['check']['status'])
     service.last_check = datetime.fromtimestamp(int(
         event['timestamp'])).strftime('%Y-%m-%d %H:%M:%S')
     service.duration = self._duration_since(event['check']['last_ok'])
     service.status_information = event['check']['output']
     service.acknowledged = event['check']['is_silenced']
     service.notifications_disabled = event['check']['is_silenced']
     service.attempt = str(event['check']['occurrences']) + '/1'
     service.passiveonly = event['check']['publish']
     service.flapping = False
     service.scheduled_downtime = False
     return service