Skip to content

Commit f19f687

Browse files
author
Flavien Peyre
committed
Add: BP rules: host/service in downtime as object with OK state
1 parent ae17749 commit f19f687

File tree

10 files changed

+298
-11
lines changed

10 files changed

+298
-11
lines changed

doc/source/06_medium/business-rules.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,12 @@ Imagine you want to build a consolidated service which notifications contain lin
482482

483483
The resulting output would look like ``Down web services: link1 link2 link3 ...`` where ``linkN`` are urls leading to the problem in the WebUI.
484484

485-
Acknowledge management
485+
Acknowledge and downtime management
486486
======================
487487

488-
By default, if we acknowledge an element, it conserves its state to determine the status of our aggregated service.
489-
In some cases, we want that an acknowledge element is considered as if it was in Ok/Up state for a business rule.
488+
By default, if we acknowledge or downtime an element, it conserves its state to determine the status of our aggregated service.
489+
In some cases, we want that an acknowledge/downtime element is considered as if it was in Ok/Up state for a business rule.
490490

491-
To enable this feature, simply set `business_rule_ack_as_ok`` to ``1``..
491+
To enable this feature, simply set `business_rule_ack_as_ok`` to ``1`` for acknowledge, `business_rule_downtime_as_ok`` to ``1`` for downtime ..
492492

493493
.. _ticket: https://github.com/naparuba/shinken/issues/509

doc/source/08_configobjects/host.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ labels *labels*
7979
business_rule_output_template *template*
8080
business_rule_smart_notifications [0/1]
8181
business_rule_downtime_as_ack [0/1]
82+
business_rule_downtime_as_ok [0/1]
8283
business_rule_ack_as_ok [0/1]
8384
business_rule_host_notification_options [d,u,r,f,s]
8485
business_rule_service_notification_options [w,u,c,r,f,s]
@@ -328,6 +329,9 @@ business_rule_downtime_as_ack
328329
business_rule_ack_as_ok
329330
By default, acknowledging an underlying problem doesn't change its state for the :ref:`business rules <medium/business-rules>` evaluation. This variable allows to treat acknowledged services or hosts as if their are in an Ok/Up state.
330331

332+
business_rule_downtime_as_ok
333+
By default, marking an underlying problem as downtime doesn't change its state for the :ref:`business rules <medium/business-rules>` evaluation. This variable allows to treat services or hosts in downtime as if their are in an Ok/Up state.
334+
331335
business_rule_host_notification_options
332336
This option allows to enforce :ref:`business rules <medium/business-rules>` underlying hosts notification options to easily compose a consolidated meta check. This is especially useful for business rules relying on grouping expansion.
333337

doc/source/08_configobjects/service.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ business_rule_output_template *template*
7171
business_rule_smart_notifications [0/1]
7272
business_rule_downtime_as_ack [0/1]
7373
business_rule_ack_as_ok [0/1]
74+
business_rule_downtime_as_ok [0/1]
7475
business_rule_host_notification_options [d,u,r,f,s]
7576
business_rule_service_notification_options [w,u,c,r,f,s]
7677
snapshot_enabled [0/1]
@@ -406,6 +407,9 @@ business_rule_downtime_as_ack
406407
business_rule_ack_as_ok
407408
By default, acknowledging an underlying problem doesn't change its state for the :ref:`business rules <medium/business-rules>` evaluation. This variable allows to treat acknowledged services or hosts as if their are in an Ok/Up state.
408409

410+
business_rule_downtime_as_ok
411+
By default, marking an underlying problem as downtime doesn't change its state for the :ref:`business rules <medium/business-rules>` evaluation. This variable allows to treat services or hosts in downtime as if their are in an Ok/Up state.
412+
409413
business_rule_host_notification_options
410414
This option allows to enforce :ref:`business rules <medium/business-rules>` underlying hosts notification options to easily compose a consolidated meta check. This is especially useful for business rules relying on grouping expansion.
411415

shinken/dependencynode.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646

4747
class DependencyNode(object):
48-
def __init__(self, ack_as_ok=False):
48+
def __init__(self, ack_as_ok=False, downtime_as_ok=False):
4949
self.operand = None
5050
self.sons = []
5151
# Of: values are a triple OK,WARN,CRIT
@@ -54,6 +54,7 @@ def __init__(self, ack_as_ok=False):
5454
self.configuration_errors = []
5555
self.not_value = False
5656
self.ack_as_ok = ack_as_ok
57+
self.downtime_as_ok = downtime_as_ok
5758

5859
def __str__(self):
5960
return "Op:'%s' Val:'%s' Sons:'[%s]' IsNot:'%s'" % (self.operand, self.of_values,
@@ -97,6 +98,9 @@ def get_simple_node_state(self):
9798
# If our node is acknowledged and business_rule_ack_as_ok is true, state is ok/up
9899
if self.sons[0].problem_has_been_acknowledged and self.ack_as_ok:
99100
state = 0
101+
# If our node is downtimed and business_rule_downtime_as_ok is true, state is ok/up
102+
if self.sons[0].in_scheduled_downtime and self.downtime_as_ok:
103+
state = 0
100104
# Maybe we are a NOT node, so manage this
101105
if self.not_value:
102106
# We inverse our states
@@ -328,7 +332,7 @@ def eval_xof_pattern(self, node, pattern):
328332
# Evaluate a complex correlation expression, such as an &, |, nested
329333
# expressions in par, and so on.
330334
def eval_complex_cor_pattern(self, pattern, hosts, services, running=False):
331-
node = DependencyNode(self.bound_item.business_rule_ack_as_ok)
335+
node = DependencyNode(self.bound_item.business_rule_ack_as_ok, self.bound_item.business_rule_downtime_as_ok)
332336
pattern = self.eval_xof_pattern(node, pattern)
333337

334338
in_par = False
@@ -446,7 +450,7 @@ def eval_complex_cor_pattern(self, pattern, hosts, services, running=False):
446450
# Evaluate a simple correlation expression, such as a host, a host + a
447451
# service, or expand a host or service expression.
448452
def eval_simple_cor_pattern(self, pattern, hosts, services, running=False):
449-
node = DependencyNode(self.bound_item.business_rule_ack_as_ok)
453+
node = DependencyNode(self.bound_item.business_rule_ack_as_ok, self.bound_item.business_rule_downtime_as_ok)
450454
pattern = self.eval_xof_pattern(node, pattern)
451455

452456
# print "Try to find?", pattern
@@ -519,7 +523,7 @@ def find_object(self, pattern, hosts, services):
519523
# using (host|service)group membership, regex, or labels as item selector.
520524
def expand_expression(self, pattern, hosts, services, running=False):
521525
error = None
522-
node = DependencyNode(self.bound_item.business_rule_ack_as_ok)
526+
node = DependencyNode(self.bound_item.business_rule_ack_as_ok, self.bound_item.business_rule_downtime_as_ok)
523527
node.operand = '&'
524528
elts = [e.strip() for e in pattern.split(',')]
525529
# If host_name is empty, use the host_name the business rule is bound to
@@ -561,7 +565,7 @@ def expand_expression(self, pattern, hosts, services, running=False):
561565
# Creates dependency node subtree
562566
for item in items:
563567
# Creates a host/service node
564-
son = DependencyNode(self.bound_item.business_rule_ack_as_ok)
568+
son = DependencyNode(self.bound_item.business_rule_ack_as_ok, self.bound_item.business_rule_downtime_as_ok)
565569
son.operand = item.__class__.my_type
566570
son.sons.append(item)
567571
# Appends it to wrapping node

shinken/objects/host.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ class Host(SchedulingItem):
214214
# Treat acknowledged host/service like an Ok/Up state in a business rule
215215
'business_rule_ack_as_ok':
216216
BoolProp(default=False, fill_brok=['full_status']),
217+
# Treat downtimed host/service like an Ok/Up state in a business rule
218+
'business_rule_downtime_as_ok':
219+
BoolProp(default=False, fill_brok=['full_status']),
217220
# Enforces child nodes notification options
218221
'business_rule_host_notification_options':
219222
ListProp(default=[], fill_brok=['full_status']),

shinken/objects/service.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ class Service(SchedulingItem):
201201
# Treat acknowledged host/service like an Ok/Up state in a business rule
202202
'business_rule_ack_as_ok':
203203
BoolProp(default=False, fill_brok=['full_status']),
204+
# Treat host/service in downtime like an Ok/Up state in a business rule
205+
'business_rule_downtime_as_ok':
206+
BoolProp(default=False, fill_brok=['full_status']),
204207
# Enforces child nodes notification options
205208
'business_rule_host_notification_options':
206209
ListProp(default=[], fill_brok=['full_status'], split_on_coma=True),

test/etc/business_correlator/hosts.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ define host{
1717
retain_status_information 1
1818
retry_interval 1
1919
business_rule_ack_as_ok 1
20+
business_rule_downtime_as_ok 1
2021
}
2122

2223
define host{

test/etc/business_correlator/services.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ define service{
2323
retain_status_information 1
2424
retry_interval 1
2525
business_rule_ack_as_ok 1
26+
business_rule_downtime_as_ok 1
2627
}
2728

2829

0 commit comments

Comments
 (0)