Skip to content

Commit

Permalink
Merge pull request #361 from Alignak-monitoring/develop+freshness_pas…
Browse files Browse the repository at this point in the history
…sivecheck

Add freshness_state, some fixes on passive and freshness + add tests
  • Loading branch information
Sébastien Coavoux committed Sep 29, 2016
2 parents 624490e + d265890 commit f5606d7
Show file tree
Hide file tree
Showing 12 changed files with 428 additions and 288 deletions.
2 changes: 1 addition & 1 deletion .pylintrc

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions alignak/objects/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

from alignak.autoslots import AutoSlots
from alignak.util import format_t_into_dhms_format
from alignak.property import BoolProp, IntegerProp, StringProp, ListProp
from alignak.property import BoolProp, IntegerProp, StringProp, ListProp, CharProp
from alignak.log import logger, naglog_result


Expand Down Expand Up @@ -133,6 +133,8 @@ class Host(SchedulingItem): # pylint: disable=R0904
StringProp(default='', fill_brok=['full_status']),
'statusmap_image':
StringProp(default='', fill_brok=['full_status']),
'freshness_state':
CharProp(default='d', fill_brok=['full_status']),

# No slots for this 2 because begin property by a number seems bad
# it's stupid!
Expand Down Expand Up @@ -597,12 +599,12 @@ def raise_freshness_log_entry(self, t_stale_by, t_threshold):
:type t_threshold: int
:return: None
"""
logger.warning("The results of host '%s' are stale by %s "
"(threshold=%s). I'm forcing an immediate check "
"of the host.",
logger.warning("The freshness period of host '%s' is expired by %s "
"(threshold=%s). I'm forcing the state to freshness state (%s).",
self.get_name(),
format_t_into_dhms_format(t_stale_by),
format_t_into_dhms_format(t_threshold))
format_t_into_dhms_format(t_threshold),
self.freshness_state)

def raise_notification_log_entry(self, notif, contact, host_ref=None):
"""Raise HOST NOTIFICATION entry (critical level)
Expand Down
86 changes: 51 additions & 35 deletions alignak/objects/schedulingitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ class SchedulingItem(Item): # pylint: disable=R0902
'check_period':
StringProp(fill_brok=['full_status'],
special=True),
# Set a default freshness threshold not 0 if parameter is missing
# and check_freshness is enabled
'check_freshness':
BoolProp(default=False, fill_brok=['full_status']),
'freshness_threshold':
IntegerProp(default=0, fill_brok=['full_status']),
IntegerProp(default=3600, fill_brok=['full_status']),

'event_handler':
StringProp(default='', fill_brok=['full_status']),
'event_handler_enabled':
Expand Down Expand Up @@ -631,31 +634,46 @@ def do_check_freshness(self, hosts, services, timeperiods, macromodulations, che
# Before, check if class (host or service) have check_freshness OK
# Then check if item want freshness, then check freshness
cls = self.__class__
if not self.in_checking:
if cls.global_check_freshness:
if self.check_freshness and self.freshness_threshold != 0:
if self.last_state_update < now - (
self.freshness_threshold + cls.additional_freshness_latency
):
# Fred: Do not raise a check for passive
# only checked hosts when not in check period ...
if self.passive_checks_enabled and not self.active_checks_enabled:
timeperiod = timeperiods[self.check_period]
if timeperiod is None or timeperiod.is_time_valid(now):
# Raise a log
self.raise_freshness_log_entry(
int(now - self.last_state_update),
int(now - self.freshness_threshold)
)
# And a new check
return self.launch_check(now, hosts, services, timeperiods,
macromodulations, checkmodulations, checks)
else:
logger.debug(
"Should have checked freshness for passive only"
" checked host:%s, but host is not in check period.",
self.host_name
)
if not self.in_checking and cls.global_check_freshness:
if self.freshness_threshold != 0:
# If we start alignak, we begin the freshness period
if self.last_state_update == 0.0:
self.last_state_update = now
if self.last_state_update < now - (
self.freshness_threshold + cls.additional_freshness_latency
):
# Do not raise a check for passive only checked hosts
# when not in check period ...
if not self.active_checks_enabled:
timeperiod = timeperiods[self.check_period]
if timeperiod is None or timeperiod.is_time_valid(now):
# Raise a log
self.raise_freshness_log_entry(
int(now - self.last_state_update),
int(now - self.freshness_threshold)
)
# And a new check
chk = self.launch_check(now, hosts, services, timeperiods,
macromodulations, checkmodulations, checks)
chk.output = "Freshness period expired"
chk.set_type_passive()
if self.freshness_state == 'o':
chk.exit_status = 0
elif self.freshness_state == 'w':
chk.exit_status = 1
elif self.freshness_state == 'd':
chk.exit_status = 2
elif self.freshness_state == 'c':
chk.exit_status = 2
elif self.freshness_state == 'u':
chk.exit_status = 3
return chk
else:
logger.debug(
"Should have checked freshness for passive only"
" checked host:%s, but host is not in check period.",
self.host_name
)
return None

def set_myself_as_problem(self, hosts, services, timeperiods, bi_modulations):
Expand Down Expand Up @@ -1083,15 +1101,13 @@ def raise_dependencies_check(self, ref_check, hosts, services, timeperiods, macr
# if the update is 'fresh', do not raise dep,
# cached_check_horizon = cached_service_check_horizon for service
if dep.last_state_update < now - cls.cached_check_horizon:
# Fred : passive only checked host dependency ...
chk = dep.launch_check(now, hosts, services, timeperiods, macromodulations,
checkmodulations, checks, ref_check, dependent=True)
# i = dep.launch_check(now, ref_check)
if chk is not None:
new_checks.append(chk)
# else:
# print "DBG: **************** The state is FRESH",
# dep.host_name, time.asctime(time.localtime(dep.last_state_update))
# Do not launch check if dependency is a passively checked item
if dep.active_checks_enabled:
chk = dep.launch_check(now, hosts, services, timeperiods,
macromodulations, checkmodulations, checks,
ref_check, dependent=True)
if chk is not None:
new_checks.append(chk)
return new_checks

def schedule(self, hosts, services, timeperiods, macromodulations, checkmodulations,
Expand Down
13 changes: 8 additions & 5 deletions alignak/objects/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
generate_key_value_sequences,
is_complex_expr,
KeyValueSyntaxError)
from alignak.property import BoolProp, IntegerProp, StringProp, ListProp
from alignak.property import BoolProp, IntegerProp, StringProp, ListProp, CharProp
from alignak.log import logger, naglog_result


Expand Down Expand Up @@ -133,6 +133,9 @@ class Service(SchedulingItem):
'host_dependency_enabled':
BoolProp(default=True, fill_brok=['full_status']),

'freshness_state':
CharProp(default='u', fill_brok=['full_status']),

# Easy Service dep definition
'service_dependencies':
ListProp(default=[], merging='join', split_on_coma=True, keep_empty=True),
Expand Down Expand Up @@ -621,12 +624,12 @@ def raise_freshness_log_entry(self, t_stale_by, t_threshold):
:type t_threshold: int
:return: None
"""
logger.warning("The results of service '%s' on host '%s' are stale "
"by %s (threshold=%s). I'm forcing an immediate check "
"of the service.",
logger.warning("The freshness period of service '%s' on host '%s' is expired "
"by %s (threshold=%s). I'm forcing the state to freshness state (%s).",
self.get_name(), self.host_name,
format_t_into_dhms_format(t_stale_by),
format_t_into_dhms_format(t_threshold))
format_t_into_dhms_format(t_threshold),
self.freshness_state)

def raise_notification_log_entry(self, notif, contact, host_ref):
"""Raise SERVICE NOTIFICATION entry (critical level)
Expand Down
31 changes: 17 additions & 14 deletions alignak/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,15 @@ def __init__(self, scheduler_daemon):
self.recurrent_works = {
0: ('update_downtimes_and_comments', self.update_downtimes_and_comments, 1),
1: ('schedule', self.schedule, 1), # just schedule
2: ('consume_results', self.consume_results, 1), # incorporate checks and dependencies
2: ('check_freshness', self.check_freshness, 10),
3: ('consume_results', self.consume_results, 1), # incorporate checks and dependencies

# now get the news actions (checks, notif) raised
3: ('get_new_actions', self.get_new_actions, 1),
4: ('get_new_broks', self.get_new_broks, 1), # and broks
5: ('scatter_master_notifications', self.scatter_master_notifications, 1),
6: ('delete_zombie_checks', self.delete_zombie_checks, 1),
7: ('delete_zombie_actions', self.delete_zombie_actions, 1),
# 3: (self.delete_unwanted_notifications, 1),
8: ('check_freshness', self.check_freshness, 10),
4: ('get_new_actions', self.get_new_actions, 1),
5: ('get_new_broks', self.get_new_broks, 1), # and broks
6: ('scatter_master_notifications', self.scatter_master_notifications, 1),
7: ('delete_zombie_checks', self.delete_zombie_checks, 1),
8: ('delete_zombie_actions', self.delete_zombie_actions, 1),
9: ('clean_caches', self.clean_caches, 1),
10: ('update_retention_file', self.update_retention_file, 3600),
11: ('check_orphaned', self.check_orphaned, 60),
Expand Down Expand Up @@ -1763,16 +1762,20 @@ def get_new_broks(self):
elt.broks = []

def check_freshness(self):
"""Iter over all hosts and services to check freshness
"""
Iter over all hosts and services to check freshness if check_freshness enabled and
passive_checks_enabled enabled
:return: None
"""
# print "********** Check freshness******"
for elt in self.iter_hosts_and_services():
chk = elt.do_check_freshness(self.hosts, self.services, self.timeperiods,
self.macromodulations, self.checkmodulations, self.checks)
if chk is not None:
self.add(chk)
if elt.check_freshness and elt.passive_checks_enabled:
chk = elt.do_check_freshness(self.hosts, self.services, self.timeperiods,
self.macromodulations, self.checkmodulations,
self.checks)
if chk is not None:
self.add(chk)
self.waiting_results.put(chk)

def check_orphaned(self):
"""Check for orphaned checks/actions::
Expand Down
18 changes: 0 additions & 18 deletions test/_old/etc/alignak_freshness.cfg

This file was deleted.

0 comments on commit f5606d7

Please sign in to comment.