mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Replace poller-wrapper with exact version from https://github.com/Atrato/observium-poller-wrapper
This commit is contained in:
@@ -6,27 +6,24 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$defaults_config_file = 'includes/defaults.inc.php';
|
|
||||||
$config_file = 'config.php';
|
$config_file = 'config.php';
|
||||||
|
|
||||||
// move to observium install dir
|
// move to observium install dir
|
||||||
chdir(dirname($argv[0]));
|
chdir(dirname($argv[0]));
|
||||||
|
|
||||||
function is_cli()
|
function iscli() {
|
||||||
{
|
|
||||||
if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
|
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||||
{
|
return true;
|
||||||
return TRUE;
|
|
||||||
} else {
|
} else {
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we are running throw the CLI, otherwise abort
|
// check if we are running throw the CLI, otherwise abort
|
||||||
|
|
||||||
if (is_cli())
|
if ( iscli() ) {
|
||||||
{
|
|
||||||
require_once($defaults_config_file);
|
|
||||||
require_once($config_file);
|
require_once($config_file);
|
||||||
print(json_encode($config));
|
print(json_encode($config));
|
||||||
}
|
}
|
||||||
|
@@ -45,37 +45,6 @@ except:
|
|||||||
print "On FreeBSD: cd /usr/ports/*/py-MySQLdb && make install clean"
|
print "On FreeBSD: cd /usr/ports/*/py-MySQLdb && make install clean"
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
Parse Arguments
|
|
||||||
Attempt to use argparse module. Probably want to use this moving forward
|
|
||||||
especially as more features want to be added to this wrapper.
|
|
||||||
and
|
|
||||||
Take the amount of threads we want to run in parallel from the commandline
|
|
||||||
if None are given or the argument was garbage, fall back to default of 16
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
import argparse
|
|
||||||
parser = argparse.ArgumentParser(description='Poller Wrapper for Observium')
|
|
||||||
parser.add_argument('workers', nargs='?', type=int, default=16, help='Number of workers to spawn.')
|
|
||||||
parser.add_argument('--host', help='Poll hostname wildcard.')
|
|
||||||
args = parser.parse_args()
|
|
||||||
amount_of_workers = int(args.workers)
|
|
||||||
except ImportError:
|
|
||||||
print "WARNING: missing the argparse python module:"
|
|
||||||
print "On ubuntu: apt-get install libpython2.7-stdlib"
|
|
||||||
print "On debian: apt-get install python-argparse"
|
|
||||||
print "Continuing with basic argument support."
|
|
||||||
try:
|
|
||||||
amount_of_workers = int(sys.argv[1])
|
|
||||||
except:
|
|
||||||
amount_of_workers = 16
|
|
||||||
|
|
||||||
if amount_of_workers == 0:
|
|
||||||
print "ERROR: 0 threads is not a valid value"
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Fetch configuration details from the config_to_json.php script
|
Fetch configuration details from the config_to_json.php script
|
||||||
"""
|
"""
|
||||||
@@ -105,17 +74,27 @@ except:
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
poller_path = config['install_dir'] + '/poller.php'
|
poller_path = config['install_dir'] + '/poller.php'
|
||||||
alerter_path = config['install_dir'] + '/alerter.php'
|
|
||||||
db_username = config['db_user']
|
db_username = config['db_user']
|
||||||
db_password = config['db_pass']
|
db_password = config['db_pass']
|
||||||
db_server = config['db_host']
|
db_server = config['db_host']
|
||||||
db_dbname = config['db_name']
|
db_dbname = config['db_name']
|
||||||
alerting = config['poller-wrapper']['alerter']
|
|
||||||
|
|
||||||
s_time = time.time()
|
s_time = time.time()
|
||||||
real_duration = 0
|
real_duration = 0
|
||||||
per_device_duration = {}
|
per_device_duration = {}
|
||||||
|
|
||||||
|
"""
|
||||||
|
Take the amount of threads we want to run in parallel from the commandline
|
||||||
|
if None are given or the argument was garbage, fall back to default of 16
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
amount_of_workers = int(sys.argv[1])
|
||||||
|
if amount_of_workers == 0:
|
||||||
|
print "ERROR: 0 threads is not a valid value"
|
||||||
|
sys.exit(2)
|
||||||
|
except:
|
||||||
|
amount_of_workers = 16
|
||||||
|
|
||||||
devices_list = []
|
devices_list = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -125,30 +104,15 @@ except:
|
|||||||
print "ERROR: Could not connect to MySQL database!"
|
print "ERROR: Could not connect to MySQL database!"
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This query specifically orders the results depending on the last_polled_timetaken variable
|
This query specificly orders the results depending on the last_polled_timetaken variable
|
||||||
Because this way, we put the devices likely to be slow, in the top of the queue
|
Because this way, we put the devices likely to be slow, in the top of the queue
|
||||||
thus greatening our chances of completing _all_ the work in exactly the time it takes to
|
thus greatening our chances of completing _all_ the work in exactly the time it takes to
|
||||||
poll the slowest device! cool stuff he
|
poll the slowest device! cool stuff he
|
||||||
Additionally, if a hostname wildcard is passed, add it to the where clause. This is
|
|
||||||
important in cases where you have pollers distributed geographically and want to limit
|
|
||||||
pollers to polling hosts matching their geographic naming scheme.
|
|
||||||
"""
|
"""
|
||||||
|
query = "select device_id from devices where disabled = 0 order by last_polled_timetaken desc"
|
||||||
|
|
||||||
query = """SELECT device_id
|
|
||||||
FROM devices
|
|
||||||
WHERE disabled != '1'"""
|
|
||||||
order = " ORDER BY last_polled_timetaken DESC"
|
|
||||||
|
|
||||||
try:
|
|
||||||
host_wildcard = args.host.replace('*', '%')
|
|
||||||
wc_query = query + " AND hostname LIKE %s " + order
|
|
||||||
cursor.execute(wc_query, host_wildcard)
|
|
||||||
except:
|
|
||||||
query = query + order
|
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
|
||||||
devices = cursor.fetchall()
|
devices = cursor.fetchall()
|
||||||
for row in devices:
|
for row in devices:
|
||||||
devices_list.append(int(row[0]))
|
devices_list.append(int(row[0]))
|
||||||
@@ -187,11 +151,6 @@ def poll_worker():
|
|||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
command = "/usr/bin/env php %s -h %s >> /dev/null 2>&1" % (poller_path, device_id)
|
command = "/usr/bin/env php %s -h %s >> /dev/null 2>&1" % (poller_path, device_id)
|
||||||
subprocess.check_call(command, shell=True)
|
subprocess.check_call(command, shell=True)
|
||||||
if alerting == True:
|
|
||||||
print "INFO starting alerter.php for %s" % device_id
|
|
||||||
command = "/usr/bin/env php %s -h %s >> /dev/null 2>&1" % (alerter_path, device_id)
|
|
||||||
print "INFO finished alerter.php for %s" % device_id
|
|
||||||
subprocess.check_call(command, shell=True)
|
|
||||||
elapsed_time = int(time.time() - start_time)
|
elapsed_time = int(time.time() - start_time)
|
||||||
print_queue.put([threading.current_thread().name, device_id, elapsed_time])
|
print_queue.put([threading.current_thread().name, device_id, elapsed_time])
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
|
Reference in New Issue
Block a user