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 from shinken
.property import UnusedProp
, BoolProp
, IntegerProp
, FloatProp
, CharProp
, StringProp
, ListProp
24 class Command(object):
29 'command_name': StringProp(
30 fill_brok
=['full_status']),
31 'command_line': StringProp(
32 fill_brok
=['full_status']),
33 'poller_tag': StringProp(
37 def __init__(self
, params
={}):
38 self
.id = self
.__class
__.id
39 self
.__class
__.id += 1
41 setattr(self
, key
, params
[key
])
42 if not hasattr(self
, 'poller_tag'):
43 self
.poller_tag
= None
47 self
.command_name
= self
.command_name
.strip()
55 return str(self
.__dict
__)
58 #Get a brok with initial status
59 def get_initial_status_brok(self
):
62 data
= {'id' : self
.id}
64 self
.fill_data_brok_from(data
, 'full_status')
65 b
= Brok('initial_'+my_type
+'_status', data
)
69 def fill_data_brok_from(self
, data
, brok_type
):
71 #Now config properties
72 for prop
in cls
.properties
:
73 #Is this property intended for brokking?
74 # if 'fill_brok' in cls.properties[prop]:
75 if brok_type
in cls
.properties
[prop
].fill_brok
:
76 if hasattr(self
, prop
):
77 data
[prop
] = getattr(self
, prop
)
78 elif 'default' in cls
.properties
[prop
]:
79 data
[prop
] = cls
.properties
[prop
].default
83 #This class is use when a service, contact or host define
86 __slots__
= ('id', 'call', 'command', 'valid', 'args')
88 my_type
= 'CommandCall'
89 def __init__(self
, commands
, call
, poller_tag
=None):
90 self
.id = self
.__class
__.id
91 self
.__class
__.id += 1
96 self
.command
= commands
.find_cmd_by_name(self
.command
.strip())
97 if self
.command
is not None:
101 self
.command
= tab
[0]
102 #If the host/service do not give an override poller_tag, take
103 #the one of the command
104 self
.poller_tag
= poller_tag
#from host/service
105 if self
.valid
and poller_tag
== None:
106 self
.poller_tag
= self
.command
.poller_tag
#from command if not set
114 return str(self
.__dict
__)
121 class Commands(object):
122 def __init__(self
, commands
):
125 self
.commands
[c
.id] = c
129 return self
.commands
.itervalues()
134 for c
in self
.commands
.values():
139 def find_cmd_id_by_name(self
, name
):
140 for id in self
.commands
:
141 if self
.commands
[id].command_name
== name
:
145 def find_cmd_by_name(self
, name
):
146 id = self
.find_cmd_id_by_name(name
)
148 return self
.commands
[id]