2 # Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
5 # Gregory Starck, g.starck@gmail.com
6 # Hartmut Goebel, h.goebel@goebel-consult.de
8 # This file is part of Shinken.
10 # Shinken is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Affero General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # Shinken is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU Affero General Public License for more details.
20 # You should have received a copy of the GNU Affero General Public License
21 # along with Shinken. If not, see <http://www.gnu.org/licenses/>.
24 from shinken
.action
import Action
28 __slots__
= ( 'id', 'is_a', 'type', '_in_timeout', 'status', 'exit_status',
29 '_command', 'output', 'long_output', 'ref', 'ref_type',
30 't_to_go', 'depend_on', 'depend_on_me', 'check_time',
31 'execution_time', 'env' )
34 'is_a': { 'required': False, 'default': 'check' },
35 'type': { 'required': False, 'default': '' },
36 '_in_timeout': { 'required': False, 'default': False },
37 'status' : { 'required': False, 'default': '' },
38 'exit_status' : { 'required': False, 'default': 3 },
39 'state': { 'required': False, 'default': 0 },
40 'output': { 'required': False, 'default': '' },
41 'long_output': { 'required': False, 'default': '' },
42 'ref': { 'required': False, 'default': -1 },
43 't_to_go': { 'required': False, 'default': 0 },
44 'depend_on': { 'required': False, 'default': [] },
45 'dep_check': { 'required': False, 'default': [] },
46 'check_time': { 'required': False, 'default': 0 },
47 'execution_time': { 'required': False, 'default': 0 },
48 'perf_data': { 'required': False, 'default': '' },
49 'poller_tag': { 'required': False, 'default': 'None' },
50 'env': { 'required': False, 'default': {} },
51 'internal': { 'required': False, 'default': False },
52 'module_type': { 'required': False, 'default': 'fork' },
53 'worker': { 'required': False, 'default': 'none' },
56 #id = 0 #Is common to Actions
57 def __init__(self
, status
, command
, ref
, t_to_go
, dep_check
=None, id=None, timeout
=10, poller_tag
='None', env
={}, module_type
='fork'):
61 if id is None: #id != None is for copy call only
64 self
._in
_timeout
= False
65 self
.timeout
= timeout
68 self
.command
= command
72 #self.ref_type = ref_type
73 self
.t_to_go
= t_to_go
76 self
.depend_on_me
= []
78 self
.depend_on_me
= [dep_check
]
80 self
.execution_time
= 0
82 self
.poller_tag
= poller_tag
83 self
.module_type
= module_type
85 # we keep the reference of the poller that will take us
87 # If it's a business rule, manage it as a special check
88 if ref
and ref
.got_business_rule
or command
.startswith('_internal'):
94 #return a copy of the check but just what is important for execution
95 #So we remove the ref and all
97 #We create a dummy check with nothing in it, jsut defaults values
98 return self
.copy_shell__( Check('', '', '', '', '', id=self
.id) )
101 def get_return_from(self
, c
):
102 self
.exit_status
= c
.exit_status
103 self
.output
= c
.output
104 self
.long_output
= c
.long_output
105 self
.check_time
= c
.check_time
106 self
.execution_time
= c
.execution_time
107 self
.perf_data
= c
.perf_data
110 def is_launchable(self
, t
):
111 return t
> self
.t_to_go
115 return "Check %d status:%s command:%s ref:%s" % (self
.id, self
.status
, self
.command
, self
.ref
)