Esempio n. 1
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. 2
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. 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.exception("Exception joining task '%s':\n%s" % (self.name, str(e)))
Esempio n. 5
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. 6
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. 7
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)))