mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 10:28:13 +00:00
Added ability to enable debug output with wrappers (#8830)
Now with optparse (python 2.3+) Does not include your doc updates @laf If I get some time later, I'll add them, feel free to as well. DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [ ] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
This commit is contained in:
parent
69a6098d43
commit
a1aaafa6ff
@ -40,6 +40,7 @@ try:
|
|||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print "ERROR: missing one or more of the following python modules:"
|
print "ERROR: missing one or more of the following python modules:"
|
||||||
@ -85,6 +86,7 @@ except:
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
discovery_path = config['install_dir'] + '/discovery.php'
|
discovery_path = config['install_dir'] + '/discovery.php'
|
||||||
|
log_dir = config['log_dir']
|
||||||
db_username = config['db_user']
|
db_username = config['db_user']
|
||||||
db_password = config['db_pass']
|
db_password = config['db_pass']
|
||||||
db_port = int(config['db_port'])
|
db_port = int(config['db_port'])
|
||||||
@ -186,14 +188,19 @@ discovered_devices = 0
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
Take the amount of threads we want to run in parallel from the commandline
|
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
|
if None are given or the argument was garbage, fall back to default of 1
|
||||||
"""
|
"""
|
||||||
|
usage = "usage: %prog [options] <workers> (Default: 1 Do not set too high)"
|
||||||
|
description = "Spawn multiple discovery.php processes in parallel."
|
||||||
|
parser = OptionParser(usage=usage, description=description)
|
||||||
|
parser.add_option('-d', '--debug', action='store_true', default=False,
|
||||||
|
help="Enable debug output. WARNING: Leaving this enabled will consume a lot of disk space.")
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
debug = options.debug
|
||||||
try:
|
try:
|
||||||
amount_of_workers = int(sys.argv[1])
|
amount_of_workers = int(args[0])
|
||||||
if amount_of_workers == 0:
|
except (IndexError, ValueError):
|
||||||
print "ERROR: 0 threads is not a valid value"
|
|
||||||
sys.exit(2)
|
|
||||||
except:
|
|
||||||
amount_of_workers = 1
|
amount_of_workers = 1
|
||||||
|
|
||||||
devices_list = []
|
devices_list = []
|
||||||
@ -304,8 +311,11 @@ def poll_worker():
|
|||||||
# EOC5
|
# EOC5
|
||||||
try:
|
try:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
command = "/usr/bin/env php %s -h %s >> /dev/null 2>&1" % (discovery_path, device_id)
|
|
||||||
|
output = "-d >> %s/discover_device_%s.log" % (log_dir, device_id) if debug else ">> /dev/null"
|
||||||
|
command = "/usr/bin/env php %s -h %s %s 2>&1" % (discovery_path, device_id, output)
|
||||||
subprocess.check_call(command, shell=True)
|
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):
|
||||||
|
@ -11,6 +11,8 @@ to LibreNMS - localhost is a good one. This is needed in order for alerting to w
|
|||||||
> Service checks is now distributed aware. If you run a distributed setup then you can now run
|
> Service checks is now distributed aware. If you run a distributed setup then you can now run
|
||||||
`services-wrapper.py` in cron instead of `check-services.php` across all polling nodes.
|
`services-wrapper.py` in cron instead of `check-services.php` across all polling nodes.
|
||||||
|
|
||||||
|
If you need to debug the output of services-wrapper.py then you can add `-d` to the end of the command - it is NOT recommended to do this in cron.
|
||||||
|
|
||||||
Firstly, install Nagios plugins however you would like, this could be via yum, apt-get or direct from source.
|
Firstly, install Nagios plugins however you would like, this could be via yum, apt-get or direct from source.
|
||||||
|
|
||||||
Next, you need to enable the services within config.php with the following:
|
Next, you need to enable the services within config.php with the following:
|
||||||
@ -30,9 +32,9 @@ For example:
|
|||||||
chmod +x /usr/lib/nagios/plugins/*
|
chmod +x /usr/lib/nagios/plugins/*
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, you now need to add check-services.php to the current cron file (/etc/cron.d/librenms typically) like:
|
Finally, you now need to add services-wrapper.py to the current cron file (/etc/cron.d/librenms typically) like:
|
||||||
```bash
|
```bash
|
||||||
*/5 * * * * librenms /opt/librenms/check-services.php >> /dev/null 2>&1
|
*/5 * * * * librenms /opt/librenms/services-wrapper.py 1
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you can add services via the main Services link in the navbar, or via the 'Add Service' link within the device, services page.
|
Now you can add services via the main Services link in the navbar, or via the 'Add Service' link within the device, services page.
|
||||||
|
@ -39,6 +39,8 @@ new will poll only those devices that have recently been added or have been sele
|
|||||||
|
|
||||||
We have a `discovery-wrapper.py` script which is based on `poller-wrapper.py` by [Job Snijders](https://github.com/job). This script is currently the default.
|
We have a `discovery-wrapper.py` script which is based on `poller-wrapper.py` by [Job Snijders](https://github.com/job). This script is currently the default.
|
||||||
|
|
||||||
|
If you need to debug the output of discovery-wrapper.py then you can add `-d` to the end of the command - it is NOT recommended to do this in cron.
|
||||||
|
|
||||||
If you want to switch back to discovery.php then you can replace:
|
If you want to switch back to discovery.php then you can replace:
|
||||||
|
|
||||||
`33 */6 * * * librenms /opt/librenms/discovery-wrapper.py 1 >> /dev/null 2>&1`
|
`33 */6 * * * librenms /opt/librenms/discovery-wrapper.py 1 >> /dev/null 2>&1`
|
||||||
|
@ -36,6 +36,12 @@ even. all will run poller against all devices.
|
|||||||
|
|
||||||
`-m` This enables you to specify the module you want to run for poller.
|
`-m` This enables you to specify the module you want to run for poller.
|
||||||
|
|
||||||
|
#### Poller Wrapper
|
||||||
|
|
||||||
|
We have a `poller-wrapper.py` script by [Job Snijders](https://github.com/job). This script is currently the default.
|
||||||
|
|
||||||
|
If you need to debug the output of poller-wrapper.py then you can add `-d` to the end of the command - it is NOT recommended to do this in cron.
|
||||||
|
|
||||||
#### Poller config
|
#### Poller config
|
||||||
|
|
||||||
These are the default poller config items. You can globally disable a module by setting it to 0. If you just want to
|
These are the default poller config items. You can globally disable a module by setting it to 0. If you just want to
|
||||||
|
@ -30,6 +30,7 @@ try:
|
|||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print "ERROR: missing one or more of the following python modules:"
|
print "ERROR: missing one or more of the following python modules:"
|
||||||
@ -75,6 +76,7 @@ except:
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
poller_path = config['install_dir'] + '/poller.php'
|
poller_path = config['install_dir'] + '/poller.php'
|
||||||
|
log_dir = config['log_dir']
|
||||||
db_username = config['db_user']
|
db_username = config['db_user']
|
||||||
db_password = config['db_pass']
|
db_password = config['db_pass']
|
||||||
db_port = int(config['db_port'])
|
db_port = int(config['db_port'])
|
||||||
@ -194,12 +196,17 @@ polled_devices = 0
|
|||||||
Take the amount of threads we want to run in parallel from the commandline
|
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
|
if None are given or the argument was garbage, fall back to default of 16
|
||||||
"""
|
"""
|
||||||
|
usage = "usage: %prog [options] <workers> (Default: 16 (Do not set too high)"
|
||||||
|
description = "Spawn multiple poller.php processes in parallel."
|
||||||
|
parser = OptionParser(usage=usage, description=description)
|
||||||
|
parser.add_option('-d', '--debug', action='store_true', default=False,
|
||||||
|
help="Enable debug output. WARNING: Leaving this enabled will consume a lot of disk space.")
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
debug = options.debug
|
||||||
try:
|
try:
|
||||||
amount_of_workers = int(sys.argv[1])
|
amount_of_workers = int(args[0])
|
||||||
if amount_of_workers == 0:
|
except (IndexError, ValueError):
|
||||||
print "ERROR: 0 threads is not a valid value"
|
|
||||||
sys.exit(2)
|
|
||||||
except:
|
|
||||||
amount_of_workers = 16
|
amount_of_workers = 16
|
||||||
|
|
||||||
devices_list = []
|
devices_list = []
|
||||||
@ -310,8 +317,11 @@ def poll_worker():
|
|||||||
# EOC5
|
# EOC5
|
||||||
try:
|
try:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
command = "/usr/bin/env php %s -h %s >> /dev/null 2>&1" % (poller_path, device_id)
|
|
||||||
|
output = "-d >> %s/poll_device_%s.log" % (log_dir, device_id) if debug else ">> /dev/null"
|
||||||
|
command = "/usr/bin/env php %s -h %s %s 2>&1" % (poller_path, device_id, output)
|
||||||
subprocess.check_call(command, shell=True)
|
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):
|
||||||
|
@ -40,6 +40,7 @@ try:
|
|||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print "ERROR: missing one or more of the following python modules:"
|
print "ERROR: missing one or more of the following python modules:"
|
||||||
@ -85,6 +86,7 @@ except:
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
service_path = config['install_dir'] + '/check-services.php'
|
service_path = config['install_dir'] + '/check-services.php'
|
||||||
|
log_dir = config['log_dir']
|
||||||
db_username = config['db_user']
|
db_username = config['db_user']
|
||||||
db_password = config['db_pass']
|
db_password = config['db_pass']
|
||||||
|
|
||||||
@ -192,12 +194,17 @@ service_devices = 0
|
|||||||
Take the amount of threads we want to run in parallel from the commandline
|
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
|
if None are given or the argument was garbage, fall back to default of 16
|
||||||
"""
|
"""
|
||||||
|
usage = "usage: %prog [options] <workers> (Default: 1 (Do not set too high)"
|
||||||
|
description = "Spawn multiple check-services.php processes in parallel."
|
||||||
|
parser = OptionParser(usage=usage, description=description)
|
||||||
|
parser.add_option('-d', '--debug', action='store_true', default=False,
|
||||||
|
help="Enable debug output. WARNING: Leaving this enabled will consume a lot of disk space.")
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
debug = options.debug
|
||||||
try:
|
try:
|
||||||
amount_of_workers = int(sys.argv[1])
|
amount_of_workers = int(args[0])
|
||||||
if amount_of_workers == 0:
|
except (IndexError, ValueError):
|
||||||
print "ERROR: 0 threads is not a valid value"
|
|
||||||
sys.exit(2)
|
|
||||||
except:
|
|
||||||
amount_of_workers = 1
|
amount_of_workers = 1
|
||||||
|
|
||||||
devices_list = []
|
devices_list = []
|
||||||
@ -302,8 +309,11 @@ def poll_worker():
|
|||||||
# EOC5
|
# EOC5
|
||||||
try:
|
try:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
command = "/usr/bin/env php %s -h %s >> /dev/null 2>&1" % (service_path, device_id)
|
|
||||||
|
output = "-d >> %s/services_device_%s.log" % (log_dir, device_id) if debug else ">> /dev/null"
|
||||||
|
command = "/usr/bin/env php %s -h %s %s 2>&1" % (service_path, device_id, output)
|
||||||
subprocess.check_call(command, shell=True)
|
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):
|
||||||
|
Loading…
Reference in New Issue
Block a user