@cryptotaxi247 / netdata-1 / commits / 80ca4e886

Alarms py collector add filtering (#12972)

add ability to filter alarms in `alarms.conf`

Andrew Maguire committed May 26, 2022 at 10:10 UTC 80ca4e8864dfdf1cc3bbaced3e780ca302d0bc9c
3 files changed +14 -1
collectors/python.d.plugin/alarms/README.md
+5
@@ -53,6 +53,11 @@ local:
53 CRITICAL: 2
54 # set to true to include a chart with calculated alarm values over time
55 collect_alarm_values: false
56 + # define the type of chart for plotting status over time e.g. 'line' or 'stacked'
57 + alarm_status_chart_type: 'line'
58 + # a "," separated list of words you want to filter alarm names for. For example 'cpu,load' would filter for only
59 + # alarms with "cpu" or "load" in alarm name. Default includes all.
60 + alarm_contains_words: ''
61 ```
62
63 It will default to pulling all alarms at each time step from the Netdata rest api at `http://127.0.0.1:19999/api/v1/alarms?all`
collectors/python.d.plugin/alarms/alarms.chart.py
+6 -1
@@ -38,7 +38,7 @@ DEFAULT_STATUS_MAP = {'CLEAR': 0, 'WARNING': 1, 'CRITICAL': 2}
38 DEFAULT_URL = 'http://127.0.0.1:19999/api/v1/alarms?all'
39 DEFAULT_COLLECT_ALARM_VALUES = False
40 DEFAULT_ALARM_STATUS_CHART_TYPE = 'line'
41 -
41 +DEFAULT_ALARM_CONTAINS_WORDS = ''
42
43 class Service(UrlService):
44 def __init__(self, configuration=None, name=None):
@@ -49,6 +49,8 @@ class Service(UrlService):
49 self.url = self.configuration.get('url', DEFAULT_URL)
50 self.collect_alarm_values = bool(self.configuration.get('collect_alarm_values', DEFAULT_COLLECT_ALARM_VALUES))
51 self.collected_dims = {'alarms': set(), 'values': set()}
52 + self.alarm_contains_words = self.configuration.get('alarm_contains_words', DEFAULT_ALARM_CONTAINS_WORDS)
53 + self.alarm_contains_words_list = [alarm_contains_word.lstrip(' ').rstrip(' ') for alarm_contains_word in self.alarm_contains_words.split(',')]
54
55 def _get_data(self):
56 raw_data = self._get_raw_data()
@@ -57,6 +59,9 @@ class Service(UrlService):
59
60 raw_data = loads(raw_data)
61 alarms = raw_data.get('alarms', {})
62 + if self.alarm_contains_words != '':
63 + alarms = {alarm_name: alarms[alarm_name] for alarm_name in alarms for alarm_contains_word in
64 + self.alarm_contains_words_list if alarm_contains_word in alarm_name}
65
66 data = {a: self.sm[alarms[a]['status']] for a in alarms if alarms[a]['status'] in self.sm}
67 self.update_charts('alarms', data)
collectors/python.d.plugin/alarms/alarms.conf
+3
@@ -52,3 +52,6 @@ local:
52 collect_alarm_values: false
53 # define the type of chart for plotting status over time e.g. 'line' or 'stacked'
54 alarm_status_chart_type: 'line'
55 + # a "," separated list of words you want to filter alarm names for. For example 'cpu,load' would filter for only
56 + # alarms with "cpu" or "load" in alarm name. Default includes all.
57 + alarm_contains_words: ''