diff options
author | Andrew Maguire <andrewm4894@gmail.com> | 2022-05-26 10:10:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-26 10:10:32 +0100 |
commit | 80ca4e8864dfdf1cc3bbaced3e780ca302d0bc9c (patch) | |
tree | 485e99fb40e5975fc27abc9d7b34065936aeb3c9 /collectors | |
parent | 8b0fffe33bccf950496f5ffee358320bde71e5b5 (diff) |
Alarms py collector add filtering (#12972)
add ability to filter alarms in `alarms.conf`
Diffstat (limited to 'collectors')
-rw-r--r-- | collectors/python.d.plugin/alarms/README.md | 5 | ||||
-rw-r--r-- | collectors/python.d.plugin/alarms/alarms.chart.py | 7 | ||||
-rw-r--r-- | collectors/python.d.plugin/alarms/alarms.conf | 3 |
3 files changed, 14 insertions, 1 deletions
diff --git a/collectors/python.d.plugin/alarms/README.md b/collectors/python.d.plugin/alarms/README.md index cd5e1b8178..ee1e599719 100644 --- a/collectors/python.d.plugin/alarms/README.md +++ b/collectors/python.d.plugin/alarms/README.md @@ -53,6 +53,11 @@ local: CRITICAL: 2 # set to true to include a chart with calculated alarm values over time collect_alarm_values: false + # define the type of chart for plotting status over time e.g. 'line' or 'stacked' + alarm_status_chart_type: 'line' + # a "," separated list of words you want to filter alarm names for. For example 'cpu,load' would filter for only + # alarms with "cpu" or "load" in alarm name. Default includes all. + alarm_contains_words: '' ``` 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` diff --git a/collectors/python.d.plugin/alarms/alarms.chart.py b/collectors/python.d.plugin/alarms/alarms.chart.py index 1eec404509..314b0e7a83 100644 --- a/collectors/python.d.plugin/alarms/alarms.chart.py +++ b/collectors/python.d.plugin/alarms/alarms.chart.py @@ -38,7 +38,7 @@ DEFAULT_STATUS_MAP = {'CLEAR': 0, 'WARNING': 1, 'CRITICAL': 2} DEFAULT_URL = 'http://127.0.0.1:19999/api/v1/alarms?all' DEFAULT_COLLECT_ALARM_VALUES = False DEFAULT_ALARM_STATUS_CHART_TYPE = 'line' - +DEFAULT_ALARM_CONTAINS_WORDS = '' class Service(UrlService): def __init__(self, configuration=None, name=None): @@ -49,6 +49,8 @@ class Service(UrlService): self.url = self.configuration.get('url', DEFAULT_URL) self.collect_alarm_values = bool(self.configuration.get('collect_alarm_values', DEFAULT_COLLECT_ALARM_VALUES)) self.collected_dims = {'alarms': set(), 'values': set()} + self.alarm_contains_words = self.configuration.get('alarm_contains_words', DEFAULT_ALARM_CONTAINS_WORDS) + self.alarm_contains_words_list = [alarm_contains_word.lstrip(' ').rstrip(' ') for alarm_contains_word in self.alarm_contains_words.split(',')] def _get_data(self): raw_data = self._get_raw_data() @@ -57,6 +59,9 @@ class Service(UrlService): raw_data = loads(raw_data) alarms = raw_data.get('alarms', {}) + if self.alarm_contains_words != '': + alarms = {alarm_name: alarms[alarm_name] for alarm_name in alarms for alarm_contains_word in + self.alarm_contains_words_list if alarm_contains_word in alarm_name} data = {a: self.sm[alarms[a]['status']] for a in alarms if alarms[a]['status'] in self.sm} self.update_charts('alarms', data) diff --git a/collectors/python.d.plugin/alarms/alarms.conf b/collectors/python.d.plugin/alarms/alarms.conf index 5e83d8f56e..cd48d44113 100644 --- a/collectors/python.d.plugin/alarms/alarms.conf +++ b/collectors/python.d.plugin/alarms/alarms.conf @@ -52,3 +52,6 @@ local: collect_alarm_values: false # define the type of chart for plotting status over time e.g. 'line' or 'stacked' alarm_status_chart_type: 'line' + # a "," separated list of words you want to filter alarm names for. For example 'cpu,load' would filter for only + # alarms with "cpu" or "load" in alarm name. Default includes all. + alarm_contains_words: '' |