Add : set 'None' as the default poller_tag value, so a poller can get untaggued AND...
[shinken.git] / shinken / check.py
blobaac4a76fc39ab223a63d49365128bd290f30d392
1 #!/usr/bin/env python
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
27 class Check(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' )
33 properties = {
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'):
59 self.is_a = 'check'
60 self.type = ''
61 if id is None: #id != None is for copy call only
62 self.id = Action.id
63 Action.id += 1
64 self._in_timeout = False
65 self.timeout = timeout
66 self.status = status
67 self.exit_status = 3
68 self.command = command
69 self.output = ''
70 self.long_output = ''
71 self.ref = ref
72 #self.ref_type = ref_type
73 self.t_to_go = t_to_go
74 self.depend_on = []
75 if dep_check is None:
76 self.depend_on_me = []
77 else:
78 self.depend_on_me = [dep_check]
79 self.check_time = 0
80 self.execution_time = 0
81 self.perf_data = ''
82 self.poller_tag = poller_tag
83 self.module_type = module_type
84 self.env = env
85 # we keep the reference of the poller that will take us
86 self.worker = 'none'
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'):
89 self.internal = True
90 else:
91 self.internal = False
94 #return a copy of the check but just what is important for execution
95 #So we remove the ref and all
96 def copy_shell(self):
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
114 def __str__(self):
115 return "Check %d status:%s command:%s ref:%s" % (self.id, self.status, self.command, self.ref)
118 def get_id(self):
119 return self.id