2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
6 #This file is part of Shinken.
8 #Shinken is free software: you can redistribute it and/or modify
9 #it under the terms of the GNU Affero General Public License as published by
10 #the Free Software Foundation, either version 3 of the License, or
11 #(at your option) any later version.
13 #Shinken is distributed in the hope that it will be useful,
14 #but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 #GNU Affero General Public License for more details.
18 #You should have received a copy of the GNU Affero General Public License
19 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
23 from comment
import Comment
25 class ContactDowntime
:
28 #Just to list the properties we will send as pickle
29 #so to others daemons, so all but NOT REF
31 #'activate_me' : None,
38 #'real_end_time' : None,
41 'is_in_effect' : None,
42 #'has_been_triggered' : None,
43 'can_be_deleted' : None,
48 # Scheduler a contactr downtime. It's far mroe easy than a host/service
49 # one because we got a start, and a end. That's all for running.
50 # got also an author and a comment for logging purpose.
51 def __init__(self
, ref
, start_time
, end_time
, author
, comment
):
52 self
.id = self
.__class
__.id
53 self
.__class
__.id += 1
54 self
.ref
= ref
#pointer to srv or host we are apply
55 self
.start_time
= start_time
56 self
.end_time
= end_time
58 self
.comment
= comment
59 self
.is_in_effect
= False
60 self
.can_be_deleted
= False
61 #self.add_automatic_comment()
64 # Check if we came into the activation of this downtime
65 def check_activation(self
):
67 was_is_in_effect
= self
.is_in_effect
68 self
.is_in_effect
= (self
.start_time
<= now
<= self
.end_time
)
69 print "CHECK ACTIVATION:", self
.is_in_effect
71 # Raise a log entry when we get in the downtime
72 if not was_is_in_effect
and self
.is_in_effect
:
75 # Same for exit purpose
76 if was_is_in_effect
and not self
.is_in_effect
:
80 def in_scheduled_downtime(self
):
81 return self
.is_in_effect
84 #The referenced host/service object enters now a (or another) scheduled
85 #downtime. Write a log message only if it was not already in a downtime
87 self
.ref
.raise_enter_downtime_log_entry()
90 #The end of the downtime was reached.
92 self
.ref
.raise_exit_downtime_log_entry()
93 self
.can_be_deleted
= True
96 # A scheduled downtime was prematurely cancelled
98 self
.is_in_effect
= False
99 self
.ref
.raise_cancel_downtime_log_entry()
100 self
.can_be_deleted
= True
104 #Call by picle for dataify the coment
105 #because we DO NOT WANT REF in this pickleisation!
106 def __getstate__(self
):
107 # print "Asking a getstate for a downtime on", self.ref.get_dbg_name()
109 #id is not in *_properties
111 for prop
in cls
.properties
:
112 res
.append(getattr(self
, prop
))
113 #We reverse because we want to recreate
114 #By check at properties in the same order
119 #Inversed funtion of getstate
120 def __setstate__(self
, state
):
122 self
.id = state
.pop()
123 for prop
in cls
.properties
:
125 setattr(self
, prop
, val
)