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/>.
21 #The resultmodulation class is used for in scheduler modulation of resulsts
22 #like the return code or the output.
26 from shinken
.item
import Item
, Items
27 from shinken
.util
import to_split
28 from shinken
.property import UnusedProp
, BoolProp
, IntegerProp
, FloatProp
, CharProp
, StringProp
, ListProp
30 class Resultmodulation(Item
):
31 id = 1#0 is always special in database, so we do not take risk here
32 my_type
= 'resultmodulation'
34 properties
= {'resultmodulation_name': StringProp(),
35 'exit_codes_match': ListProp(
37 'exit_code_modulation': StringProp(
39 'modulation_period': StringProp(
42 running_properties
= {}
46 #For debugging purpose only (nice name)
48 return self
.resultmodulation_name
55 #Make the return code modulation if need
56 def module_return(self
, return_code
):
57 #Only if in modulation_period of modulation_period == None
58 if self
.modulation_period
== None or self
.modulation_period
.is_time_valid(time
.time()):
59 #Try to change the exit code only if a new one is defined
60 if self
.exit_code_modulation
!= None:
61 #First with the exit_code_match
62 if return_code
in self
.exit_codes_match
:
63 return_code
= self
.exit_code_modulation
68 #We override the pythonize because we have special cases that we do not want
71 #First apply Item pythonize
72 super(self
.__class
__, self
).pythonize()
74 #Then very special cases
75 if hasattr(self
, 'exit_codes_match'):
77 for ec
in self
.exit_codes_match
:
79 self
.exit_codes_match
= ecm
81 self
.exit_codes_match
= []
83 if hasattr(self
, 'exit_code_modulation'):
84 self
.exit_code_modulation
= int(self
.exit_code_modulation
)
86 self
.exit_code_modulation
= None
91 class Resultmodulations(Items
):
92 name_property
= "resultmodulation_name"
93 inner_class
= Resultmodulation
96 def linkify(self
, timeperiods
):
97 self
.linkify_rm_by_tp(timeperiods
)
100 #We just search for each timeperiod the tp
101 #and replace the name by the tp
102 def linkify_rm_by_tp(self
, timeperiods
):
104 mtp_name
= rm
.modulation_period
106 #The new member list, in id
107 mtp
= timeperiods
.find_by_name(mtp_name
)
109 rm
.modulation_period
= mtp