Add : the full demoCA certification autority so people can sign their own keys.
[shinken.git] / shinken / contactdowntime.py
blob1d7594eda12177b6663fdd812b1ddebf7d36b6b4
1 #!/usr/bin/env python
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/>.
22 import time
23 from comment import Comment
25 class ContactDowntime:
26 id = 1
28 #Just to list the properties we will send as pickle
29 #so to others daemons, so all but NOT REF
30 properties = {
31 #'activate_me' : None,
32 #'entry_time' : None,
33 #'fixed' : None,
34 'start_time' : None,
35 #'duration' : None,
36 #'trigger_id' : None,
37 'end_time' : None,
38 #'real_end_time' : None,
39 'author' : None,
40 'comment' : 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
57 self.author = author
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):
66 now = time.time()
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:
73 self.enter()
75 # Same for exit purpose
76 if was_is_in_effect and not self.is_in_effect:
77 self.exit()
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
86 def enter(self):
87 self.ref.raise_enter_downtime_log_entry()
90 #The end of the downtime was reached.
91 def exit(self):
92 self.ref.raise_exit_downtime_log_entry()
93 self.can_be_deleted = True
96 # A scheduled downtime was prematurely cancelled
97 def cancel(self):
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()
108 cls = self.__class__
109 #id is not in *_properties
110 res = [self.id]
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
115 res.reverse()
116 return res
119 #Inversed funtion of getstate
120 def __setstate__(self, state):
121 cls = self.__class__
122 self.id = state.pop()
123 for prop in cls.properties:
124 val = state.pop()
125 setattr(self, prop, val)