Search
j0ke.net Open Build Service
>
Projects
>
server:monitoring
>
check_mk
> check_mk_enable_mod_gearman.patch
Sign Up
|
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File check_mk_enable_mod_gearman.patch of Package check_mk
diff -crB modules/check_mk_base.py modules-gearman//check_mk_base.py *** modules/check_mk_base.py 2011-06-03 00:51:09.671095255 +0200 --- modules-gearman//check_mk_base.py 2011-06-03 01:20:06.891679649 +0200 *************** *** 24,30 **** # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301 USA. ! import socket, os, sys, time, re, signal, math # Python 2.3 does not have 'set' in normal namespace. # But it can be imported from 'sets' --- 24,31 ---- # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301 USA. ! from Crypto.Cipher import AES ! import socket, os, sys, time, re, signal, math, gearman, base64 # Python 2.3 does not have 'set' in normal namespace. # But it can be imported from 'sets' *************** *** 90,95 **** --- 91,98 ---- g_single_oid_cache = {} g_broken_snmp_hosts = set([]) g_broken_agent_hosts = set([]) + g_submit_via_pipe = True + g_submit_via_gearman = False # variables set later by getopt *************** *** 193,202 **** else: text = " *** ".join([ item + " " + output for itemstatus, item, output in outputlist ]) ! if not opt_dont_submit and nagios_command_pipe: ! nagios_command_pipe.write("[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n" % ! (int(time.time()), aggr_hostname, servicedesc, status, text)) ! nagios_command_pipe.flush() if opt_verbose: color = { 0: tty_green, 1: tty_yellow, 2: tty_red, 3: tty_magenta }[status] --- 195,226 ---- else: text = " *** ".join([ item + " " + output for itemstatus, item, output in outputlist ]) ! if not opt_dont_submit: ! if g_submit_via_pipe and nagios_command_pipe: ! nagios_command_pipe.write("[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n" % ! (int(time.time()), aggr_hostname, servicedesc, status, text)) ! nagios_command_pipe.flush() ! if g_submit_via_gearman: ! queue = gearman_queue ! cmkout = ("type=%s\nhost_name=%s\nstart_time=%d\nfinish_time=%d\nlatency=%d\nreturn_code=%d\nservice_description=%s\noutput=%s\n" % ! ("passive", aggr_hostname, int(time.time()), int(time.time()), 0.0, status, servicedesc, text)) ! cmkout = gearman_strencode(cmkout) ! gm_client = gearman.GearmanClient(gearman_server) ! completed_job_request = gm_client.submit_job(queue, cmkout, background=True, wait_until_complete=False) ! # check_request_status(completed_job_request) ! ! # send to dup servers ! if gearman_dup_server: ! for s in gearman_dup_server: ! try: ! gm_client = gearman.GearmanClient(s) ! if gearman_dup_queue: ! queue = gearman_dup_queue ! ! completed_job_request = gm_client.submit_job(queue, cmkout, background=True, wait_until_complete=False) ! except: ! pass ! if opt_verbose: color = { 0: tty_green, 1: tty_yellow, 2: tty_red, 3: tty_magenta }[status] *************** *** 214,224 **** return if not opt_dont_submit: ! open_command_pipe() ! if nagios_command_pipe: ! nagios_command_pipe.write("[%d] PROCESS_SERVICE_CHECK_RESULT;%s;Check_MK;%d;%s\n" % ! (int(time.time()), summary_hostname(hostname), status, output)) ! nagios_command_pipe.flush() if opt_verbose: color = { 0: tty_green, 1: tty_yellow, 2: tty_red, 3: tty_magenta }[status] print "%-20s %s%s%-70s%s" % ("Check_MK", tty_bold, color, output, tty_normal) --- 238,270 ---- return if not opt_dont_submit: ! if g_submit_via_pipe: ! open_command_pipe() ! if nagios_command_pipe: ! nagios_command_pipe.write("[%d] PROCESS_SERVICE_CHECK_RESULT;%s;Check_MK;%d;%s\n" % ! (int(time.time()), summary_hostname(hostname), status, output)) ! nagios_command_pipe.flush() ! if g_submit_via_gearman: ! queue = gearman_queue ! cmkout = ("type=%s\nhost_name=%s\nstart_time=%d\nfinish_time=%d\nlatency=%d\nreturn_code=%d\nservice_description=%s\noutput=%s\n" % ! ("passive", summary_hostname(hostname), int(time.time()), int(time.time()), 0.0, status, "Check_MK", output)) ! cmkout = gearman_strencode(cmkout) ! gm_client = gearman.GearmanClient(gearman_server) ! completed_job_request = gm_client.submit_job(queue, cmkout, background=True, wait_until_complete=False) ! # check_request_status(completed_job_request) ! ! # send to dup servers ! if gearman_dup_server: ! for s in gearman_dup_server: ! try: ! gm_client = gearman.GearmanClient(s) ! if gearman_dup_queue: ! queue = gearman_dup_queue ! ! completed_job_request = gm_client.submit_job(queue, cmkout, background=True, wait_until_complete=False) ! except: ! pass ! if opt_verbose: color = { 0: tty_green, 1: tty_yellow, 2: tty_red, 3: tty_magenta }[status] print "%-20s %s%s%-70s%s" % ("Check_MK", tty_bold, color, output, tty_normal) *************** *** 703,708 **** --- 749,760 ---- if opt_verbose: sys.stderr.write("Check_mk version %s\n" % check_mk_version) + if gearman_use: + global g_submit_via_gearman + global g_submit_via_pipe + g_submit_via_gearman = True + g_submit_via_pipe = False + start_time = time.time() try: *************** *** 911,923 **** perftext = "|" + (" ".join(perftexts)) if not opt_dont_submit: ! open_command_pipe() ! if nagios_command_pipe: ! nagios_command_pipe.write("[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n" % ! (int(time.time()), host, servicedesc, result[0], result[1] + perftext) ) ! # Important: Nagios needs the complete command in one single write() block! ! # Python buffers and sends chunks of 4096 bytes, if we do not flush. ! nagios_command_pipe.flush() if opt_verbose: if opt_showperfdata: --- 963,996 ---- perftext = "|" + (" ".join(perftexts)) if not opt_dont_submit: ! if g_submit_via_pipe: ! open_command_pipe() ! if nagios_command_pipe: ! nagios_command_pipe.write("[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n" % ! (int(time.time()), host, servicedesc, result[0], result[1] + perftext) ) ! # Important: Nagios needs the complete command in one single write() block! ! # Python buffers and sends chunks of 4096 bytes, if we do not flush. ! nagios_command_pipe.flush() ! if g_submit_via_gearman: ! queue = gearman_queue ! cmkout = ("type=%s\nhost_name=%s\nstart_time=%d\nfinish_time=%d\nlatency=%d\nreturn_code=%d\nservice_description=%s\noutput=%s\n" % ! ("passive", host, int(time.time()), int(time.time()), 0.0, result[0], servicedesc, "gearman_" + result[1] + perftext)) ! cmkout = gearman_strencode(cmkout) ! gm_client = gearman.GearmanClient(gearman_server) ! completed_job_request = gm_client.submit_job(queue, cmkout, background=True, wait_until_complete=False) ! # check_request_status(completed_job_request) ! ! # send to dup servers ! if gearman_dup_server: ! for s in gearman_dup_server: ! try: ! gm_client = gearman.GearmanClient(s) ! if gearman_dup_queue: ! queue = gearman_dup_queue ! ! completed_job_request = gm_client.submit_job(queue, cmkout, background=True, wait_until_complete=False) ! except: ! pass if opt_verbose: if opt_showperfdata: *************** *** 972,977 **** --- 1045,1106 ---- return nodes return None + def gearman_strencode(cmkout): + secretkey = None + + # Read key from gearman_secret or gearman_secert_file. Strip \t,\n,\r and spaces + if gearman_encryption: + if gearman_secret: + secretkey = gearman_secret.strip(' \t\n\r') + elif gearman_secret_file: + f = open(gearman_secret_file, 'r') + for key in f.readlines(): + if not key.isspace(): + secretkey = key.strip(' \t\n\r') + break + + # the block size for the cipher object; must be 16, 24, or 32 for AES + blocksize = 16 + + # maximum/minimum key string size + maxsize = 32 + + # bring keystring to the right size. If it's too short, fill with \x0 + if (len(secretkey) < maxsize): + mod = maxsize - len(secretkey)%maxsize + for i in range(mod): + secretkey = secretkey + chr(0) + elif (len(secretkey) > maxsize): + secretkey = secretkey[0:maxsize] + + # the character used for padding--with a block cipher such as AES, the value + # you encrypt must be a multiple of blocksize in length. This character is + # used to ensure that your value is always a multiple of blocksize + padding = '{' + + # one-liner to sufficiently pad the text to be encrypted + pad = lambda s: s + (blocksize - len(s) % blocksize) * padding + + # one-liners to encrypt/encode and decrypt/decode a string + # encrypt with AES, encode with base64 + EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s))) + DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(padding) + + # create a cipher object using the secret + cipher = AES.new(secretkey) + encrypted = EncodeAES(cipher, cmkout) + + return encrypted + else: + return base64.b64encode(cmkout) + + def check_request_status(job_request): + if job_request.complete: + print "Job %s finished! Result: %s - %s" % (job_request.job.unique, job_request.state, job_request.result) + elif job_request.timed_out: + print "Job %s timed out!" % job_request.unique + elif job_request.state == JOB_UNKNOWN: + print "Job %s connection failed!" % job_request.unique # +----------------------------------------------------------------------+ # | ____ _ _ _ _ | diff -crB modules/check_mk.py modules-gearman//check_mk.py *** modules/check_mk.py 2011-06-03 00:50:04.703021273 +0200 --- modules-gearman//check_mk.py 2011-06-03 01:18:00.415408749 +0200 *************** *** 286,291 **** --- 286,300 ---- donation_command = 'mail -r checkmk@yoursite.de -s "Host donation %s" donatehosts@mathias-kettner.de' % check_mk_version scanparent_hosts = [ ( ALL_HOSTS ) ] + gearman_secret = None + gearman_secret_file = None + gearman_encryption = True + gearman_server = [ 'localhost:4730' ] + gearman_dup_server = False + gearman_queue = 'check_results' + gearman_dup_queue = 'check_results_test' + gearman_use = False + # global variables used to cache temporary values (not needed in check_mk_base) ip_to_hostname_cache = None *************** *** 2016,2022 **** 'var_dir', 'counters_directory', 'tcp_cache_dir', 'snmpwalks_dir', 'check_mk_basedir', 'nagios_user', 'www_group', 'cluster_max_cachefile_age', 'check_max_cachefile_age', ! 'simulation_mode', 'aggregate_check_mk', 'debug_log', ]: output.write("%s = %r\n" % (var, globals()[var])) --- 2025,2031 ---- 'var_dir', 'counters_directory', 'tcp_cache_dir', 'snmpwalks_dir', 'check_mk_basedir', 'nagios_user', 'www_group', 'cluster_max_cachefile_age', 'check_max_cachefile_age', ! 'simulation_mode', 'aggregate_check_mk', 'debug_log', 'gearman_server', 'gearman_secret', 'gearman_queue', 'gearman_dup_server', 'gearman_dup_queue', 'gearman_secret_file', 'gearman_use', 'gearman_encryption', ]: output.write("%s = %r\n" % (var, globals()[var]))