2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
5 # Gregory Starck, g.starck@gmail.com
6 # Hartmut Goebel, h.goebel@goebel-consult.de
8 #This file is part of Shinken.
10 #Shinken is free software: you can redistribute it and/or modify
11 #it under the terms of the GNU Affero General Public License as published by
12 #the Free Software Foundation, either version 3 of the License, or
13 #(at your option) any later version.
15 #Shinken is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 #GNU Affero General Public License for more details.
20 #You should have received a copy of the GNU Affero General Public License
21 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
27 class ContactDowntime
:
30 #Just to list the properties we will send as pickle
31 #so to others daemons, so all but NOT REF
40 #'real_end_time': None,
44 #'has_been_triggered': None,
45 'can_be_deleted': None,
50 # Scheduler a contactr downtime. It's far mroe easy than a host/service
51 # one because we got a start, and a end. That's all for running.
52 # got also an author and a comment for logging purpose.
53 def __init__(self
, ref
, start_time
, end_time
, author
, comment
):
54 self
.id = self
.__class
__.id
55 self
.__class
__.id += 1
56 self
.ref
= ref
#pointer to srv or host we are apply
57 self
.start_time
= start_time
58 self
.end_time
= end_time
60 self
.comment
= comment
61 self
.is_in_effect
= False
62 self
.can_be_deleted
= False
63 #self.add_automatic_comment()
66 # Check if we came into the activation of this downtime
67 def check_activation(self
):
69 was_is_in_effect
= self
.is_in_effect
70 self
.is_in_effect
= (self
.start_time
<= now
<= self
.end_time
)
71 print "CHECK ACTIVATION:", self
.is_in_effect
73 # Raise a log entry when we get in the downtime
74 if not was_is_in_effect
and self
.is_in_effect
:
77 # Same for exit purpose
78 if was_is_in_effect
and not self
.is_in_effect
:
82 def in_scheduled_downtime(self
):
83 return self
.is_in_effect
86 #The referenced host/service object enters now a (or another) scheduled
87 #downtime. Write a log message only if it was not already in a downtime
89 self
.ref
.raise_enter_downtime_log_entry()
92 #The end of the downtime was reached.
94 self
.ref
.raise_exit_downtime_log_entry()
95 self
.can_be_deleted
= True
98 # A scheduled downtime was prematurely cancelled
100 self
.is_in_effect
= False
101 self
.ref
.raise_cancel_downtime_log_entry()
102 self
.can_be_deleted
= True
106 #Call by picle for dataify the coment
107 #because we DO NOT WANT REF in this pickleisation!
108 def __getstate__(self
):
109 # print "Asking a getstate for a downtime on", self.ref.get_dbg_name()
111 #id is not in *_properties
113 for prop
in cls
.properties
:
114 res
.append(getattr(self
, prop
))
115 #We reverse because we want to recreate
116 #By check at properties in the same order
121 #Inversed funtion of getstate
122 def __setstate__(self
, state
):
124 self
.id = state
.pop()
125 for prop
in cls
.properties
:
127 setattr(self
, prop
, val
)
128 if self
.id >= cls
.id: