Fix : get back LiveStatus as default.
[shinken.git] / shinken / property.py
blobc5916a33d35e3cff9406e1578e4e12ca108f60fb
1 # -*- mode: python ; coding: utf-8 -*-
3 # Copyright (C) 2010-2011:
4 # Hartmut Goebel, h.goebel@goebel-consult.de
5 # Gabes Jean, naparuba@gmail.com
6 # Gerhard Lausser, Gerhard.Lausser@consol.de
7 # Gregory Starck, g.starck@gmail.com
8 # Hartmut Goebel, h.goebel@goebel-consult.de
10 # This file is part of Shinken.
12 # Shinken is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU Affero General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # Shinken is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU Affero General Public License for more details.
22 # You should have received a copy of the GNU Affero General Public License
23 # along with Shinken. If not, see <http://www.gnu.org/licenses/>.
24 """
25 """
27 from shinken.util import to_float, to_split, to_char, to_int
29 __all__ = ['UnusedProp', 'BoolProp', 'IntegerProp', 'FloatProp',
30 'CharProp', 'StringProp', 'ListProp',
31 'FULL_STATUS', 'CHECK_RESULT']
33 __author__ = "Hartmut Goebel <h.goebel@goebel-consult.de>"
34 __copyright__ = "Copyright 2010-2011 by Hartmut Goebel <h.goebel@goebel-consult.de>"
35 __licence__ = "GNU Affero General Public License version 3 (AGPL v3)"
38 FULL_STATUS = 'full_status'
39 CHECK_RESULT = 'check_result'
42 none_object = object()
45 class Property(object):
46 """
47 Baseclass of all properties.
49 Same semantic for all subclasses (except UnusedProp): The property
50 is required if, and only if, the default value is `None`.
53 """
54 def __init__(self, default=none_object, class_inherit=None,
55 unmanaged=False, help='', no_slots=False,
56 fill_brok=None, conf_send_preparation=None,
57 brok_transformation=None,retention=False,to_send=False,
58 override=False,managed=True):
59 """
60 `default`: default value to be used if this property is not set.
61 If default is None, this property is requied.
63 `class_inherit`: List of 2-tuples, (Service, 'blabla') : must
64 set this property to the Service class with name
65 blabla. if (Service, None): must set this property
66 to the Service class with same name
67 `unmanaged`: ....
68 `help`: usage text
69 `no_slots`: do not take this property for __slots__
71 `fill_brok`: if set, send to broker. There are two categories:
72 FULL_STATUS for initial and update status,
73 CHECK_RESULT for check results
75 Only for the inital call:
77 conf_send_preparation: if set, will pass the property to this
78 function. It's used to 'flatten' some dangerous
79 properties like realms that are too 'linked' to
80 be send like that.
82 brok_transformation: if set, will call the function with the
83 value of the property the major times it will be
84 to flatten the data (like realm_name instead of
85 the realm object).
87 override : for scheduler, if the property must override the
88 value of the configuration we send
90 managed : property that is managed in Nagios but not in Shinken
92 """
93 self.default = default
94 self.has_default = (default is not none_object)
95 self.required = not self.has_default
96 self.class_inherit = class_inherit or []
97 self.help = help or ''
98 self.unmanaged = unmanaged
99 self.no_slots = no_slots
100 self.fill_brok = fill_brok or []
101 self.conf_send_preparation = conf_send_preparation
102 self.brok_transformation = brok_transformation
103 self.retention = retention
104 self.to_send = to_send
105 self.override = override
106 self.managed = managed
107 self.unused = False
110 class UnusedProp(Property):
112 A unused Property. These are typically used by Nagios but
113 no longer usefull/used by Shinken.
115 This is just to warn the user that the option he use is no more used
116 in Shinken.
118 def __init__(self, text=None):
120 Since this property is not used, there is no use for other
121 parameters than `text`.
123 `text` a some usage text if present, will print it to explain
124 why it's no more useful
126 if text is None:
127 text = ("This parameter is no longer useful in the "
128 "Shinken architecture.")
129 self.text = text
130 self.has_default = False
131 self.class_inherit = []
132 self.unused = True
133 self.managed = True
136 _boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True,
137 '0': False, 'no': False, 'false': False, 'off': False}
140 class BoolProp(Property):
142 A Boolean Property.
144 Boolean values are currently case insensitively defined as 0,
145 false, no, off for False, and 1, true, yes, on for True).
147 # @staticmethod
148 def pythonize(self, val):
149 return _boolean_states[val.lower()]
152 class IntegerProp(Property):
153 # @staticmethod
154 def pythonize(self, val):
155 return to_int(val)
158 class FloatProp(Property):
159 # @staticmethod
160 def pythonize(self, val):
161 return to_float(val)
164 class CharProp(Property):
165 # @staticmethod
166 def pythonize(self, val):
167 return to_char(val)
170 class StringProp(Property):
171 # @staticmethod
172 def pythonize(self, val):
173 return val
175 class PathProp(StringProp):
176 """A string property representing a path"""
178 class ListProp(Property):
179 # @staticmethod
180 def pythonize(self, val):
181 return to_split(val)