[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a

Naparuba naparuba at gmail.com
Tue Feb 28 22:07:58 UTC 2012


The following commit has been merged in the debian/master branch:
commit 61390cc6b0fe6fce7142daefa0c7d82474b6919e
Author: Naparuba <naparuba at gmail.com>
Date:   Mon Dec 5 20:01:41 2011 +0100

    Add : make external commands to be send as bulk from arbiter to schedulers instead of one connexion by command. Manage 10K commands in few seconds, so should be ok.

diff --git a/external_commands/PROCESS_HOST_CHECK_RESULT.sh b/external_commands/PROCESS_HOST_CHECK_RESULT.sh
index c0cc13e..7e9f823 100755
--- a/external_commands/PROCESS_HOST_CHECK_RESULT.sh
+++ b/external_commands/PROCESS_HOST_CHECK_RESULT.sh
@@ -1,8 +1,8 @@
-#!/bin/sh
+#!/bin/bash
 # This is a sample shell script showing how you can submit the CHANGE_HOST_CHECK_COMMAND command
 # to Nagios.  Adjust variables to fit your environment as necessary.
 
 now=`date +%s`
 commandfile='/usr/local/shinken/var/rw/nagios.cmd'
 
-printf "[%lu] PROCESS_HOST_CHECK_RESULT;dc1;2;yoyo est mort\n" $now > $commandfile
+printf "[%lu] PROCESS_HOST_CHECK_RESULT;router2;2;yoyo est mort\n" $now > $commandfile
diff --git a/shinken/daemons/arbiterdaemon.py b/shinken/daemons/arbiterdaemon.py
index a9d8388..c5d5808 100644
--- a/shinken/daemons/arbiterdaemon.py
+++ b/shinken/daemons/arbiterdaemon.py
@@ -34,7 +34,7 @@ from shinken.daemon import Daemon, Interface
 from shinken.log import logger
 from shinken.brok import Brok
 from shinken.external_command import ExternalCommand
-
+from shinken.util import safe_print
 
 # Interface for the other Arbiter
 # It connects, and together we decide who's the Master and who's the Slave, etc.
@@ -539,6 +539,23 @@ class Arbiter(Daemon):
                 self.must_run = True
                 break
 
+    # Take all external commands, make packs and send them to
+    # the schedulers
+    def push_external_commands_to_schedulers(self):
+        # Now get all external commands and put them into the
+        # good schedulers
+        for ext_cmd in self.external_commands:
+            self.external_command.resolve_command(ext_cmd)
+
+        # Now for all alive schedulers, send the commands
+        for sched in self.conf.schedulerlinks:
+            cmds = sched.external_commands
+            if len(cmds) > 0 and sched.alive:
+                safe_print("Sending %d commands" % len(cmds), 'to scheduler', sched.get_name())
+                sched.run_external_commands(cmds)
+            # clean them
+            sched.external_commands = []
+
 
     # Main function
     def run(self):
@@ -628,9 +645,8 @@ class Arbiter(Daemon):
                 print "Nb Broks send:", self.nb_broks_send
             self.nb_broks_send = 0
 
-            # Now send all external commands to schedulers
-            for ext_cmd in self.external_commands:
-                self.external_command.resolve_command(ext_cmd)
+            self.push_external_commands_to_schedulers()
+
             # It's send, do not keep them
             # TODO: check if really send. Queue by scheduler?
             self.external_commands = []
diff --git a/shinken/daemons/schedulerdaemon.py b/shinken/daemons/schedulerdaemon.py
index 95b4473..20f671c 100644
--- a/shinken/daemons/schedulerdaemon.py
+++ b/shinken/daemons/schedulerdaemon.py
@@ -96,8 +96,8 @@ HE got user entry, so we must listen him carefully and give information he want,
 
     #arbiter is send us a external coomand.
     #it can send us global command, or specific ones
-    def run_external_command(self, command):
-        self.app.sched.run_external_command(command)
+    def run_external_commands(self, cmds):
+        self.app.sched.run_external_commands(cmds)
 
     def put_conf(self, conf):
         self.app.sched.die()
diff --git a/shinken/external_command.py b/shinken/external_command.py
index 6838fe6..ca8dd0f 100644
--- a/shinken/external_command.py
+++ b/shinken/external_command.py
@@ -290,7 +290,19 @@ class ExternalCommandManager:
         #Only log if we are in the Arbiter
         if self.mode == 'dispatcher' and self.conf.log_external_commands:
             logger.log('EXTERNAL COMMAND: '+command.rstrip())
-        self.get_command_and_args(command)
+        r = self.get_command_and_args(command)
+        if r is not None:
+            is_global = r['global']
+            if not is_global:
+                c_name = r['c_name']
+                args = r['args']
+                print "Got commands", c_name, args
+                f = getattr(self, c_name)
+                apply(f, args)
+            else:
+                command = r['command']
+                self.dispatch_global_command(command)
+
 
 
     #Ok the command is not for every one, so we search
@@ -306,7 +318,8 @@ class ExternalCommandManager:
                     host_found = True
                     sched = cfg.assigned_to
                     safe_print("Sending command to the scheduler", sched.get_name())
-                    sched.run_external_command(command)
+                    #sched.run_external_command(command)
+                    sched.external_commands.append(command)
                     break
                 else:
                     print "Problem: a configuration is found, but is not assigned!"
@@ -315,29 +328,30 @@ class ExternalCommandManager:
                 #print "Sorry but the host", host_name, "was not found"
 
 
-    #The command is global, so sent it to every schedulers
+    # The command is global, so sent it to every schedulers
     def dispatch_global_command(self, command):
         for sched in self.conf.schedulerlinks:
             safe_print("Sending a command", command, 'to scheduler', sched)
-            if sched.alive:
-                sched.run_external_command(command)
+            if sched.alive:                
+                #sched.run_external_command(command)
+                sched.external_commands.append(command)
 
 
     #We need to get the first part, the command name
     def get_command_and_args(self, command):
-        safe_print("Trying to resolve", command)
+        #safe_print("Trying to resolve", command)
         command = command.rstrip()
         elts = command.split(';') # danger!!! passive checkresults with perfdata
         part1 = elts[0]
 
         elts2 = part1.split(' ')
-        print "Elts2:", elts2
+        #print "Elts2:", elts2
         if len(elts2) != 2:
             safe_print("Malformed command", command)
             return None
         c_name = elts2[1]
 
-        safe_print("Get command name", c_name)
+        #safe_print("Get command name", c_name)
         if c_name not in ExternalCommandManager.commands:
             print "This command is not recognized, sorry"
             return None
@@ -361,12 +375,12 @@ class ExternalCommandManager:
         if self.mode == 'dispatcher' and entry['global']:
             if not internal:
                 print "This command is a global one, we resent it to all schedulers"
-                self.dispatch_global_command(command)
-                return None
+                return {'global' : True, 'cmd' : command}
+        
 
-        print "Is global?", c_name, entry['global']
-        print "Mode:", self.mode
-        print "This command have arguments:", entry['args'], len(entry['args'])
+        #print "Is global?", c_name, entry['global']
+        #print "Mode:", self.mode
+        #print "This command have arguments:", entry['args'], len(entry['args'])
 
         args = []
         i = 1
@@ -374,16 +388,16 @@ class ExternalCommandManager:
         tmp_host = ''
         try:
             for elt in elts[1:]:
-                safe_print("Searching for a new arg:", elt, i)
+                #safe_print("Searching for a new arg:", elt, i)
                 val = elt.strip()
                 if val[-1] == '\n':
                     val = val[:-1]
 
-                safe_print("For command arg", val)
+                #safe_print("For command arg", val)
 
                 if not in_service:
                     type_searched = entry['args'][i-1]
-                    safe_print("Search for a arg", type_searched)
+                    #safe_print("Search for a arg", type_searched)
 
                     if type_searched == 'host':
                         if self.mode == 'dispatcher':
@@ -439,7 +453,7 @@ class ExternalCommandManager:
                     elif type_searched == 'service':
                         in_service = True
                         tmp_host = elt.strip()
-                        safe_print("TMP HOST", tmp_host)
+                        #safe_print("TMP HOST", tmp_host)
                         if tmp_host[-1] == '\n':
                             tmp_host = tmp_host[:-1]
                             #If
@@ -453,7 +467,7 @@ class ExternalCommandManager:
                     srv_name = elt
                     if srv_name[-1] == '\n':
                         srv_name = srv_name[:-1]
-                    safe_print("Got service full", tmp_host, srv_name)
+                    #safe_print("Got service full", tmp_host, srv_name)
                     s = self.services.find_srv_by_name_and_hostname(tmp_host, srv_name)
                     if s is not None:
                         args.append(s)
@@ -465,11 +479,13 @@ class ExternalCommandManager:
             return None
         safe_print('Finally got ARGS:', args)
         if len(args) == len(entry['args']):
-            safe_print("OK, we can call the command", c_name, "with", args)
-            f = getattr(self, c_name)
-            apply(f, args)
+            #safe_print("OK, we can call the command", c_name, "with", args)
+            return {'global' : False, 'c_name' : c_name, 'args' : args}
+            #f = getattr(self, c_name)
+            #apply(f, args)
         else:
             safe_print("Sorry, the arguments are not corrects", args)
+            return None
 
 
 
diff --git a/shinken/scheduler.py b/shinken/scheduler.py
index 550a2f1..4bc19f8 100644
--- a/shinken/scheduler.py
+++ b/shinken/scheduler.py
@@ -195,6 +195,10 @@ class Scheduler:
 
 
     # We've got activity in the fifo, we get and run commands
+    def run_external_commands(self, cmds):
+        for command in cmds:
+            self.run_external_command(command)
+
     def run_external_command(self, command):
         safe_print("scheduler resolves command", command)
         ext_cmd = ExternalCommand(command)
diff --git a/shinken/schedulerlink.py b/shinken/schedulerlink.py
index c9ac7d2..afb43db 100644
--- a/shinken/schedulerlink.py
+++ b/shinken/schedulerlink.py
@@ -46,6 +46,7 @@ class SchedulerLink(SatelliteLink):
     running_properties.update({
         'conf':      StringProp(default=None),
         'need_conf': StringProp(default=True),
+        'external_commands' : StringProp(default=[]),
     })
 
 
@@ -53,14 +54,14 @@ class SchedulerLink(SatelliteLink):
         return self.scheduler_name
 
 
-    def run_external_command(self, command):
+    def run_external_commands(self, commands):
         if self.con is None:
             self.create_connection()
         if not self.alive:
             return None
-        safe_print("Send command", command)
+        safe_print("Send %d commands", len(commands))
         try:
-            self.con.run_external_command(command)
+            self.con.run_external_commands(commands)
         except Pyro.errors.URIError , exp:
             self.con = None
             return False

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list