67 lines
2.0 KiB
Python
Executable File
67 lines
2.0 KiB
Python
Executable File
class Alert_Config():
|
|
def __init__(self, yaml_config) :
|
|
if not 'alert_tags' in yaml_config :
|
|
yaml_config['alert_tags'] = {}
|
|
self.id = str(yaml_config['id'])
|
|
self.yaml_config = yaml_config
|
|
self.tags = {}
|
|
self.state = {}
|
|
|
|
def type(self) :
|
|
if 'type' in self.yaml_config :
|
|
return self.yaml_config['type']
|
|
return 'kairos'
|
|
|
|
def tags(self) :
|
|
if 'tags' in self.yaml_config :
|
|
return self.yaml_config['tags']
|
|
return []
|
|
|
|
def occurrences(self) :
|
|
if 'occurrences_threshold' in self.yaml_config :
|
|
return self.yaml_config['occurrences_threshold']
|
|
return 1
|
|
|
|
def url(self) :
|
|
if 'url' in self.yaml_config :
|
|
return self.yaml_config['url']
|
|
from os import environ
|
|
return environ['AOM_GRAFANA_URL'] + self.id
|
|
|
|
def get_level(self, key) :
|
|
if not key in self.state :
|
|
self.state[key] = None
|
|
return self.state[key]
|
|
|
|
def set_level(self, key, value) :
|
|
self.state[key] = value
|
|
|
|
def get_for_tags(self, key) :
|
|
if not key in self.tags :
|
|
self.tags[key] = 0
|
|
return self.tags[key]
|
|
|
|
def set_for_tags(self, key, value) :
|
|
if not key in self.tags :
|
|
self.tags[key] = 0
|
|
self.tags[key] = value
|
|
|
|
def init_for_tags(self, key) :
|
|
for k in [key, key+"_count"] :
|
|
if not key in self.tags :
|
|
self.set_for_tags(key, 0)
|
|
self.set_for_tags(key+"_noresult", 0)
|
|
|
|
def get_threshold(isUpper, isWarning) :
|
|
if isUpper and isWarning :
|
|
return self.try_get_yaml_config('warning_upper_threshold')
|
|
if isUpper and not isWarning :
|
|
return self.try_get_yaml_config('critical_upper_threshold')
|
|
elif not isUpper and isWarning :
|
|
return self.try_get_yaml_config('warning_lower_threshold')
|
|
elif not isUpper and not isWarning :
|
|
return self.try_get_yaml_config('critical_lower_threshold')
|
|
|
|
def try_get_yaml_config(self, key) :
|
|
return self.yaml_config[key] if key in self.yaml_config else None, key in self.yaml_config
|