Beispiel #1
0
    def get_check_result_perfdata_points(self, perf_data, timestamp, tags={}):
        """
        :param perf_data: Perf data of the brok
        :param timestamp: Timestamp of the check result
        :param tags: Tags for the point
        :return: List of perfdata points
        """
        points = []
        metrics = PerfDatas(perf_data).metrics

        for e in metrics.values():
            fields = {}
            fields_mappings = [('value', 'value'), ('uom', 'unit'),
                               ('warning', 'warning'),
                               ('critical', 'critical'), ('min', 'min'),
                               ('max', 'max')]
            for mapping in fields_mappings:
                value = getattr(e, mapping[0], None)
                if value is not None:
                    if isinstance(value, (int, long)):
                        value = float(value)
                    fields[mapping[1]] = value

            if fields:
                point = {
                    "measurement":
                    'metric_%s' % self.illegal_char.sub('_', e.name),
                    "time": timestamp,
                    "fields": fields,
                    "tags": tags,
                }
                points.append(point)

        return points
Beispiel #2
0
    def get_check_result_perfdata_points(self, perf_data, timestamp, tags={}):
        """
        :param perf_data: Perf data of the brok
        :param timestamp: Timestamp of the check result
        :param tags: Tags for the point
        :return: List of perfdata points
        """
        points = []
        metrics = PerfDatas(perf_data).metrics

        for e in metrics.values():
            fields = {}
            field_names = ['value', 'unit', 'warning',
                           'critical', 'min', 'max']
            for field_name in field_names:
                value = getattr(e, field_name, None)
                if value is not None:
                    fields[field_name] = value

            if fields:
                point = {
                    "name": 'metric_%s' % self.illegal_char.sub('_', e.name),
                    "time": timestamp,
                    "fields": fields,
                    "tags": tags,
                }
                points.append(point)

        return points
Beispiel #3
0
    def get_check_result_perfdata_points(perf_data, timestamp, name):

        points = []
        metrics = PerfDatas(perf_data).metrics

        for e in metrics.values():
            points.append(
                {"points": [[timestamp, e.value, e.uom, e.warning, e.critical, e.min, e.max]],
                 "name": "%s.%s" % (name, e.name),
                 "columns": ["time", "value", "unit", "warning", "critical", "min", "max"]
                 }
            )

        return points
Beispiel #4
0
    def get_check_result_perfdata_points(perf_data, timestamp, name):

        points = []
        metrics = PerfDatas(perf_data).metrics

        for e in metrics.values():
            points.append(
                {"points": [[timestamp, e.value, e.uom, e.warning, e.critical, e.min, e.max]],
                 "name": "%s.%s" % (name, e.name),
                 "columns": ["time", "value", "unit", "warning", "critical", "min", "max"]
                 }
            )

        return points
Beispiel #5
0
    def get_check_result_perfdata_points(self, perf_data, timestamp, tags={}):
        """
        :param perf_data: Perf data of the brok
        :param timestamp: Timestamp of the check result
        :param tags: Tags for the point
        :return: List of perfdata points
        """
        points = []
        metrics = PerfDatas(perf_data).metrics

        for e in metrics.values():
            fields = {}
            fields_mappings = [
                ('value', 'value'),
                ('uom', 'unit'),
                ('warning', 'warning'),
                ('critical', 'critical'),
                ('min', 'min'),
                ('max', 'max')
            ]
            for mapping in fields_mappings:
                value = getattr(e, mapping[0], None)
                if value is not None:
                    if isinstance(value, (int, long)):
                        value = float(value)
                    fields[mapping[1]] = value

            if fields:
                point = {
                    "measurement": 'metric_%s' % self.illegal_char.sub('_',
                                                                       e.name),
                    "time": timestamp,
                    "fields": fields,
                    "tags": tags,
                }
                points.append(point)

        return points
Beispiel #6
0
    def get_check_result_perfdata_events(self, perf_data, timestamp, host, service):

        events = []
        metrics = PerfDatas(perf_data).metrics

        for e in metrics.values():
            event_data = {
                'host': host,
                'service': service,
                'time': timestamp,
                #'state': 'WARNING',
                'metric_f': e.value,
                'description': e.name,
            }
            attributes = {}
            if e.uom is not None:
                attributes['unit'] = unicode(e.uom)

            if e.warning is not None:
                attributes['warning'] = unicode(e.warning)

            if e.critical is not None:
                attributes['critical'] = unicode(e.critical)

            if e.min is not None:
                attributes['min'] = unicode(e.min)

            if e.max is not None:
                attributes['max'] = unicode(e.max)

            if attributes is not {}:
                event_data['attributes'] = attributes

            events.append(
                self.client.create_event(event_data)
            )

        return events