1 # -*- mode: python ; coding: utf-8 -*-
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
9 # This file is part of Shinken.
11 # Shinken is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU Affero General Public License as published by
13 # the Free Software Foundation, either version 3 of the License, or
14 # (at your option) any later version.
16 # Shinken is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU Affero General Public License for more details.
21 # You should have received a copy of the GNU Affero General Public License
22 # along with Shinken. If not, see <http://www.gnu.org/licenses/>.
26 from shinken
.util
import to_bool
, to_float
, to_split
, to_char
, to_int
28 __author__
= "Hartmut Goebel <h.goebel@goebel-consult.de>"
29 __copyright__
= "Copyright 2010 by Hartmut Goebel <h.goebel@goebel-consult.de>"
30 __licence__
= "GNU Affero General Public License version 3 (AGPL v3)"
33 FULL_STATUS
= 'full_status'
34 CHECK_RESULT
= 'check_result'
37 class Property(object):
39 Baseclass of all properties.
41 Same semantic for all subclasses (except UnusedProp): The property
42 is required if, and only if, the default value is `None`.
46 def __init__(self
, default
='ididnotsetdefault', class_inherit
=[],
47 unmanaged
=False, help='', no_slots
=False,
48 fill_brok
=[], conf_send_preparation
=None,
49 brok_transformation
=None,retention
=False,to_send
=False,
50 override
=False,managed
=True):
52 `default`: default value to be used if this property is not set.
53 If default is None, this property is requied.
55 `class_inherit`: List of 2-tuples, (Service, 'blabla') : must
56 set this property to the Service class with name
57 blabla. if (Service, None): must set this property
58 to the Service class with same name
61 `no_slots`: do not take this property for __slots__
63 `fill_brok`: if set, send to broker. There are two categories:
64 FULL_STATUS for initial and update status,
65 CHECK_RESULT for check results
67 Only for the inital call:
69 conf_send_preparation: if set, will pass the property to this
70 function. It's used to 'flatten' some dangerous
71 properties like realms that are too 'linked' to
74 brok_transformation: if set, will call the function with the
75 value of the property the major times it will be
76 to flatten the data (like realm_name instead of
79 override : for scheduler, if the property must override the
80 value of the configuration we send
82 managed : property that is managed in Nagios but not in Shinken
85 self
.default
= default
86 self
.has_default
= (default
!= 'ididnotsetdefault')
87 self
.required
= default
is 'ididnotsetdefault'
88 self
.class_inherit
= class_inherit
89 self
.help = help or ''
90 self
.unmanaged
= unmanaged
91 self
.no_slots
= no_slots
92 self
.fill_brok
= fill_brok
93 self
.conf_send_preparation
= conf_send_preparation
94 self
.brok_transformation
= brok_transformation
95 self
.retention
= retention
96 self
.to_send
= to_send
97 self
.override
= override
98 self
.managed
= managed
102 class UnusedProp(Property
):
104 A unused Property. These are typically used by Nagios but
105 no longer usefull/used by Shinken.
107 This is just to warn the user that the option he use is no more used
110 def __init__(self
, text
=None):
112 Since this property is not used, there is no use for other
113 parameters than `text`.
115 `text` a some usage text if present, will print it to explain
116 why it's no more useful
119 text
= ("This parameter is no longer useful in the "
120 "Shinken architecture.")
122 self
.has_default
= False
123 self
.class_inherit
= []
128 _boolean_states
= {'1': True, 'yes': True, 'true': True, 'on': True,
129 '0': False, 'no': False, 'false': False, 'off': False}
132 class BoolProp(Property
):
136 Boolean values are currently case insensitively defined as 0,
137 false, no, off for False, and 1, true, yes, on for True).
140 def pythonize(self
, val
):
141 return _boolean_states
[val
.lower()]
144 class IntegerProp(Property
):
146 def pythonize(self
, val
):
150 class FloatProp(Property
):
152 def pythonize(self
, val
):
156 class CharProp(Property
):
158 def pythonize(self
, val
):
162 class StringProp(Property
):
164 def pythonize(self
, val
):
168 class ListProp(Property
):
170 def pythonize(self
, val
):