Commit 22399e0c authored by Andrey Vertiprahov's avatar Andrey Vertiprahov Committed by Dmitry Volodin

noc/noc#1245 Move configvalidation umbrella to 'Config | Object Policy Violation' AlarmClass.

parent be31a99a
......@@ -6,8 +6,12 @@
# See LICENSE for details
# ----------------------------------------------------------------------
# Third-party modules
import cachetools
# NOC modules
from noc.services.discovery.jobs.base import DiscoveryCheck
from noc.fm.models.alarmclass import AlarmClass
class ConfigValidationCheck(DiscoveryCheck):
......@@ -18,21 +22,49 @@ class ConfigValidationCheck(DiscoveryCheck):
name = "configvalidation"
required_artefacts = ["config_acquired"]
@staticmethod
@cachetools.cached({})
def get_ac_cm_violations():
return AlarmClass.get_by_name("Config | Policy Violations")
def handler(self):
self.logger.info("Running config validation")
is_changed = self.get_artefact("config_changed") or False
# Legacy CLIPS path, problems are passed via Facts
self.object.validate_config(is_changed)
# New ConfDB path, problems are passed via alarms
n = 0
alarms = []
for problem in self.object.iter_validation_problems(is_changed):
self.set_problem(**problem)
n += 1
if n:
self.logger.info("%d problem(s) detected", n)
alarms += [self.get_umbrella_alarm_cfg(**problem)]
# self.set_problem(**problem)
if alarms:
self.logger.info("%d problem(s) detected", len(alarms))
else:
self.logger.info("No problems detected")
self.job.update_umbrella(self.get_ac_cm_violations(), alarms)
def is_enabled(self):
checks = self.job.attrs.get("_checks", set())
return not checks or "config" in checks
def get_umbrella_alarm_cfg(
self, alarm_class=None, path=None, message=None, fatal=False, **kwargs
):
"""
Getting Umbrella Alarm Cfg
:param alarm_class: Alarm class instance or name
:param path: Additional path
:param message: Text message
:param fatal: True if problem is fatal and all following checks
must be disabled
:param kwargs: Dict containing optional variables
:return:
"""
alarm_cfg = {
"alarm_class": AlarmClass.get_by_name(alarm_class),
"path": " | ".join(path),
"vars": kwargs,
}
alarm_cfg["vars"]["message"] = message
alarm_cfg["vars"]["path"] = path
return alarm_cfg
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment