Esempio n. 1
0
    def join(self):
        try:
            stdout, stderr, returncode = SubProcessTask.join(self)

            try:
                results = json.loads(stdout)
            except Exception as e:
                log.error("Failed to parse JSON. '%s':\n%s" % (self.name, str(e)))
                return

            for result in results:
                for field in ['service', 'state', 'description', 'metric']:
                    if field not in result:
                        log.error("Event missing field '%s'" % (field))
                        continue

                event = Event()
                event.ttl = self.ttl * self.ttl_multiplier
                event.host = self.host
                event.tags = self.tags
                event.attributes = self.attributes

                if "attributes" in result:
                    event.attributes.update({self.attrprefix + name: result["attributes"][name] for name in result["attributes"]})

                event.service = result['service']
                event.state = result['state']
                event.metric = result['metric']
                event.description = "%s\n%s" % (self.note, result['description'])
                self.events.append(event)
        except Exception as e:
            log.error("Exception joining task '%s':\n%s" % (self.name, str(e)))
Esempio n. 2
0
def parse_event_list_from_html(html):
    soup = BeautifulSoup(html, HTML_PARSER)
    event_list_divs = soup.select("#list")[0].find_all('div', recursive=False)

    event_list = list()
    for div in event_list_divs:
        name_tag = div.find("span", class_="eventname")
        if not name_tag:
            continue
        host_tag = div.find("span", class_="event_by")
        desc_tag = div.find("span", {"itemprop": "description"})
        start_date_tag = div.find("time", {"itemprop": "startDate"})
        end_date_tag = div.find("time", {"itemprop": "endDate"})
        # No idea why it's just 'name'
        location_tag = div.find("span", {"itemprop": "name"})

        event = Event()
        event.name = name_tag.string
        event.host = host_tag.string[HOST_NAME_START:]
        event.desc = desc_tag.string
        event.start_date = datetime_string_to_obj(
            start_date_tag['datetime'])
        event.end_date = datetime_string_to_obj(end_date_tag['datetime'])
        event.location = location_tag.string
        event_list.append(event)

    return event_list
Esempio n. 3
0
    def join(self):
        try:
            json_result = self.q.get(timeout=(self.ttl * 0.3))
            self.proc.join()

            log.debug('CloudKickTask: Processing %s metrics' % (len(json_result['metrics'])))
            for metric in json_result['metrics']:
                note = metric['note'] if 'note' in metric else self.note
                event = Event()
                event.ttl = self.ttl * self.ttl_multiplier
                event.host = self.host
                event.tags = self.tags
                event.service = metric['name']
                event.state = metric['state']
                event.metric = metric['value']
                event.description = "%s\nWarn threshold: %s, Error threshold: %s" % (note,
                                                                                     metric['warn_threshold'],
                                                                                     metric['error_threshold'])
                if 'attributes' in metric:
                    event.attributes = metric['attributes']

                self.events.append(event)
        except Exception as e:
            log.error("Exception joining CloudKickTask '%s'\n%s" % (self.name, traceback.format_exc()))
            self.locked = False
Esempio n. 4
0
    def join(self):
        try:
            stdout, stderr, returncode = SubProcessTask.join(self)

            event = Event()
            event.service = self.name
            event.ttl = self.ttl * self.ttl_multiplier
            event.host = self.host
            event.tags = self.tags
            event.attributes = self.attributes

            output, attributes = self.parse_nagios_output(stdout)
            event.description = "Note: %s\nCommand: %s\nOutput: %s\n" % (self.note, self.raw_command, output)

            if returncode in self.exitcodes:
                event.state = self.exitcodes[returncode]
            else:
                event.state = 'unknown'

            if attributes:
                if 'metric' in self.config and self.config['metric'] in attributes:
                    metric_key = self.config['metric']
                else:
                    metric_key = attributes.keys()[0]

                event.attributes.update(attributes)
                event.metric = float(NUMERIC_REGEX.match(attributes[metric_key]).group(1))

            self.events.append(event)
        except Exception as e:
            log.error("Exception joining task '%s':\n%s" % (self.name, str(e)))
Esempio n. 5
0
    def join(self):
        try:
            stdout, stderr, returncode = SubProcessTask.join(self)

            event = Event()
            event.service = self.name
            event.ttl = self.ttl * self.ttl_multiplier
            event.host = self.host
            event.tags = self.tags
            event.attributes = self.attributes

            output, attributes = self.parse_nagios_output(stdout)
            event.description = "Note: %s\nCommand: %s\nOutput: %s\n" % (self.note, self.raw_command, output)

            if returncode in self.exitcodes:
                event.state = self.exitcodes[returncode]
            else:
                event.state = 'unknown'

            if attributes:
                if 'metric' in self.config and self.config['metric'] in attributes:
                    metric_key = self.config['metric']
                else:
                    metric_key = attributes.keys()[0]

                event.attributes.update(attributes)
                event.metric = float(NUMERIC_REGEX.match(attributes[metric_key]).group(1))

            self.events.append(event)
        except Exception as e:
            log.exception("Exception joining task '%s':\n%s" % (self.name, str(e)))
Esempio n. 6
0
    def join(self):
        try:
            json_result = self.q.get(timeout=(self.ttl * 0.3))
            self.proc.join()

            log.debug('CloudKickTask: Processing %s metrics' % (len(json_result['metrics'])))
            for metric in json_result['metrics']:
                note = metric['note'] if 'note' in metric else self.note
                event = Event()
                event.ttl = self.ttl * self.ttl_multiplier
                event.host = self.host
                event.tags = self.tags
                event.service = metric['name']
                event.state = metric['state']
                event.metric = metric['value']
                event.description = "%s\nWarn threshold: %s, Error threshold: %s" % (note,
                                                                                     metric['warn_threshold'],
                                                                                     metric['error_threshold'])
                if 'attributes' in metric:
                    event.attributes = metric['attributes']

                self.events.append(event)
        except Exception as e:
            log.exception("Exception joining CloudKickTask '%s'\n%s" % (self.name, traceback.format_exc()))
            self.locked = False
Esempio n. 7
0
def google_format_to_event(src_event):
    event = Event()
    event.name = src_event.get('summary', '')
    event.location = src_event.get('location', '')
    event.desc = src_event.get('description', '')
    event.start_date = dateutil.parser.parse(src_event['start']['dateTime'])
    event.end_date = dateutil.parser.parse(src_event['end']['dateTime'])
    event.host = src_event.get('extendedProperties', {}).get('shared', {}).get('host', '')
    return event
Esempio n. 8
0
    def join(self):
        try:
            stdout, stderr, returncode = SubProcessTask.join(self)

            try:
                results = json.loads(stdout)
            except Exception as e:
                log.error("Failed to parse JSON. '%s':\n%s" % (self.name, str(e)))
                return

            for result in results:
                for field in ['service', 'state', 'description', 'metric']:
                    if field not in result:
                        log.error("Event missing field '%s'" % (field))
                        continue

                event = Event()
                event.ttl = self.ttl * self.ttl_multiplier
                event.attributes = dict(self.attributes)

                if 'host' in result and result['host'] is not None:
                    event.host = result['host']
                else:
                    event.host = self.host

                if 'tags' in result and result['tags'] is not None:
                    event.tags = self.tags.union(result['tags'])
                else:
                    event.tags = self.tags

                if "attributes" in result:
                    attributes = result["attributes"]
                    event.attributes.update(dict((self.clean_attribute_name(key), attributes[key]) for key in attributes))

                event.service = result['service']
                event.state = result['state']
                event.metric = result['metric']
                event.description = "%s\n%s" % (self.note, result['description'])
                self.events.append(event)
        except Exception as e:
            log.exception("Exception joining task '%s':\n%s" % (self.name, str(e)))
Esempio n. 9
0
    def join(self):
        try:
            stdout, stderr, returncode = SubProcessTask.join(self)

            try:
                results = json.loads(stdout)
            except Exception as e:
                log.error("Failed to parse JSON. '%s':\n%s" %
                          (self.name, str(e)))
                return

            for result in results:
                for field in ['service', 'state', 'description', 'metric']:
                    if field not in result:
                        log.error("Event missing field '%s'" % (field))
                        continue

                event = Event()
                event.ttl = self.ttl * self.ttl_multiplier
                event.host = self.host
                event.tags = self.tags
                event.attributes = self.attributes

                if "attributes" in result:
                    event.attributes.update({
                        self.attrprefix + name: result["attributes"][name]
                        for name in result["attributes"]
                    })

                event.service = result['service']
                event.state = result['state']
                event.metric = result['metric']
                event.description = "%s\n%s" % (self.note,
                                                result['description'])
                self.events.append(event)
        except Exception as e:
            log.error("Exception joining task '%s':\n%s" % (self.name, str(e)))