[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Sebastien Coavoux
s.coavoux at free.fr
Tue Feb 28 22:14:57 UTC 2012
The following commit has been merged in the debian/master branch:
commit e2f3f305ae8251b966f7c81b19c6da08f3c0255d
Author: Sebastien Coavoux <s.coavoux at free.fr>
Date: Fri Jan 20 18:18:23 2012 +0100
Code Review.
Fixed : typo in comments
Added : licence in files
Added : personnal tags on comments
+ <WTF??> : Refers to something that is unclear for me so that I can't fix it
+ <TMI!!> : Too Much Information/Comments.
This is my opinion, if everyone agrees we remove some.
Personal Note :
* I choose to use """ for class comment and # for other function comments.
* TODO stuff is good, but please dont use the doc syntax (""") for drafts :)
* Comments are usally before the function definition not under.
Feel free to (dis)agree
diff --git a/shinken/__init__.py b/shinken/__init__.py
index be8f817..5323228 100644
--- a/shinken/__init__.py
+++ b/shinken/__init__.py
@@ -1,4 +1,25 @@
+#!/usr/bin/env python
+# Copyright (C) 2009-2011 :
+# Gabes Jean, naparuba at gmail.com
+# Gerhard Lausser, Gerhard.Lausser at consol.de
+# Gregory Starck, g.starck at gmail.com
+# Hartmut Goebel, h.goebel at goebel-consult.de
+#
+# This file is part of Shinken.
+#
+# Shinken is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Shinken is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
# shinken.objects must be imported first:
import objects
diff --git a/shinken/acknowledge.py b/shinken/acknowledge.py
index db028d1..537726f 100644
--- a/shinken/acknowledge.py
+++ b/shinken/acknowledge.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
-# Copyright (C) 2009-2010 :
+
+# Copyright (C) 2009-2011 :
# Gabes Jean, naparuba at gmail.com
# Gerhard Lausser, Gerhard.Lausser at consol.de
# Gregory Starck, g.starck at gmail.com
@@ -20,6 +21,7 @@
# You should have received a copy of the GNU Affero General Public
# License along with Shinken. If not, see <http://www.gnu.org/licenses/>.
#
+
"""
Allows you to acknowledge the current problem for the specified service.
By acknowledging the current problem, future notifications (for the same
@@ -28,8 +30,8 @@ servicestate) are disabled.
class Acknowledge:
id = 1
- #Just to list the properties we will send as pickle
- #so to others daemons, so all but NOT REF
+ # Just to list the properties we will send as pickle
+ # so to others daemons, all but NOT REF
properties = {
'id' : None,
'sticky' : None,
@@ -50,16 +52,20 @@ class Acknowledge:
# sent out to contacts indicating that the current service problem
# has been acknowledged.
#
+ # <WTF??>
# If the "persistent" option is set to one (1), the comment
# associated with the acknowledgement will survive across restarts
# of the Shinken process. If not, the comment will be deleted the
- # next time Nagios restarts. "persistent" not only means "survive
- # restarts", but also
- #
+ # next time Shinken restarts. "persistent" not only means "survive
+ # restarts", but also
+ #
+ # => End of comment Missing !!
+ # </WTF??>
+
def __init__(self, ref, sticky, notify, persistent, author, comment, end_time=0):
self.id = self.__class__.id
self.__class__.id += 1
- self.ref = ref # pointer to srv or host we are apply
+ self.ref = ref # pointer to srv or host we are applied
self.sticky = sticky
self.notify = notify
self.end_time = end_time
@@ -67,8 +73,8 @@ class Acknowledge:
self.comment = comment
- #Call by picle for dataify the ackn
- #because we DO NOT WANT REF in this pickleisation!
+ # Call by pickle for dataify the ackn
+ # because we DO NOT WANT REF in this pickleisation!
def __getstate__(self):
cls = self.__class__
# id is not in *_properties
@@ -79,13 +85,13 @@ class Acknowledge:
return res
- #Inversed funtion of getstate
+ # Inversed funtion of getstate
def __setstate__(self, state):
cls = self.__class__
self.id = state['id']
for prop in cls.properties:
if prop in state:
setattr(self, prop, state[prop])
- # If load a old ack, set the end_time to 0 so it's infinite
+ # If load a old ack, set the end_time to 0 which refers to infinite
if not hasattr(self, 'end_time'):
self.end_time = 0
diff --git a/shinken/action.py b/shinken/action.py
index 00ff5c5..44eb52f 100644
--- a/shinken/action.py
+++ b/shinken/action.py
@@ -1,24 +1,25 @@
#!/usr/bin/env python
-#Copyright (C) 2009-2010 :
+
+# Copyright (C) 2009-2011 :
# Gabes Jean, naparuba at gmail.com
# Gerhard Lausser, Gerhard.Lausser at consol.de
# Gregory Starck, g.starck at gmail.com
# Hartmut Goebel, h.goebel at goebel-consult.de
#
-#This file is part of Shinken.
+# This file is part of Shinken.
#
-#Shinken is free software: you can redistribute it and/or modify
-#it under the terms of the GNU Affero General Public License as published by
-#the Free Software Foundation, either version 3 of the License, or
-#(at your option) any later version.
+# Shinken is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
#
-#Shinken is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-#GNU Affero General Public License for more details.
+# Shinken is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
#
-#You should have received a copy of the GNU Affero General Public License
-#along with Shinken. If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
import os
import time
@@ -28,6 +29,8 @@ import sys
import subprocess
from shinken.util import safe_print
+from shinken.log import logger
+
__all__ = ( 'Action' )
valid_exit_status = (0, 1, 2, 3)
@@ -38,23 +41,22 @@ shellchars = ( '!', '$', '^', '&', '*', '(', ')', '~', '[', ']',
'|', '{', '}', ';', '<', '>', '?', '`')
-# This abstract class is use just for having a common id between actions and checks
+""" This abstract class is used just for having a common id between actions and checks """
class __Action(object):
id = 0
- # Mix the env into the environnment variables
+ # Mix the env and the environnment variables
# into a new local env dict
# rmq : we cannot just update os.environ because
- # it will be modified for all other checks too
+ # it will be also modified for all others checks
def get_local_environnement(self):
local_env = copy.copy(os.environ)
for p in self.env:
local_env[p] = self.env[p].encode('utf8')
return local_env
-
+ # Start this action command ; the command will be executed in a subprocess
def execute(self):
- """ Start this action command ; the command will be executed in a subprocess """
self.status = 'launched'
self.check_time = time.time()
self.wait_time = 0.0001
@@ -67,6 +69,7 @@ class __Action(object):
def get_outputs(self, out, max_plugins_output_length):
#print "Get only," , max_plugins_output_length, "bytes"
+ # <TMI!!>
# Squize all output after max_plugins_output_length
out = out[:max_plugins_output_length]
# Then cuts by lines
@@ -97,6 +100,7 @@ class __Action(object):
self.perf_data += ' ' + elts[1].strip()
# long_output is all non output and perfline, join with \n
self.long_output = '\n'.join(long_output)
+ # </TMI!!>
@@ -122,10 +126,11 @@ class __Action(object):
self.exit_status = self.process.returncode
(stdoutdata, stderrdata) = self.process.communicate()
- #we should not keep the process now
+ # we should not keep the process now
del self.process
# if the exit status is anormal, we add stderr to the output
+ # TODO : Anormal should be logged properly no?
if self.exit_status not in valid_exit_status:
stdoutdata = stdoutdata + stderrdata
# Now grep what we want in the output
@@ -136,7 +141,7 @@ class __Action(object):
def copy_shell__(self, new_i):
- """ This will assign the attributes present in 'only_copy_prop' from self to new_i """
+ # This will assign the attributes present in 'only_copy_prop' from self to new_i
for prop in only_copy_prop:
setattr(new_i, prop, getattr(self, prop))
return new_i
@@ -157,7 +162,7 @@ if os.name != 'nt':
class Action(__Action):
# We allow direct launch only for 2.7 and higher version
- # because if a direct launch crash, under this the file hanldes
+ # because if a direct launch crash, under this the file handles
# are not releases, it's not good.
def execute__(self, force_shell=sys.version_info < (2, 7)):
# If the command line got shell characters, we should go in a shell
@@ -185,7 +190,7 @@ if os.name != 'nt':
close_fds=True, shell=force_shell, env=self.local_env,
preexec_fn=os.setsid)
except OSError , exp:
- print "Debug : Error in launching command:", self.command, exp, force_shell
+ logger.log("Debug : Error in launching command: %s %s %s" % (self.command, exp, force_shell))
# Maybe it's just a shell we try to exec. So we must retry
if not force_shell and exp.errno == 8 and exp.strerror == 'Exec format error':
return self.execute__(True)
@@ -221,7 +226,7 @@ else:
self.process = subprocess.Popen(cmd,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=self.local_env, shell=True)
except WindowsError, exp:
- print "We kill the process : ", exp, self.command
+ logger.log("We kill the process : %s %s" % (exp, self.command))
self.status = 'timeout'
self.execution_time = time.time() - self.check_time
diff --git a/shinken/arbiterlink.py b/shinken/arbiterlink.py
index be57d9c..1f62d0b 100644
--- a/shinken/arbiterlink.py
+++ b/shinken/arbiterlink.py
@@ -1,24 +1,25 @@
#!/usr/bin/env python
-#Copyright (C) 2009-2010 :
+
+# Copyright (C) 2009-2011 :
# Gabes Jean, naparuba at gmail.com
# Gerhard Lausser, Gerhard.Lausser at consol.de
# Gregory Starck, g.starck at gmail.com
# Hartmut Goebel, h.goebel at goebel-consult.de
#
-#This file is part of Shinken.
+# This file is part of Shinken.
#
-#Shinken is free software: you can redistribute it and/or modify
-#it under the terms of the GNU Affero General Public License as published by
-#the Free Software Foundation, either version 3 of the License, or
-#(at your option) any later version.
+# Shinken is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
#
-#Shinken is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-#GNU Affero General Public License for more details.
+# Shinken is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
#
-#You should have received a copy of the GNU Affero General Public License
-#along with Shinken. If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
import socket
@@ -29,6 +30,8 @@ Pyro = pyro.Pyro
from shinken.log import logger
+
+""" TODO : Add some comment about this class for the doc"""
class ArbiterLink(SatelliteLink):
id = 0
my_type = 'arbiter'
@@ -47,14 +50,16 @@ class ArbiterLink(SatelliteLink):
return self.con.get_config()
- #Check is required prop are set:
- #contacts OR contactgroups is need
+ # Check is required when prop are set:
+ # contacts OR contactgroups is need
def is_correct(self):
state = True #guilty or not? :)
cls = self.__class__
for prop, entry in cls.properties.items():
if not hasattr(self, prop) and entry.required:
+ # This sould raise an error afterwards?
+ # If so, logger.log it !
print self.get_name(), " : I do not have", prop
state = False #Bad boy...
return state
@@ -131,7 +136,7 @@ class ArbiterLinks(SatelliteLinks):
inner_class = ArbiterLink
- #We must have a realm property, so we find our realm
+ # We must have a realm property, so we find our realm
def linkify(self, modules):
self.linkify_s_by_plug(modules)
diff --git a/shinken/autoslots.py b/shinken/autoslots.py
index 7e4bd17..5523139 100644
--- a/shinken/autoslots.py
+++ b/shinken/autoslots.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
+# -*- coding: utf-8 -*-
#
-# Copyright (C) 2009-2010 :
+# Copyright (C) 2009-2011 :
# Gabes Jean, naparuba at gmail.com
# Gerhard Lausser, Gerhard.Lausser at consol.de
# Gregory Starck, g.starck at gmail.com
@@ -21,7 +22,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
-"""The AutoSlots Class is a MetaClass : it manage how other classes
+"""The AutoSlots Class is a MetaClass : it manages how other classes
are created (Classes, not instances of theses classes).
Here it's role is to create the __slots__ list of the class with
all properties of Class.properties and Class.running_properties
@@ -32,10 +33,10 @@ class AutoSlots(type):
# new is call when we create a new Class
# that have metaclass = AutoSlots
# CLS is AutoSlots
- # name is s tring of the Class (like Service)
+ # name is string of the Class (like Service)
# bases are the Classes of which Class inherits (like SchedulingItem)
# dct is the new Class dict (like all method of Service)
- # Some properties name are not alowed in __slots__ like 2d_coords of
+ # Some properties names are not allowed in __slots__ like 2d_coords of
# Host, so we must tag them in properties with no_slots
def __new__(cls, name, bases, dct):
# Thanks to Bertrand Mathieu to the set idea
diff --git a/shinken/basemodule.py b/shinken/basemodule.py
index de87630..fd32723 100644
--- a/shinken/basemodule.py
+++ b/shinken/basemodule.py
@@ -1,20 +1,26 @@
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
-#Copyright (C) 2009 Gabes Jean, naparuba at gmail.com
+
+# Copyright (C) 2009-2011 :
+# Gabes Jean, naparuba at gmail.com
+# Gerhard Lausser, Gerhard.Lausser at consol.de
+# Gregory Starck, g.starck at gmail.com
+# Hartmut Goebel, h.goebel at goebel-consult.de
#
-#This file is part of Shinken.
+# This file is part of Shinken.
#
-#Shinken is free software: you can redistribute it and/or modify
-#it under the terms of the GNU Affero General Public License as published by
-#the Free Software Foundation, either version 3 of the License, or
-#(at your option) any later version.
+# Shinken is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
#
-#Shinken is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-#GNU Affero General Public License for more details.
+# Shinken is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
#
-#You should have received a copy of the GNU Affero General Public License
-#along with Shinken. If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
""" This python module contains the class BaseModule that shinken modules will subclass """
@@ -28,20 +34,23 @@ from multiprocessing import Queue, Process
from shinken.log import logger
-## TODO: use a class for defining the module "properties" instead of plain dict ?? Like:
-"""
+
+
+# TODO: use a class for defining the module "properties" instead of plain dict ?? Like:
+'''
class ModuleProperties(object):
def __init__(self, type, phases, external=False)
self.type = type
self.phases = phases
self.external = external
-"""
-## and have the new modules instanciate this like follow :
-"""
+'''
+# and have the new modules instanciate this like follow :
+'''
properties = ModuleProperties('the_module_type', the_module_phases, is_mod_ext)
-"""
-##
-""" The `properties´ dict defines what the module can do and if it's an external module or not. """
+'''
+
+
+# The `properties´ dict defines what the module can do and if it's an external module or not.
properties = {
# name of the module type ; to distinguish between them:
'type': None,
@@ -54,52 +63,57 @@ properties = {
}
+""" TODO : Add some comment about this class for the doc"""
class ModulePhases:
-## TODO: why not use simply integers instead of string to represent the different phases ??
+# TODO: why not use simply integers instead of string to represent the different phases ??
CONFIGURATION = 1
LATE_CONFIGURATION = 2
RUNNING = 4
RETENTION = 8
-
-class BaseModule(object):
- """ This is the base class for the shinken modules.
+""" This is the base class for the shinken modules.
Modules can be used by the different shinken daemons/services for different tasks.
Example of task that a shinken module can do:
- load additional configuration objects.
- recurrently save hosts/services status/perfdata informations in different format.
- ...
+
"""
+class BaseModule(object):
+
def __init__(self, mod_conf):
- """ Instanciate a new module. There can be many instance of the same type.
-`mod_conf´ is module configuration object for this new module instance. """
+ # Instanciate a new module. There can be many instance of the same type.
+ #`mod_conf´ is module configuration object for this new module instance.
self.myconf = mod_conf
self.name = mod_conf.get_name()
# We can have sub modules
self.modules = getattr(mod_conf, 'modules', [])
self.props = mod_conf.properties.copy()
- self.properties = self.props # TODO: choose between 'props' or 'properties'..
- self.interrupted = False
+ # TODO: choose between 'props' or 'properties'..
+ self.interrupted = Falseself.properties = self.props
self.is_external = self.props.get('external', False)
- self.phases = self.props.get('phases', []) # though a module defined with no phase is quite useless ..
+ # though a module defined with no phase is quite useless .
+ self.phases = self.props.get('phases', [])
self.phases.append(None)
- self.to_q = None # the queue the module will receive data to manage
- self.from_q = None # the queue the module will put its result data
+ # the queue the module will receive data to manage
+ self.to_q = None
+ # the queue the module will put its result data
+ self.from_q = None
self.process = None
self.init_try = 0
-
+ # Handle this module "post" init ; just before it'll be started.
+ # Like just open necessaries file(s), database(s), or whatever the module will need.
def init(self):
- """ Handle this module "post" init ; just before it'll be started.
-Like just open necessaries file(s), database(s), or whatever the module will need. """
pass
# The manager is None on android, but a true Manager() elsewhere
+ # Create the shared queues that will be used by shinken daemon process and this module process.
+ # But clear queues if they were already set before recreating new one.
def create_queues(self, manager=None):
- """ Create the shared queues that will be used by shinken daemon process and this module process.
-But clear queues if they were already set before recreating new one. """
+
self.clear_queues(manager)
# If no Manager() object, go with classic Queue()
if not manager:
@@ -110,30 +124,30 @@ But clear queues if they were already set before recreating new one. """
self.to_q = manager.Queue()
+ # Release the resources associated to the queues of this instance
def clear_queues(self, manager):
- """ Release the resources associated with the queues of this instance """
for q in (self.to_q, self.from_q):
if q is None: continue
- # If we gotno manager, we direct call the clean
+ # If we got no manager, we direct call the clean
if not manager:
q.close()
q.join_thread()
-# else:
-# q._callmethod('close')
-# q._callmethod('join_thread')
+ #else:
+ # q._callmethod('close')
+ # q._callmethod('join_thread')
self.to_q = self.from_q = None
-
+ # Start this module process if it's external. if not -> donothing
def start(self):
- """ Start this module process if it's external. if not -> donothing """
+
if not self.is_external:
return
self.stop_process()
logger.log("Starting external process for instance %s" % (self.name))
p = Process(target=self.main, args=())
- # Under windows we should not call a start on an object that got
- # it's process as object, so we remove it it we set it in a earlier
+ # Under windows we should not call start() on an object that got
+ # its process as object, so we remove it and we set it in a earlier
# start
try:
del self.properties['process']
@@ -160,9 +174,8 @@ But clear queues if they were already set before recreating new one. """
if self.process.is_alive():
os.kill(self.process.pid, 9)
-
+ # Request the module process to stop and release it
def stop_process(self):
- """ Request the module process to stop and release it """
if self.process:
logger.log("I'm stopping module '%s' process pid:%s " % (self.get_name(), self.process.pid))
self.process.terminate()
@@ -177,33 +190,16 @@ But clear queues if they were already set before recreating new one. """
## TODO: are these 2 methods really needed ?
def get_name(self):
return self.name
+
+ # The classic has : do we have a prop or not?
def has(self, prop):
- """ The classic has : do we have a prop or not? """
return hasattr(self, prop)
-# def get_objects(self):
-# """ Called during arbiter configuration phase. Return a dict to the objects that the module provides.
-##Possible objects are Host, Service, Timeperiod, etc ..
-#Examples of valid return:
-# h1 = { 'host_name': "server1", register=0 }
-# return { 'hosts': [ h1 ] } """
-# raise NotImplementedError()
-
-
-# def update_retention_objects(self, sched, log_mgr):
-# """ Update the retention objects of this module.
-#Called recurrently by scheduler. Also during stop of scheduler. """
-# raise NotImplementedError()
-
-
-# def hook_late_configuration(self, conf):
-# """ Hook for the module "late configuration" : Called by arbiter after the configuration has been fully loaded & built """
-# raise NotImplementedError()
-
+ # Request the module to manage the given brok.
+ # There a lot of different possible broks to manage.
def manage_brok(self, brok):
- """ Request the module to manage the given brok.
-There a lot of different possible broks to manage. """
+
manage = getattr(self, 'manage_' + brok.type + '_brok', None)
if manage:
return manage(brok)
@@ -221,23 +217,25 @@ There a lot of different possible broks to manage. """
set_exit_handler = set_signal_handler
- def do_stop(self):
- """ Called just before the module will exit
-Put in this method all you need to cleanly release all open resource used by your module """
+ # Called just before the module will exit
+ # Put in this method all you need to cleanly
+ # release all open resources used by your module
+ def do_stop(self):
pass
+ # For external modules only: implement in this method the body of you main loop
def do_loop_turn(self):
- """ For external modules only: implement in this method the body of you main loop """
raise NotImplementedError()
+ # module "main" method. Only used by external modules.
def main(self):
- """ module "main" method. Only used by external modules. """
self.set_signal_handler()
logger.log("[%s[%d]]: Now running.." % (self.name, os.getpid()))
while not self.interrupted:
self.do_loop_turn()
self.do_stop()
logger.log("[%s]: exiting now.." % (self.name))
-
- work = main # TODO: apparently some modules would uses "work" as the main method ??
+
+ # TODO: apparently some modules would uses "work" as the main method ??
+ work = main
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list