diff --git a/poller-wrapper.py b/poller-wrapper.py old mode 100755 new mode 100644 index 148e15bd04..448a093288 --- a/poller-wrapper.py +++ b/poller-wrapper.py @@ -17,16 +17,24 @@ FreeBSD: cd /usr/ports/*/py-MySQLdb && make install clean Tested on: Python 2.7.3 / PHP 5.3.10-1ubuntu3.4 / Ubuntu 12.04 LTS - + GitHub: https://github.com/Atrato/observium-poller-wrapper - License: To the extent possible under law, Job Snijders has waived all - copyright and related or neighboring rights to this script. - This script has been put into the Public Domain. This work is + License: To the extent possible under law, Job Snijders has waived all + copyright and related or neighboring rights to this script. + This script has been put into the Public Domain. This work is published from: The Netherlands. """ try: - import threading, Queue, sys, subprocess, time, os, json + + import json + import os + import Queue + import subprocess + import sys + import threading + import time + except: print "ERROR: missing one or more of the following python modules:" print "threading, Queue, sys, subprocess, time, os, json" @@ -47,6 +55,7 @@ except: ob_install_dir = os.path.dirname(os.path.realpath(__file__)) config_file = ob_install_dir + '/config.php' + def get_config_data(): config_cmd = ['/usr/bin/env', 'php', '%s/config_to_json.php' % ob_install_dir] try: @@ -57,7 +66,8 @@ def get_config_data(): return proc.communicate()[0] try: - with open(config_file) as f: pass + with open(config_file) as f: + pass except IOError as e: print "ERROR: Oh dear... %s does not seem readable" % config_file sys.exit(2) @@ -71,8 +81,8 @@ except: poller_path = config['install_dir'] + '/poller.php' db_username = config['db_user'] db_password = config['db_pass'] -db_server = config['db_host'] -db_dbname = config['db_name'] +db_server = config['db_host'] +db_dbname = config['db_name'] # (c) 2015, GPLv3, Daniel Preussker << << << << << << 0 and nodes is not None: @@ -308,8 +328,8 @@ if distpoll == True or memc_alive() is True: print "Clearing Locks" x = minlocks while x <= maxlocks: - memc.delete('poller.device.'+str(x)) - x = x+1 + memc.delete('poller.device.' + str(x)) + x = x + 1 print "%s Locks Cleared" % x print "Clearing Nodes" memc.delete("poller.master") @@ -321,28 +341,30 @@ if distpoll == True or memc_alive() is True: show_stopper = False -query = "update pollers set last_polled=NOW(), devices='%d', time_taken='%d' where poller_name='%s'" % (polled_devices, total_time, config['distributed_poller_name']) +query = "update pollers set last_polled=NOW(), devices='%d', time_taken='%d' where poller_name='%s'" % (polled_devices, + total_time, config['distributed_poller_name']) response = cursor.execute(query) if response == 1: db.commit() else: - query = "insert into pollers set poller_name='%s', last_polled=NOW(), devices='%d', time_taken='%d'" % (config['distributed_poller_name'],polled_devices, total_time) + query = "insert into pollers set poller_name='%s', last_polled=NOW(), devices='%d', time_taken='%d'" % ( + config['distributed_poller_name'], polled_devices, total_time) cursor.execute(query) db.commit() db.close() if total_time > 300: - recommend = int(total_time / 300.0 * amount_of_workers + 1) print "WARNING: the process took more than 5 minutes to finish, you need faster hardware or more threads" print "INFO: in sequential style polling the elapsed time would have been: %s seconds" % real_duration for device in per_device_duration: if per_device_duration[device] > 300: print "WARNING: device %s is taking too long: %s seconds" % (device, per_device_duration[device]) show_stopper = True - if show_stopper == True: + if show_stopper: print "ERROR: Some devices are taking more than 300 seconds, the script cannot recommend you what to do." - if show_stopper == False: + else: + recommend = int(total_time / 300.0 * amount_of_workers + 1) print "WARNING: Consider setting a minimum of %d threads. (This does not constitute professional advice!)" % recommend sys.exit(2)