@@ -1244,10 +1244,6 @@ def schedule(self, hosts, services, timeperiods, macromodulations, checkmodulati
1244
1244
self .get_full_name (),
1245
1245
datetime .datetime .fromtimestamp (self .next_chk ).strftime ('%Y-%m-%d %H:%M:%S' ),
1246
1246
interval , time_add )
1247
- print ("-> schedule: %s / %s (interval: %d, added: %d)" ,
1248
- self .get_full_name (),
1249
- datetime .datetime .fromtimestamp (self .next_chk ).strftime ('%Y-%m-%d %H:%M:%S' ),
1250
- interval , time_add )
1251
1247
# Get the command to launch, and put it in queue
1252
1248
return self .launch_check (self .next_chk , hosts , services , timeperiods , macromodulations ,
1253
1249
checkmodulations , checks , force = force )
@@ -1526,7 +1522,7 @@ def update_hard_unknown_phase_state(self):
1526
1522
1527
1523
def consume_result (self , chk , notif_period , hosts ,
1528
1524
services , timeperiods , macromodulations , checkmodulations , bi_modulations ,
1529
- res_modulations , checks ):
1525
+ res_modulations , checks , raise_log ):
1530
1526
# pylint: disable=too-many-locals, too-many-arguments
1531
1527
# pylint: disable=too-many-branches, too-many-statements
1532
1528
"""Consume a check return and send action in return
@@ -1662,6 +1658,10 @@ def consume_result(self, chk, notif_period, hosts,
1662
1658
self .last_state_type = self .state_type
1663
1659
self .return_code = chk .exit_status
1664
1660
1661
+ # Raise the log only when the item information are up-to-date :/
1662
+ if raise_log :
1663
+ self .raise_check_result ()
1664
+
1665
1665
# we change the state, do whatever we are or not in
1666
1666
# an impact mode, we can put it
1667
1667
self .state_changed_since_impact = True
@@ -1889,6 +1889,7 @@ def consume_result(self, chk, notif_period, hosts,
1889
1889
self .get_perfdata_command (hosts , macromodulations , timeperiods )
1890
1890
# Also snapshot if need :)
1891
1891
self .get_snapshot (hosts , macromodulations , timeperiods )
1892
+
1892
1893
return []
1893
1894
1894
1895
def update_event_and_problem_id (self ):
@@ -1977,12 +1978,12 @@ def update_notification_command(self, notif, contact, macromodulations, timeperi
1977
1978
if cls .enable_environment_macros or notif .enable_environment_macros :
1978
1979
notif .env = macrosolver .get_env_macros (data )
1979
1980
1980
- def is_escalable (self , notif , escalations , timeperiods ):
1981
+ def is_escalable (self , notification , escalations , timeperiods ):
1981
1982
"""Check if a notification can be escalated.
1982
1983
Basically call is_eligible for each escalation
1983
1984
1984
- :param notif : notification we would like to escalate
1985
- :type notif : alignak.objects.notification.Notification
1985
+ :param notification : notification we would like to escalate
1986
+ :type notification : alignak.objects.notification.Notification
1986
1987
:param escalations: Esclations objects, used to get escalation objects (period)
1987
1988
:type escalations: alignak.objects.escalation.Escalations
1988
1989
:param timeperiods: Timeperiods objects, used to get escalation period
@@ -1994,14 +1995,14 @@ def is_escalable(self, notif, escalations, timeperiods):
1994
1995
1995
1996
# We search since when we are in notification for escalations
1996
1997
# that are based on time
1997
- in_notif_time = time .time () - notif .creation_time
1998
+ in_notif_time = time .time () - notification .creation_time
1998
1999
1999
2000
# Check is an escalation match the current_notification_number
2000
- for escal_id in self .escalations :
2001
- escal = escalations [escal_id ]
2002
- escal_period = timeperiods [escal .escalation_period ]
2003
- if escal .is_eligible (notif .t_to_go , self .state , notif .notif_nb ,
2004
- in_notif_time , cls .interval_length , escal_period ):
2001
+ for escalation_id in self .escalations :
2002
+ escalation = escalations [escalation_id ]
2003
+ escalation_period = timeperiods [escalation .escalation_period ]
2004
+ if escalation .is_eligible (notification .t_to_go , self .state , notification .notif_nb ,
2005
+ in_notif_time , cls .interval_length , escalation_period ):
2005
2006
return True
2006
2007
2007
2008
return False
@@ -2030,14 +2031,14 @@ def get_next_notification_time(self, notif, escalations, timeperiods):
2030
2031
# and then look for currently active notifications, and take notification_interval
2031
2032
# if filled and less than the self value
2032
2033
in_notif_time = time .time () - notif .creation_time
2033
- for escal_id in self .escalations :
2034
- escal = escalations [escal_id ]
2035
- escal_period = timeperiods [escal .escalation_period ]
2036
- if escal .is_eligible (notif .t_to_go , self .state , notif .notif_nb ,
2037
- in_notif_time , cls .interval_length , escal_period ):
2038
- if escal .notification_interval != - 1 and \
2039
- escal .notification_interval < notification_interval :
2040
- notification_interval = escal .notification_interval
2034
+ for escalation_id in self .escalations :
2035
+ escalation = escalations [escalation_id ]
2036
+ escalation_period = timeperiods [escalation .escalation_period ]
2037
+ if escalation .is_eligible (notif .t_to_go , self .state , notif .notif_nb ,
2038
+ in_notif_time , cls .interval_length , escalation_period ):
2039
+ if escalation .notification_interval != - 1 and \
2040
+ escalation .notification_interval < notification_interval :
2041
+ notification_interval = escalation .notification_interval
2041
2042
2042
2043
# So take the by default time
2043
2044
std_time = notif .t_to_go + notification_interval * cls .interval_length
@@ -2054,25 +2055,26 @@ def get_next_notification_time(self, notif, escalations, timeperiods):
2054
2055
creation_time = notif .creation_time
2055
2056
in_notif_time = now - notif .creation_time
2056
2057
2057
- for escal_id in self .escalations :
2058
- escal = escalations [escal_id ]
2058
+ for escalation_id in self .escalations :
2059
+ escalation = escalations [escalation_id ]
2059
2060
# If the escalation was already raised, we do not look for a new "early start"
2060
- if escal .get_name () not in notif .already_start_escalations :
2061
- escal_period = timeperiods [escal .escalation_period ]
2062
- next_t = escal .get_next_notif_time (std_time , self .state ,
2063
- creation_time , cls .interval_length , escal_period )
2061
+ if escalation .get_name () not in notif .already_start_escalations :
2062
+ escalation_period = timeperiods [escalation .escalation_period ]
2063
+ next_t = escalation .get_next_notif_time (std_time , self .state ,
2064
+ creation_time , cls .interval_length ,
2065
+ escalation_period )
2064
2066
# If we got a real result (time base escalation), we add it
2065
2067
if next_t is not None and now < next_t < res :
2066
2068
res = next_t
2067
2069
2068
2070
# And we take the minimum of this result. Can be standard or escalation asked
2069
2071
return res
2070
2072
2071
- def get_escalable_contacts (self , notif , escalations , timeperiods ):
2073
+ def get_escalable_contacts (self , notification , escalations , timeperiods ):
2072
2074
"""Get all contacts (uniq) from eligible escalations
2073
2075
2074
- :param notif : Notification to get data from (notif number...)
2075
- :type notif : alignak.objects.notification.Notification
2076
+ :param notification : Notification to get data from (notif number...)
2077
+ :type notification : alignak.objects.notification.Notification
2076
2078
:param escalations: Esclations objects, used to get escalation objects (contact, period)
2077
2079
:type escalations: alignak.objects.escalation.Escalations
2078
2080
:param timeperiods: Timeperiods objects, used to get escalation period
@@ -2085,17 +2087,18 @@ def get_escalable_contacts(self, notif, escalations, timeperiods):
2085
2087
2086
2088
# We search since when we are in notification for escalations
2087
2089
# that are based on this time
2088
- in_notif_time = time .time () - notif .creation_time
2090
+ in_notif_time = time .time () - notification .creation_time
2089
2091
2090
2092
contacts = set ()
2091
- for escal_id in self .escalations :
2092
- escal = escalations [escal_id ]
2093
- escal_period = timeperiods [escal .escalation_period ]
2094
- if escal .is_eligible (notif .t_to_go , self .state , notif .notif_nb ,
2095
- in_notif_time , cls .interval_length , escal_period ):
2096
- contacts .update (escal .contacts )
2093
+ for escalation_id in self .escalations :
2094
+ escalation = escalations [escalation_id ]
2095
+
2096
+ escalation_period = timeperiods [escalation .escalation_period ]
2097
+ if escalation .is_eligible (notification .t_to_go , self .state , notification .notif_nb ,
2098
+ in_notif_time , cls .interval_length , escalation_period ):
2099
+ contacts .update (escalation .contacts )
2097
2100
# And we tag this escalations as started now
2098
- notif .already_start_escalations .add (escal .get_name ())
2101
+ notification .already_start_escalations .add (escalation .get_name ())
2099
2102
2100
2103
return list (contacts )
2101
2104
@@ -2219,55 +2222,59 @@ def scatter_notification(self, notif, contacts, notifways, timeperiods, macromod
2219
2222
cls = self .__class__
2220
2223
childnotifications = []
2221
2224
escalated = False
2222
- notif_contacts = []
2225
+ notification_contacts = []
2223
2226
if notif .type == u'RECOVERY' :
2224
2227
if self .first_notification_delay != 0 and not self .notified_contacts :
2225
2228
# Recovered during first_notification_delay. No notifications
2226
2229
# have been sent yet, so we keep quiet
2227
- notif_contacts = []
2230
+ notification_contacts = []
2228
2231
else :
2229
2232
# The old way. Only send recover notifications to those contacts
2230
2233
# who also got problem notifications
2231
- notif_contacts = [c_id for c_id in self .notified_contacts ]
2234
+ notification_contacts = [c_id for c_id in self .notified_contacts ]
2232
2235
self .notified_contacts .clear ()
2233
2236
else :
2234
2237
# Check is an escalation match. If yes, get all contacts from escalations
2235
2238
if self .is_escalable (notif , escalations , timeperiods ):
2236
- notif_contacts = self .get_escalable_contacts (notif , escalations , timeperiods )
2239
+ notification_contacts = self .get_escalable_contacts (notif , escalations , timeperiods )
2237
2240
escalated = True
2238
2241
# else take normal contacts
2239
2242
else :
2240
2243
# notif_contacts = [contacts[c_id] for c_id in self.contacts]
2241
- notif_contacts = self .contacts
2244
+ notification_contacts = self .contacts
2242
2245
2243
- for contact_id in notif_contacts :
2244
- contact = contacts [contact_id ]
2246
+ recipients = []
2247
+ recipients_names = []
2248
+ for contact_uuid in notification_contacts :
2245
2249
# We do not want to notify again a contact with notification interval == 0
2246
2250
# if has been already notified except if the item hard state changed!
2247
2251
# This can happen when a service exits a downtime and it is still in
2248
2252
# critical/warning (and not acknowledge)
2249
- if notif .type == u'PROBLEM' and \
2250
- self .notification_interval == 0 \
2253
+ if notif .type == u'PROBLEM' and self .notification_interval == 0 \
2251
2254
and self .state_type == 'HARD' and self .last_state_type == self .state_type \
2252
2255
and self .state == self .last_state \
2253
2256
and contact .uuid in self .notified_contacts :
2254
2257
# Do not send notification
2255
2258
continue
2259
+ recipients .append (contact_uuid )
2260
+ recipients_names .append (contacts [contact_uuid ].contact_name )
2261
+
2262
+ for contact_uuid in recipients :
2263
+ contact = contacts [contact_uuid ]
2264
+
2256
2265
# Get the property name for notification commands, like
2257
2266
# service_notification_commands for service
2258
2267
notif_commands = contact .get_notification_commands (notifways , cls .my_type )
2259
2268
2260
2269
for cmd in notif_commands :
2261
- # Get the notification recipients list
2262
- recipients = ',' .join ([contacts [c_uuid ].contact_name for c_uuid in notif_contacts ])
2263
2270
data = {
2264
2271
'type' : notif .type ,
2265
2272
'command' : u'VOID' ,
2266
2273
'command_call' : cmd ,
2267
2274
'ref' : self .uuid ,
2268
2275
'contact' : contact .uuid ,
2269
2276
'contact_name' : contact .contact_name ,
2270
- 'recipients' : recipients ,
2277
+ 'recipients' : recipients_names ,
2271
2278
't_to_go' : notif .t_to_go ,
2272
2279
'escalated' : escalated ,
2273
2280
'timeout' : cls .notification_timeout ,
@@ -2429,7 +2436,6 @@ def launch_check(self, timestamp, hosts, services, timeperiods,
2429
2436
self .checks_in_progress .append (chk .uuid )
2430
2437
2431
2438
self .update_in_checking ()
2432
- print ("Check: %s" % chk )
2433
2439
2434
2440
# We need to put this new check in our actions queue
2435
2441
# so scheduler can take it
0 commit comments