Clean : (Grégory Starck) clean of some getattr code, bis.
[shinken.git] / shinken / serviceescalation.py
blobc8e2b56e1ff4b84eacee92acacafb52a12dfe0f7
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/>.
21 from item import Item, Items
22 from util import to_int, to_split
23 from escalation import Escalation
24 from shinken.property import UnusedProp, BoolProp, IntegerProp, FloatProp, CharProp, StringProp, ListProp
26 class Serviceescalation(Item):
27 id = 1 #0 is always special in database, so we do not take risk here
28 my_type = 'serviceescalation'
30 properties={'host_name' : StringProp(),
31 'hostgroup_name' : StringProp(),
32 'service_description' : StringProp(),
33 'first_notification' : IntegerProp(),
34 'last_notification' : IntegerProp(),
35 'notification_interval' : IntegerProp(),
36 'escalation_period' : StringProp(default=''),
37 'escalation_options' : ListProp(default='d,u,r,w,c'),
38 'contacts' : StringProp(),
39 'contact_groups' : StringProp(),
42 running_properties = {}
45 macros = {}
48 #For debugging purpose only (nice name)
49 def get_name(self):
50 return ''
53 class Serviceescalations(Items):
54 name_property = ""
55 inner_class = Serviceescalation
58 #We look for contacts property in contacts and
59 def explode(self, escalations):
60 #Now we explode all escalations (host_name, service_description) to escalations
61 for es in self:
62 properties = es.__class__.properties
64 creation_dict = {'escalation_name' : 'Generated-Serviceescalation-%d' % es.id}
65 for prop in properties:
66 if hasattr(es, prop):
67 creation_dict[prop] = getattr(es, prop)
68 #print "Creation an escalation with :", creation_dict
69 s = Escalation(creation_dict)
70 escalations.add_escalation(s)