[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Naparuba
naparuba at gmail.com
Tue Feb 28 22:08:22 UTC 2012
The following commit has been merged in the debian/master branch:
commit f41b5ae2e9c0b7ccf0dc15d0d4bef4217f8849e7
Author: Naparuba <naparuba at gmail.com>
Date: Fri Dec 9 15:25:50 2011 +0100
Add : NOT operand rule in the business rules.
diff --git a/shinken/dependencynode.py b/shinken/dependencynode.py
index cc93b6f..92ced83 100644
--- a/shinken/dependencynode.py
+++ b/shinken/dependencynode.py
@@ -40,6 +40,7 @@ class DependencyNode(object):
self.of_values = (0,0,0)
self.is_of_mul = False
self.configuration_errors = []
+ self.not_value = False
def __str__(self):
return "Op:'%s' Val:'%s' Sons:'[%s]'" % (self.operand, self.of_values, ','.join([str(s) for s in self.sons]))
@@ -58,6 +59,19 @@ class DependencyNode(object):
# Make DOWN look as CRITICAL (2 instead of 1)
if self.operand == 'host' and state == 1:
state = 2
+ # Maybe we are a NOT node, so manage this
+ if self.not_value:
+ # We inverse our states
+ if self.operand == 'host' and state == 1:
+ return 0
+ if self.operand == 'host' and state == 0:
+ return 1
+ #Critical -> OK
+ if self.operand == 'service' and state == 2:
+ return 0
+ #OK -> CRITICAL (warning is untouched)
+ if self.operand == 'service' and state == 0:
+ return 2
return state
# First we get the state of all our sons
@@ -220,6 +234,11 @@ class DependencyNodeFactory(object):
# if it's a single host/service
if not complex_node:
#print "Try to find?", patern
+ # If it's a not value, tag the node and find
+ # the namewithout this ! operator
+ if patern.startswith('!'):
+ node.not_value = True
+ patern = patern[1:]
node.operand = 'object'
obj, error = self.find_object(patern, hosts, services)
if obj is not None:
diff --git a/shinken/objects/schedulingitem.py b/shinken/objects/schedulingitem.py
index bfa595f..335fe19 100644
--- a/shinken/objects/schedulingitem.py
+++ b/shinken/objects/schedulingitem.py
@@ -1278,8 +1278,8 @@ class SchedulingItem(Item):
self.got_business_rule = True
rule = ''
if len(elts) >= 2:
- rule = elts[1]
- #print "Got rules", rule
+ rule = '!'.join(elts[1:])
+ print "Got rules", rule
fact = DependencyNodeFactory()
node = fact.eval_cor_patern(rule, hosts, services)
#print "got node", node
diff --git a/test/etc/business_correlator/services.cfg b/test/etc/business_correlator/services.cfg
index c517882..fc2879d 100644
--- a/test/etc/business_correlator/services.cfg
+++ b/test/etc/business_correlator/services.cfg
@@ -164,3 +164,12 @@ define service{
use generic-service
}
+
+
+
+define service{
+ check_command bp_rule!test_host_0,db1&!test_host_0,db2
+ host_name test_host_0
+ service_description Simple_And_not
+ use generic-service
+}
diff --git a/test/test_business_correlator.py b/test/test_business_correlator.py
index fe6a6c0..b546c77 100755
--- a/test/test_business_correlator.py
+++ b/test/test_business_correlator.py
@@ -1044,6 +1044,114 @@ class TestBusinesscorrel(ShinkenTest):
+
+ # We will try a simple bd1 AND NOT db2
+ def test_simple_and_not_business_correlator(self):
+ #
+ # Config is not correct because of a wrong relative path
+ # in the main config file
+ #
+ print "Get the hosts and services"
+ now = time.time()
+ host = self.sched.hosts.find_by_name("test_host_0")
+ host.checks_in_progress = []
+ host.act_depend_of = [] # ignore the router
+ router = self.sched.hosts.find_by_name("test_router_0")
+ router.checks_in_progress = []
+ router.act_depend_of = [] # ignore the router
+ svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
+ svc.checks_in_progress = []
+ svc.act_depend_of = [] # no hostchecks on critical checkresults
+
+ svc_bd1 = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "db1")
+ self.assert_(svc_bd1.got_business_rule == False)
+ self.assert_(svc_bd1.business_rule is None)
+ svc_bd2 = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "db2")
+ self.assert_(svc_bd2.got_business_rule == False)
+ self.assert_(svc_bd2.business_rule is None)
+ svc_cor = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "Simple_And_not")
+ self.assert_(svc_cor.got_business_rule == True)
+ self.assert_(svc_cor.business_rule is not None)
+ bp_rule = svc_cor.business_rule
+ self.assert_(bp_rule.operand == '&')
+
+ sons = bp_rule.sons
+ print "Sons,", sons
+ #We(ve got 2 sons, 2 services nodes
+ self.assert_(len(sons) == 2)
+ self.assert_(sons[0].operand == 'service')
+ self.assert_(sons[0].sons[0] == svc_bd1)
+ self.assert_(sons[1].operand == 'service')
+ self.assert_(sons[1].sons[0] == svc_bd2)
+
+ # Now state working on the states
+ self.scheduler_loop(2, [[svc_bd1, 0, 'OK | value1=1 value2=2'], [svc_bd2, 2, 'CRITICAL | rtt=10']])
+ self.assert_(svc_bd1.state == 'OK')
+ self.assert_(svc_bd1.state_type == 'HARD')
+ self.assert_(svc_bd2.state == 'CRITICAL')
+ self.assert_(svc_bd2.state_type == 'HARD')
+
+ # We are a NOT, so should be OK here
+ state = bp_rule.get_state()
+ self.assert_(state == 0)
+
+ # Now we set the bd1 as soft/CRITICAL
+ self.scheduler_loop(1, [[svc_bd1, 2, 'CRITICAL | value1=1 value2=2']])
+ self.assert_(svc_bd1.state == 'CRITICAL')
+ self.assert_(svc_bd1.state_type == 'SOFT')
+ self.assert_(svc_bd1.last_hard_state_id == 0)
+
+ # The business rule must still be 0
+ # becase we want HARD states
+ state = bp_rule.get_state()
+ self.assert_(state == 0)
+
+ # Now we get bd1 CRITICAL/HARD
+ self.scheduler_loop(1, [[svc_bd1, 2, 'CRITICAL | value1=1 value2=2']])
+ self.assert_(svc_bd1.state == 'CRITICAL')
+ self.assert_(svc_bd1.state_type == 'HARD')
+ self.assert_(svc_bd1.last_hard_state_id == 2)
+
+ # The rule must go CRITICAL
+ state = bp_rule.get_state()
+ self.assert_(state == 2)
+
+ # Now we also set bd2 as WARNING/HARD...
+ self.scheduler_loop(2, [[svc_bd2, 1, 'WARNING | value1=1 value2=2']])
+ self.assert_(svc_bd2.state == 'WARNING')
+ self.assert_(svc_bd2.state_type == 'HARD')
+ self.assert_(svc_bd2.last_hard_state_id == 1)
+
+ # And now the state of the rule must be 2
+ state = bp_rule.get_state()
+ self.assert_(state == 2)
+
+ # And If we set one WARNING too?
+ self.scheduler_loop(2, [[svc_bd1, 1, 'WARNING | value1=1 value2=2']])
+ self.assert_(svc_bd1.state == 'WARNING')
+ self.assert_(svc_bd1.state_type == 'HARD')
+ self.assert_(svc_bd1.last_hard_state_id == 1)
+
+ # Must be WARNING (worse no 0 value for both)
+ state = bp_rule.get_state()
+ self.assert_(state == 1)
+
+ # Now try to get ok in both place, should be bad :)
+ self.scheduler_loop(2, [[svc_bd1, 0, 'OK | value1=1 value2=2'], [svc_bd2, 0, 'OK | value1=1 value2=2']])
+ self.assert_(svc_bd1.state == 'OK')
+ self.assert_(svc_bd1.state_type == 'HARD')
+ self.assert_(svc_bd1.last_hard_state_id == 0)
+ self.assert_(svc_bd2.state == 'OK')
+ self.assert_(svc_bd2.state_type == 'HARD')
+ self.assert_(svc_bd2.last_hard_state_id == 0)
+
+ # Must be CRITICAL (ok and not ok IS no OK :) )
+ state = bp_rule.get_state()
+ self.assert_(state == 2)
+
+
+
+
class TestConfigBroken(ShinkenTest):
"""A class with a broken configuration, where business rules reference unknown hosts/services"""
def setUp(self):
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list