From 81698110899e8b6cccb7a2a42fbcb9821bbf1aa9 Mon Sep 17 00:00:00 2001 From: Gabes Jean Date: Wed, 9 Mar 2011 15:44:08 +0100 Subject: [PATCH] Add : set 'None' as the default poller_tag value, so a poller can get untaggued AND taggued checks. --- etc/shinken-specific.cfg | 1 + shinken/check.py | 4 ++-- shinken/daemons/schedulerdaemon.py | 2 +- shinken/modules/hack_commands_poller_tag_arbiter.py | 2 +- shinken/objects/command.py | 8 ++++---- shinken/objects/host.py | 2 +- shinken/objects/service.py | 2 +- shinken/pollerlink.py | 2 +- shinken/scheduler.py | 6 ++++-- test/test_end_to_end.sh | 2 +- test/test_poller_tag_get_checks.py | 4 +++- 11 files changed, 20 insertions(+), 15 deletions(-) diff --git a/etc/shinken-specific.cfg b/etc/shinken-specific.cfg index bb8bfbd..766673c 100644 --- a/etc/shinken-specific.cfg +++ b/etc/shinken-specific.cfg @@ -52,6 +52,7 @@ define poller{ # advanced features #modules NrpeBooster + #poller_tags None realm All } diff --git a/shinken/check.py b/shinken/check.py index f2b6bce..aac4a76 100644 --- a/shinken/check.py +++ b/shinken/check.py @@ -46,7 +46,7 @@ class Check(Action): 'check_time': { 'required': False, 'default': 0 }, 'execution_time': { 'required': False, 'default': 0 }, 'perf_data': { 'required': False, 'default': '' }, - 'poller_tag': { 'required': False, 'default': None }, + 'poller_tag': { 'required': False, 'default': 'None' }, 'env': { 'required': False, 'default': {} }, 'internal': { 'required': False, 'default': False }, 'module_type': { 'required': False, 'default': 'fork' }, @@ -54,7 +54,7 @@ class Check(Action): } #id = 0 #Is common to Actions - def __init__(self, status, command, ref, t_to_go, dep_check=None, id=None, timeout=10, poller_tag=None, env={}, module_type='fork'): + def __init__(self, status, command, ref, t_to_go, dep_check=None, id=None, timeout=10, poller_tag='None', env={}, module_type='fork'): self.is_a = 'check' self.type = '' diff --git a/shinken/daemons/schedulerdaemon.py b/shinken/daemons/schedulerdaemon.py index f3c4bb4..0bd37ae 100644 --- a/shinken/daemons/schedulerdaemon.py +++ b/shinken/daemons/schedulerdaemon.py @@ -47,7 +47,7 @@ They connect here and see if they are still OK with our running_id, if not, they # poller or reactionner ask us actions - def get_checks(self , do_checks=False, do_actions=False, poller_tags=None, worker_name='none'): + def get_checks(self , do_checks=False, do_actions=False, poller_tags=[], worker_name='none'): #print "We ask us checks" res = self.app.get_to_run_checks(do_checks, do_actions, poller_tags, worker_name) #print "Sending %d checks" % len(res) diff --git a/shinken/modules/hack_commands_poller_tag_arbiter.py b/shinken/modules/hack_commands_poller_tag_arbiter.py index dbfe899..bd42398 100644 --- a/shinken/modules/hack_commands_poller_tag_arbiter.py +++ b/shinken/modules/hack_commands_poller_tag_arbiter.py @@ -75,7 +75,7 @@ class Hack_cmds_pt(BaseModule): p = re.compile(self.cmd_line_match) for c in arb.conf.commands: m = p.match(c.command_line) - if m is not None and c.poller_tag is None: + if m is not None and c.poller_tag is 'None': print "[Hack command poller tag] Match! Chaging the poller tag of %s by %s " % (c.command_name, self.poller_tag) c.poller_tag = self.poller_tag self.update_service_and_hosts_commandCall(arb, c, self.poller_tag) diff --git a/shinken/objects/command.py b/shinken/objects/command.py index 4df61ed..ee632d9 100644 --- a/shinken/objects/command.py +++ b/shinken/objects/command.py @@ -30,7 +30,7 @@ class Command(object): properties = { 'command_name': StringProp(fill_brok=['full_status']), 'command_line': StringProp(fill_brok=['full_status']), - 'poller_tag': StringProp(default=None), + 'poller_tag': StringProp(default='None'), 'module_type': StringProp(default=None), } @@ -40,7 +40,7 @@ class Command(object): for key in params: setattr(self, key, params[key]) if not hasattr(self, 'poller_tag'): - self.poller_tag = None + self.poller_tag = 'None' if not hasattr(self, 'module_type'): # If the command satr with a _, set the module_type # as the name of the command, without the _ @@ -96,7 +96,7 @@ class CommandCall: __slots__ = ('id', 'call', 'command', 'valid', 'args') id = 0 my_type = 'CommandCall' - def __init__(self, commands, call, poller_tag=None): + def __init__(self, commands, call, poller_tag='None'): self.id = self.__class__.id self.__class__.id += 1 self.call = call @@ -114,7 +114,7 @@ class CommandCall: #the one of the command self.poller_tag = poller_tag #from host/service self.module_type = self.command.module_type - if self.valid and poller_tag is None: + if self.valid and poller_tag is 'None': self.poller_tag = self.command.poller_tag #from command if not set diff --git a/shinken/objects/host.py b/shinken/objects/host.py index 5958d05..9ec499f 100644 --- a/shinken/objects/host.py +++ b/shinken/objects/host.py @@ -112,7 +112,7 @@ class Host(SchedulingItem): # 'fill_brok' is ok because in scheduler it's already # a string from conf_send_preparation 'realm': StringProp(default=None, fill_brok=['full_status'], conf_send_preparation=get_obj_name), - 'poller_tag': StringProp(default=None), + 'poller_tag': StringProp(default='None'), 'resultmodulations': StringProp(default=''), 'escalations': StringProp(default='', fill_brok=['full_status']), 'maintenance_period': StringProp(default='', fill_brok=['full_status']), diff --git a/shinken/objects/service.py b/shinken/objects/service.py index 729934e..5cc980f 100644 --- a/shinken/objects/service.py +++ b/shinken/objects/service.py @@ -107,7 +107,7 @@ class Service(SchedulingItem): 'parallelize_check': BoolProp (default='1', fill_brok=['full_status']), # Shinken specific - 'poller_tag': StringProp(default=None), + 'poller_tag': StringProp(default='None'), 'resultmodulations': StringProp(default=''), 'escalations': StringProp(default='', fill_brok=['full_status']), 'maintenance_period': StringProp(default='', fill_brok=['full_status']), diff --git a/shinken/pollerlink.py b/shinken/pollerlink.py index 39e3748..466f23b 100644 --- a/shinken/pollerlink.py +++ b/shinken/pollerlink.py @@ -44,7 +44,7 @@ class PollerLink(SatelliteLink): 'processes_by_worker': IntegerProp(default='256', fill_brok=['full_status'], to_send=True), 'polling_interval': IntegerProp(default='1', fill_brok=['full_status'], to_send=True), 'manage_arbiters': IntegerProp(default='0'), - 'poller_tags': ListProp(default='', to_send=True), + 'poller_tags': ListProp(default='None', to_send=True), 'use_timezone': StringProp(default='NOTSET', to_send=True), 'timeout': IntegerProp(default='3', fill_brok=['full_status']), 'data_timeout': IntegerProp(default='120', fill_brok=['full_status']), diff --git a/shinken/scheduler.py b/shinken/scheduler.py index f935c87..7da68a8 100644 --- a/shinken/scheduler.py +++ b/shinken/scheduler.py @@ -346,7 +346,7 @@ class Scheduler: # Called by poller to get checks # Can get checks and actions (notifications and co) def get_to_run_checks(self, do_checks=False, do_actions=False, - poller_tags=[], worker_name='none'): + poller_tags=['None'], worker_name='none'): res = [] now = time.time() @@ -356,7 +356,9 @@ class Scheduler: # If the command is untagged, and the poller too, or if both are taggued # with same name, go for it # if do_check, call for poller, and so poller_tags by default is [] - if (c.poller_tag is None and poller_tags == []) or c.poller_tag in poller_tags: + #if (c.poller_tag is None and poller_tags == []) or c.poller_tag in poller_tags: + # by defaultpoller_tag is 'None' and poller_tags is ['None'] + if c.poller_tag in poller_tags: # must be ok to launch, and not an internal one (business rules based) if c.status == 'scheduled' and c.is_launchable(now) and not c.internal: c.status = 'inpoller' diff --git a/test/test_end_to_end.sh b/test/test_end_to_end.sh index ba0d1f5..b82a669 100755 --- a/test/test_end_to_end.sh +++ b/test/test_end_to_end.sh @@ -456,7 +456,7 @@ string_in_file "Connexion OK to the poller poller-Master-2" $VAR/nagios.log echo "Now we clean it" -./clean.sh +#./clean.sh echo "" diff --git a/test/test_poller_tag_get_checks.py b/test/test_poller_tag_get_checks.py index e525657..b632fa2 100755 --- a/test/test_poller_tag_get_checks.py +++ b/test/test_poller_tag_get_checks.py @@ -56,14 +56,16 @@ class TestPollerTagGetchecks(ShinkenTest): # the scheduler need to get this new checks in its own queues self.sched.get_new_actions() # Ask for untag checks only - untaggued_checks = self.sched.get_to_run_checks(True, False, poller_tags=[]) + untaggued_checks = self.sched.get_to_run_checks(True, False, poller_tags=['None']) print "Got untaggued_checks", untaggued_checks + self.assert_(len(untaggued_checks) > 0) for c in untaggued_checks: # Should be the service one, but not the host one self.assert_(c.command.startswith('plugins/test_servicecheck.pl')) # Now get only tag ones taggued_checks = self.sched.get_to_run_checks(True, False, poller_tags=['mytestistrue']) + self.assert_(len(taggued_checks) > 0) for c in taggued_checks: # Should be the host one only self.assert_(c.command.startswith('plugins/test_hostcheck.pl')) -- 2.11.4.GIT