mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 02:18:39 +00:00
Deprecate poller.php (#15370)
* Deprecate poller.php * Apply fixes from StyleCI * Remove references to poller.php Leave wrapper... * fix python style * update wraper to call lnms device:poll * Quiet output too * make pb happy --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
This commit is contained in:
parent
008efe41cd
commit
e0444bffcf
26
.github/ISSUE_TEMPLATE/device_bug.yml
vendored
26
.github/ISSUE_TEMPLATE/device_bug.yml
vendored
@ -6,9 +6,9 @@ body:
|
|||||||
value: |
|
value: |
|
||||||
This issue form is for reporting device ***_BUGS_*** only!
|
This issue form is for reporting device ***_BUGS_*** only!
|
||||||
|
|
||||||
* [Add Device request here](https://community.librenms.org/c/device-requests/12)
|
* [Add Device request here](https://community.librenms.org/c/device-requests/12)
|
||||||
* [I have a question or need support](https://www.librenms.org/#support)
|
* [I have a question or need support](https://www.librenms.org/#support)
|
||||||
|
|
||||||
- type: textarea
|
- type: textarea
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
@ -23,53 +23,53 @@ body:
|
|||||||
attributes:
|
attributes:
|
||||||
value: |
|
value: |
|
||||||
## Environment
|
## Environment
|
||||||
|
|
||||||
- type: textarea
|
- type: textarea
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
attributes:
|
attributes:
|
||||||
label: Output of ./validate.php
|
label: Output of ./validate.php
|
||||||
description: |
|
description: |
|
||||||
Please post the output of running: /opt/librenms/validate.php
|
Please post the output of running: /opt/librenms/validate.php
|
||||||
render: txt
|
render: txt
|
||||||
|
|
||||||
- type: input
|
- type: input
|
||||||
attributes:
|
attributes:
|
||||||
label: What was the last working version of LibreNMS?
|
label: What was the last working version of LibreNMS?
|
||||||
placeholder: 21.7.0
|
placeholder: 21.7.0
|
||||||
description: >
|
description: >
|
||||||
If known, otherwise leave blank.
|
If known, otherwise leave blank.
|
||||||
|
|
||||||
- type: input
|
- type: input
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
attributes:
|
attributes:
|
||||||
label: Device info
|
label: Device info
|
||||||
placeholder: Juniper SRX1500
|
placeholder: Juniper SRX1500
|
||||||
description: >
|
description: >
|
||||||
The Brand and model of the device
|
The Brand and model of the device
|
||||||
|
|
||||||
- type: markdown
|
- type: markdown
|
||||||
attributes:
|
attributes:
|
||||||
value: |
|
value: |
|
||||||
# Details
|
# Details
|
||||||
|
|
||||||
- type: textarea
|
- type: textarea
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
attributes:
|
attributes:
|
||||||
label: Discovery output
|
label: Discovery output
|
||||||
description: |
|
description: |
|
||||||
Paste the result of:
|
Paste the result of:
|
||||||
./discovery.php -d -h HOSTNAME
|
./discovery.php -d -h HOSTNAME
|
||||||
render: txt
|
render: txt
|
||||||
|
|
||||||
- type: textarea
|
- type: textarea
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
attributes:
|
attributes:
|
||||||
label: Poller output
|
label: Poller output
|
||||||
description: |
|
description: |
|
||||||
Paste the result of:
|
Paste the result of:
|
||||||
./poller.php -r -f -p -d -h HOSTNAME
|
lnms device:poll HOSTNAME -vv --no-data
|
||||||
render: txt
|
render: txt
|
||||||
|
@ -539,8 +539,12 @@ class PollerQueueManager(QueueManager):
|
|||||||
if self.lock(device_id, timeout=self.config.poller.frequency):
|
if self.lock(device_id, timeout=self.config.poller.frequency):
|
||||||
logger.info("Polling device {}".format(device_id))
|
logger.info("Polling device {}".format(device_id))
|
||||||
|
|
||||||
args = ("-d", "-h", device_id) if self.config.debug else ("-h", device_id)
|
args = (
|
||||||
exit_code, output = LibreNMS.call_script("poller.php", args)
|
("device:poll", device_id, "-vv")
|
||||||
|
if self.config.debug
|
||||||
|
else ("device:poll", device_id, "-q")
|
||||||
|
)
|
||||||
|
exit_code, output = LibreNMS.call_script("lnms", args)
|
||||||
|
|
||||||
if self.config.log_output:
|
if self.config.log_output:
|
||||||
with open(
|
with open(
|
||||||
|
@ -55,7 +55,6 @@ import LibreNMS
|
|||||||
from LibreNMS.command_runner import command_runner
|
from LibreNMS.command_runner import command_runner
|
||||||
from LibreNMS.config import DBConfig
|
from LibreNMS.config import DBConfig
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Timeout in seconds for any poller / service / discovery action per device
|
# Timeout in seconds for any poller / service / discovery action per device
|
||||||
@ -86,6 +85,7 @@ All time related variables are in seconds
|
|||||||
wrappers = {
|
wrappers = {
|
||||||
"service": {
|
"service": {
|
||||||
"executable": "check-services.php",
|
"executable": "check-services.php",
|
||||||
|
"option": "-h",
|
||||||
"table_name": "services",
|
"table_name": "services",
|
||||||
"memc_touch_time": 10,
|
"memc_touch_time": 10,
|
||||||
"stepping": 300,
|
"stepping": 300,
|
||||||
@ -94,6 +94,7 @@ wrappers = {
|
|||||||
},
|
},
|
||||||
"discovery": {
|
"discovery": {
|
||||||
"executable": "discovery.php",
|
"executable": "discovery.php",
|
||||||
|
"option": "-h",
|
||||||
"table_name": "devices",
|
"table_name": "devices",
|
||||||
"memc_touch_time": 30,
|
"memc_touch_time": 30,
|
||||||
"stepping": 300,
|
"stepping": 300,
|
||||||
@ -101,7 +102,8 @@ wrappers = {
|
|||||||
"total_exec_time": 21600,
|
"total_exec_time": 21600,
|
||||||
},
|
},
|
||||||
"poller": {
|
"poller": {
|
||||||
"executable": "poller.php",
|
"executable": "lnms",
|
||||||
|
"option": "device:poll -q",
|
||||||
"table_name": "devices",
|
"table_name": "devices",
|
||||||
"memc_touch_time": 10,
|
"memc_touch_time": 10,
|
||||||
"stepping": 300,
|
"stepping": 300,
|
||||||
@ -280,7 +282,9 @@ def poll_worker(
|
|||||||
os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
|
os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
|
||||||
wrappers[wrapper_type]["executable"],
|
wrappers[wrapper_type]["executable"],
|
||||||
)
|
)
|
||||||
command = "/usr/bin/env php {} -h {}".format(executable, device_id)
|
command = "/usr/bin/env php {} {} {}".format(
|
||||||
|
executable, wrappers[wrapper_type]["option"], device_id
|
||||||
|
)
|
||||||
if modules is not None and len(str(modules).strip()):
|
if modules is not None and len(str(modules).strip()):
|
||||||
module_str = re.sub("\s", "", str(modules).strip())
|
module_str = re.sub("\s", "", str(modules).strip())
|
||||||
command = command + " -m {}".format(module_str)
|
command = command + " -m {}".format(module_str)
|
||||||
|
@ -1,96 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use App\Models\Device;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Symfony\Component\Process\Process;
|
|
||||||
|
|
||||||
class FindWarnings extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'find:warnings {regex? : regex to match snmprec files (default /.*/)}';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Command description';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $found = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
// TODO DELETE ME
|
|
||||||
|
|
||||||
$regex = $this->argument('regex') ?: '/./';
|
|
||||||
$modules = 'core,isis,mempools,mpls,nac,netstats,os,printer-supplies,slas';
|
|
||||||
|
|
||||||
foreach (glob(base_path('tests/snmpsim/*.snmprec')) as $file) {
|
|
||||||
if ($this->found) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$community = basename($file, '.snmprec');
|
|
||||||
if (preg_match($regex, $community)) {
|
|
||||||
$this->addDevice($community);
|
|
||||||
$this->info($community);
|
|
||||||
|
|
||||||
$process = new Process(['./discovery.php', '-d', '-h', 'snmpsim', '-m', $modules]);
|
|
||||||
$process->run([$this, 'find']);
|
|
||||||
|
|
||||||
$process = new Process(['./poller.php', '-d', '-h', 'snmpsim', '-m', $modules]);
|
|
||||||
$process->run([$this, 'find']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Command::SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function find(string $type, string $buffer): void
|
|
||||||
{
|
|
||||||
if (Str::contains($buffer, ['Warning:', 'Error:'])) {
|
|
||||||
preg_match_all('/^(Warning|\S*Error): .*$/', $buffer, $matches);
|
|
||||||
|
|
||||||
$this->error(implode(PHP_EOL, $matches[0]));
|
|
||||||
$this->found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addDevice(string $community): void
|
|
||||||
{
|
|
||||||
$device = Device::firstOrNew(['hostname' => 'snmpsim']);
|
|
||||||
$device->overwrite_ip = '127.1.6.1';
|
|
||||||
$device->port = 1161;
|
|
||||||
$device->snmpver = 'v2c';
|
|
||||||
$device->transport = 'udp';
|
|
||||||
$device->community = $community;
|
|
||||||
$device->last_discovered = null;
|
|
||||||
$device->status_reason = '';
|
|
||||||
$device->save();
|
|
||||||
}
|
|
||||||
}
|
|
@ -64,7 +64,7 @@ mode by adding a `-d` flag.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
./discovery.php -d -h HOSTNAME
|
./discovery.php -d -h HOSTNAME
|
||||||
./poller.php -d -h HOSTNAME
|
lnms device:poll HOSTNAME -vv
|
||||||
```
|
```
|
||||||
|
|
||||||
### Inspecting variables
|
### Inspecting variables
|
||||||
|
@ -248,7 +248,7 @@ Discovery
|
|||||||
Polling
|
Polling
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./poller.php -h HOSTNAME
|
lnms device:poll HOSTNAME
|
||||||
```
|
```
|
||||||
|
|
||||||
At this step we should see all the values retrieved in LibreNMS.
|
At this step we should see all the values retrieved in LibreNMS.
|
||||||
|
@ -490,7 +490,7 @@ COMMUNITY. Use `snmpwalk` instead of `snmpbulkwalk` for v1 devices.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
./discovery.php -h HOSTNAME -d | ./pbin.sh
|
./discovery.php -h HOSTNAME -d | ./pbin.sh
|
||||||
./poller.php -h HOSTNAME -r -f -d | ./pbin.sh
|
lnms device:poll HOSTNAME -vv | ./pbin.sh
|
||||||
snmpbulkwalk -OUneb -v2c -c COMMUNITY HOSTNAME . | ./pbin.sh
|
snmpbulkwalk -OUneb -v2c -c COMMUNITY HOSTNAME . | ./pbin.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1,46 +1,32 @@
|
|||||||
# poller.php
|
# lnms device:poll
|
||||||
|
|
||||||
This document will explain how to use poller.php to debug issues or
|
This document will explain how to use `lnms device:poll` to debug issues or
|
||||||
manually running to process data.
|
manually running to process data.
|
||||||
|
|
||||||
## Command options
|
## Command options
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
LibreNMS 2014.master Poller
|
Description:
|
||||||
|
Poll data from device(s) as defined by discovery
|
||||||
|
|
||||||
-h <device id> | <device hostname wildcard> Poll single device
|
Usage:
|
||||||
-h odd Poll odd numbered devices (same as -i 2 -n 0)
|
device:poll [options] [--] <device spec>
|
||||||
-h even Poll even numbered devices (same as -i 2 -n 1)
|
|
||||||
-h all Poll all devices
|
|
||||||
|
|
||||||
-i <instances> -n <number> Poll as instance <number> of <instances>
|
Arguments:
|
||||||
Instances start at 0. 0-3 for -n 4
|
device spec Device spec to poll: device_id, hostname, wildcard (*), odd, even, all
|
||||||
|
|
||||||
Debugging and testing options:
|
Options:
|
||||||
-r Do not create or update RRDs
|
-m, --modules=MODULES Specify single module to be run. Comma separate modules, submodules may be added with /
|
||||||
-f Do not insert data into InfluxDB
|
-x, --no-data Do not update datastores (RRD, InfluxDB, etc)
|
||||||
-d Enable debugging output
|
-h, --help Display help for the given command. When no command is given display help for the list command
|
||||||
-v Enable verbose debugging output
|
-q, --quiet Do not output any message
|
||||||
-m Specify module(s) to be run. Comma separate modules, submodules may be added with /
|
-V, --version Display this application version
|
||||||
|
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
|
||||||
|
-n, --no-interaction Do not ask any interactive question
|
||||||
|
--env[=ENV] The environment the command should run under
|
||||||
|
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
|
||||||
```
|
```
|
||||||
|
|
||||||
`-h` Use this to specify a device via either id or hostname (including
|
|
||||||
wildcard using *). You can also specify odd and even. all will run
|
|
||||||
poller against all devices.
|
|
||||||
|
|
||||||
`-i` This can be used to stagger the poller process.
|
|
||||||
|
|
||||||
`-r` This option will suppress the creation or update of RRD files.
|
|
||||||
|
|
||||||
`-d` Enables debugging output (verbose output but with most sensitive
|
|
||||||
data masked) so that you can see what is happening during a poller
|
|
||||||
run. This includes things like rrd updates, SQL queries and response
|
|
||||||
from snmp.
|
|
||||||
|
|
||||||
`-v` Enables verbose debugging output with all data in tact.
|
|
||||||
|
|
||||||
`-m` This enables you to specify the module you want to run for poller.
|
|
||||||
|
|
||||||
## Poller Wrapper
|
## Poller Wrapper
|
||||||
|
|
||||||
We have a `poller-wrapper.py` script by [Job
|
We have a `poller-wrapper.py` script by [Job
|
||||||
@ -201,36 +187,36 @@ configured to be ignored by config options.
|
|||||||
Here are some examples of running poller from within your install directory.
|
Here are some examples of running poller from within your install directory.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./poller.php -h localhost
|
lnms device:poll localhost
|
||||||
|
|
||||||
./poller.php -h localhost -m ports
|
lnms device:poll localhost -m ports
|
||||||
```
|
```
|
||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
|
|
||||||
To provide debugging output you will need to run the poller process
|
To provide debugging output you will need to run the poller process
|
||||||
with the `-d` flag. You can do this either against
|
with the `-vv` flag. You can do this either against
|
||||||
all modules, single or multiple modules:
|
all modules, single or multiple modules:
|
||||||
|
|
||||||
All Modules
|
All Modules
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./poller.php -h localhost -d
|
lnms device:poll localhost -vv
|
||||||
```
|
```
|
||||||
|
|
||||||
Single Module
|
Single Module
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./poller.php -h localhost -m ports -d
|
lnms device:poll localhost -m ports -vv
|
||||||
```
|
```
|
||||||
|
|
||||||
Multiple Modules
|
Multiple Modules
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./poller.php -h localhost -m ports,entity-physical -d
|
lnms device:poll localhost -m ports,entity-physical -vv
|
||||||
```
|
```
|
||||||
|
|
||||||
Using `-d` shouldn't output much sensitive information, `-v` will so
|
Using `-vv` shouldn't output much sensitive information, `-vvv` will so
|
||||||
it is then advisable to sanitise the output before pasting it
|
it is then advisable to sanitise the output before pasting it
|
||||||
somewhere as the debug output will contain snmp details amongst other
|
somewhere as the debug output will contain snmp details amongst other
|
||||||
items including port descriptions.
|
items including port descriptions.
|
||||||
|
@ -32,7 +32,7 @@ $type = $_REQUEST['type'];
|
|||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'poller':
|
case 'poller':
|
||||||
$cmd = ['php', \LibreNMS\Config::get('install_dir') . '/poller.php', '-h', $hostname, '-r', '-f', '-d'];
|
$cmd = ['php', \LibreNMS\Config::get('install_dir') . '/lnms', 'device:poll', $hostname, '--no-data', '-vv'];
|
||||||
$filename = "poller-$hostname.txt";
|
$filename = "poller-$hostname.txt";
|
||||||
break;
|
break;
|
||||||
case 'snmpwalk':
|
case 'snmpwalk':
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\DeviceGraph;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use LibreNMS\Config;
|
|
||||||
use LibreNMS\Enum\Severity;
|
use LibreNMS\Enum\Severity;
|
||||||
use LibreNMS\Exceptions\JsonAppBase64DecodeException;
|
use LibreNMS\Exceptions\JsonAppBase64DecodeException;
|
||||||
use LibreNMS\Exceptions\JsonAppBlankJsonException;
|
use LibreNMS\Exceptions\JsonAppBlankJsonException;
|
||||||
@ -242,221 +240,6 @@ function record_sensor_data($device, $all_sensors)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $device The device to poll
|
|
||||||
* @param bool $force_module Ignore device module overrides
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function poll_device($device, $force_module = false)
|
|
||||||
{
|
|
||||||
global $device, $graphs;
|
|
||||||
|
|
||||||
$device_start = microtime(true);
|
|
||||||
|
|
||||||
$deviceModel = DeviceCache::getPrimary();
|
|
||||||
$device['attribs'] = $deviceModel->getAttribs();
|
|
||||||
|
|
||||||
$os = \LibreNMS\OS::make($device);
|
|
||||||
|
|
||||||
unset($array);
|
|
||||||
|
|
||||||
// Start counting device poll time
|
|
||||||
echo 'Hostname: ' . $device['hostname'] . PHP_EOL;
|
|
||||||
echo 'Device ID: ' . $device['device_id'] . PHP_EOL;
|
|
||||||
echo 'OS: ' . $device['os'] . PHP_EOL;
|
|
||||||
|
|
||||||
if (empty($device['overwrite_ip'])) {
|
|
||||||
$ip = dnslookup($device);
|
|
||||||
} else {
|
|
||||||
$ip = $device['overwrite_ip'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$db_ip = null;
|
|
||||||
if (! empty($ip)) {
|
|
||||||
if (empty($device['overwrite_ip'])) {
|
|
||||||
echo 'Resolved IP: ' . $ip . PHP_EOL;
|
|
||||||
} else {
|
|
||||||
echo 'Assigned IP: ' . $ip . PHP_EOL;
|
|
||||||
}
|
|
||||||
$db_ip = inet_pton($ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! empty($db_ip) && inet6_ntop($db_ip) != inet6_ntop($device['ip'])) {
|
|
||||||
log_event('Device IP changed to ' . $ip, $device, 'system', 3);
|
|
||||||
dbUpdate(['ip' => $db_ip], 'devices', 'device_id=?', [$device['device_id']]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($os_group = Config::get("os.{$device['os']}.group")) {
|
|
||||||
$device['os_group'] = $os_group;
|
|
||||||
echo ' (' . $device['os_group'] . ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo PHP_EOL . PHP_EOL;
|
|
||||||
|
|
||||||
unset($poll_update);
|
|
||||||
unset($poll_update_query);
|
|
||||||
unset($poll_separator);
|
|
||||||
$poll_update_array = [];
|
|
||||||
$update_array = [];
|
|
||||||
|
|
||||||
$host_rrd = Rrd::name($device['hostname'], '', '');
|
|
||||||
if (Config::get('norrd') !== true && ! is_dir($host_rrd)) {
|
|
||||||
mkdir($host_rrd);
|
|
||||||
echo "Created directory : $host_rrd\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$helper = new \LibreNMS\Polling\ConnectivityHelper($deviceModel);
|
|
||||||
$helper->saveMetrics();
|
|
||||||
|
|
||||||
if ($helper->isUp()) {
|
|
||||||
if ($device['snmp_disable']) {
|
|
||||||
// only non-snmp modules
|
|
||||||
Config::set('poller_modules', array_intersect_key(Config::get('poller_modules'), [
|
|
||||||
'availability' => true,
|
|
||||||
'ipmi' => true,
|
|
||||||
'unix-agent' => true,
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
// update $device array status
|
|
||||||
$device['status'] = $deviceModel->status;
|
|
||||||
$device['status_reason'] = $deviceModel->status_reason;
|
|
||||||
|
|
||||||
/** @var \App\Polling\Measure\MeasurementManager $measurements */
|
|
||||||
$measurements = app(\App\Polling\Measure\MeasurementManager::class);
|
|
||||||
$measurements->checkpoint(); // don't count previous stats
|
|
||||||
|
|
||||||
foreach (Config::get('poller_modules') as $module => $module_status) {
|
|
||||||
if (! is_file("includes/polling/$module.inc.php")) {
|
|
||||||
echo "Module $module does not exist, please remove it from your configuration";
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$os_module_status = Config::get("os.{$device['os']}.poller_modules.$module");
|
|
||||||
d_echo('Modules status: Global' . (isset($module_status) ? ($module_status ? '+ ' : '- ') : ' '));
|
|
||||||
d_echo('OS' . (isset($os_module_status) ? ($os_module_status ? '+ ' : '- ') : ' '));
|
|
||||||
d_echo('Device' . (isset($device['attribs']['poll_' . $module]) ? ($device['attribs']['poll_' . $module] ? '+ ' : '- ') : ' '));
|
|
||||||
if ($force_module === true ||
|
|
||||||
! empty($device['attribs']['poll_' . $module]) ||
|
|
||||||
($os_module_status && ! isset($device['attribs']['poll_' . $module])) ||
|
|
||||||
($module_status && ! isset($os_module_status) && ! isset($device['attribs']['poll_' . $module]))) {
|
|
||||||
$start_memory = memory_get_usage();
|
|
||||||
$module_start = microtime(true);
|
|
||||||
echo "\n#### Load poller module $module ####\n";
|
|
||||||
|
|
||||||
try {
|
|
||||||
include "includes/polling/$module.inc.php";
|
|
||||||
} catch (Throwable $e) {
|
|
||||||
// isolate module exceptions so they don't disrupt the polling process
|
|
||||||
Log::error("%rError polling $module module for {$device['hostname']}.%n $e", ['color' => true]);
|
|
||||||
\App\Models\Eventlog::log("Error polling $module module. Check log file for more details.", $device['device_id'], 'poller', Severity::Error);
|
|
||||||
report($e);
|
|
||||||
|
|
||||||
// Re-throw exception if we're in CI
|
|
||||||
if (getenv('CI') == true) {
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$module_time = microtime(true) - $module_start;
|
|
||||||
$module_mem = (memory_get_usage() - $start_memory);
|
|
||||||
printf("\n>> Runtime for poller module '%s': %.4f seconds with %s bytes\n", $module, $module_time, $module_mem);
|
|
||||||
$measurements->printChangedStats();
|
|
||||||
echo "#### Unload poller module $module ####\n\n";
|
|
||||||
|
|
||||||
// save per-module poller stats
|
|
||||||
$tags = [
|
|
||||||
'module' => $module,
|
|
||||||
'rrd_def' => RrdDefinition::make()->addDataset('poller', 'GAUGE', 0),
|
|
||||||
'rrd_name' => ['poller-perf', $module],
|
|
||||||
];
|
|
||||||
$fields = [
|
|
||||||
'poller' => $module_time,
|
|
||||||
];
|
|
||||||
data_update($device, 'poller-perf', $tags, $fields);
|
|
||||||
$os->enableGraph('poller_perf');
|
|
||||||
|
|
||||||
// remove old rrd
|
|
||||||
$oldrrd = Rrd::name($device['hostname'], ['poller', $module, 'perf']);
|
|
||||||
if (is_file($oldrrd)) {
|
|
||||||
unlink($oldrrd);
|
|
||||||
}
|
|
||||||
unset($tags, $fields, $oldrrd);
|
|
||||||
} elseif (isset($device['attribs']['poll_' . $module]) && $device['attribs']['poll_' . $module] == '0') {
|
|
||||||
echo "Module [ $module ] disabled on host.\n\n";
|
|
||||||
} elseif (isset($os_module_status) && $os_module_status == '0') {
|
|
||||||
echo "Module [ $module ] disabled on os.\n\n";
|
|
||||||
} else {
|
|
||||||
echo "Module [ $module ] disabled globally.\n\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ping response
|
|
||||||
if ($helper->canPing()) {
|
|
||||||
$os->enableGraph('ping_perf');
|
|
||||||
}
|
|
||||||
|
|
||||||
$device_time = round(microtime(true) - $device_start, 3);
|
|
||||||
|
|
||||||
// Poller performance
|
|
||||||
if (! empty($device_time)) {
|
|
||||||
$tags = [
|
|
||||||
'rrd_def' => RrdDefinition::make()->addDataset('poller', 'GAUGE', 0),
|
|
||||||
'module' => 'ALL',
|
|
||||||
];
|
|
||||||
$fields = [
|
|
||||||
'poller' => $device_time,
|
|
||||||
];
|
|
||||||
|
|
||||||
data_update($device, 'poller-perf', $tags, $fields);
|
|
||||||
$os->enableGraph('poller_modules_perf');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $force_module) {
|
|
||||||
// don't update last_polled time if we are forcing a specific module to be polled
|
|
||||||
$update_array['last_polled'] = ['NOW()'];
|
|
||||||
$update_array['last_polled_timetaken'] = $device_time;
|
|
||||||
|
|
||||||
echo 'Enabling graphs: ';
|
|
||||||
DeviceGraph::deleted(function ($graph) {
|
|
||||||
echo '-';
|
|
||||||
});
|
|
||||||
DeviceGraph::created(function ($graph) {
|
|
||||||
echo '+';
|
|
||||||
});
|
|
||||||
|
|
||||||
$os->persistGraphs();
|
|
||||||
echo PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
$updated = false;
|
|
||||||
if (! empty($update_array)) {
|
|
||||||
$updated = dbUpdate($update_array, 'devices', '`device_id` = ?', [$device['device_id']]);
|
|
||||||
}
|
|
||||||
if ($updated) {
|
|
||||||
d_echo('Updating ' . $device['hostname'] . PHP_EOL);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "\nPolled in $device_time seconds\n";
|
|
||||||
|
|
||||||
// check if the poll took to long and log an event
|
|
||||||
if ($device_time > Config::get('rrd.step')) {
|
|
||||||
log_event('Polling took longer than ' . round(Config::get('rrd.step') / 60, 2) .
|
|
||||||
' minutes! This will cause gaps in graphs.', $device, 'system', 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($storage_cache);
|
|
||||||
// Clear cache of hrStorage ** MAYBE FIXME? **
|
|
||||||
unset($cache);
|
|
||||||
// Clear cache (unify all things here?)
|
|
||||||
|
|
||||||
return true; // device was polled
|
|
||||||
}
|
|
||||||
|
|
||||||
return false; // device not polled
|
|
||||||
}//end poll_device()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the application status and output in the database.
|
* Update the application status and output in the database.
|
||||||
*
|
*
|
||||||
|
132
poller.php
132
poller.php
@ -23,69 +23,18 @@
|
|||||||
* Modified 4/17/19
|
* Modified 4/17/19
|
||||||
* @author Heath Barnhart <hbarnhart@kanren.net>
|
* @author Heath Barnhart <hbarnhart@kanren.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use App\Action;
|
|
||||||
use App\Actions\Device\UpdateDeviceGroupsAction;
|
|
||||||
use LibreNMS\Alert\AlertRules;
|
|
||||||
use LibreNMS\Config;
|
|
||||||
use LibreNMS\Data\Store\Datastore;
|
|
||||||
use LibreNMS\Util\Debug;
|
|
||||||
|
|
||||||
$init_modules = ['polling', 'alerts', 'laravel'];
|
$init_modules = ['polling', 'alerts', 'laravel'];
|
||||||
require __DIR__ . '/includes/init.php';
|
require __DIR__ . '/includes/init.php';
|
||||||
|
|
||||||
$poller_start = microtime(true);
|
$options = getopt('h:rfpdvm:q');
|
||||||
Log::setDefaultDriver('console');
|
|
||||||
echo Config::get('project_name') . " Poller\n";
|
|
||||||
|
|
||||||
$options = getopt('h:m:i:n:r::d::v::a::f::q');
|
c_echo('%RWarning: poller.php is deprecated!%n Use %9lnms device:poll%n instead.' . PHP_EOL . PHP_EOL);
|
||||||
|
|
||||||
if (isset($options['h'])) {
|
if (empty($options['h'])) {
|
||||||
if ($options['h'] == 'odd') {
|
|
||||||
$options['n'] = '1';
|
|
||||||
$options['i'] = '2';
|
|
||||||
} elseif ($options['h'] == 'even') {
|
|
||||||
$options['n'] = '0';
|
|
||||||
$options['i'] = '2';
|
|
||||||
} elseif ($options['h'] == 'all') {
|
|
||||||
$where = ' ';
|
|
||||||
$doing = 'all';
|
|
||||||
} elseif ($options['h']) {
|
|
||||||
if (is_numeric($options['h'])) {
|
|
||||||
$where = 'AND `device_id` = ' . $options['h'];
|
|
||||||
$doing = $options['h'];
|
|
||||||
} else {
|
|
||||||
if (preg_match('/\*/', $options['h'])) {
|
|
||||||
$where = "AND `hostname` LIKE '" . str_replace('*', '%', $options['h']) . "'";
|
|
||||||
} else {
|
|
||||||
$where = "AND `hostname` = '" . $options['h'] . "'";
|
|
||||||
}
|
|
||||||
$doing = $options['h'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($options['i']) && $options['i'] && isset($options['n'])) {
|
|
||||||
$where = true;
|
|
||||||
// FIXME
|
|
||||||
$query = 'SELECT * FROM (SELECT @rownum :=0) r,
|
|
||||||
(
|
|
||||||
SELECT @rownum := @rownum +1 AS rownum, `devices`.*
|
|
||||||
FROM `devices`
|
|
||||||
WHERE `disabled` = 0
|
|
||||||
ORDER BY `device_id` ASC
|
|
||||||
) temp
|
|
||||||
WHERE MOD(temp.rownum, ' . $options['i'] . ') = ' . $options['n'] . ';';
|
|
||||||
$doing = $options['n'] . '/' . $options['i'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($where)) {
|
|
||||||
echo "-h <device id> | <device hostname wildcard> Poll single device\n";
|
echo "-h <device id> | <device hostname wildcard> Poll single device\n";
|
||||||
echo "-h odd Poll odd numbered devices (same as -i 2 -n 0)\n";
|
echo "-h odd Poll odd numbered devices\n";
|
||||||
echo "-h even Poll even numbered devices (same as -i 2 -n 1)\n";
|
echo "-h even Poll even numbered devices\n";
|
||||||
echo "-h all Poll all devices\n\n";
|
echo "-h all Poll all devices\n\n";
|
||||||
echo "-i <instances> -n <number> Poll as instance <number> of <instances>\n";
|
|
||||||
echo " Instances start at 0. 0-3 for -n 4\n\n";
|
|
||||||
echo "Debugging and testing options:\n";
|
echo "Debugging and testing options:\n";
|
||||||
echo "-r Do not create or update RRDs\n";
|
echo "-r Do not create or update RRDs\n";
|
||||||
echo "-f Do not insert data into InfluxDB\n";
|
echo "-f Do not insert data into InfluxDB\n";
|
||||||
@ -93,74 +42,29 @@ if (empty($where)) {
|
|||||||
echo "-d Enable debugging output\n";
|
echo "-d Enable debugging output\n";
|
||||||
echo "-v Enable verbose debugging output\n";
|
echo "-v Enable verbose debugging output\n";
|
||||||
echo "-m Specify module(s) to be run. Comma separate modules, submodules may be added with /\n";
|
echo "-m Specify module(s) to be run. Comma separate modules, submodules may be added with /\n";
|
||||||
|
echo "-q Quiet, minimal output /\n";
|
||||||
echo "\n";
|
echo "\n";
|
||||||
echo "No polling type specified!\n";
|
echo "No polling type specified!\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Debug::set(isset($options['d']), false) || isset($options['v'])) {
|
$arguments = [
|
||||||
echo \LibreNMS\Util\Version::get()->header();
|
'device spec' => $options['h'],
|
||||||
|
'--verbose' => isset($options['v']) ? 3 : (isset($options['d']) ? 2 : 1),
|
||||||
|
];
|
||||||
|
|
||||||
echo "DEBUG!\n";
|
if (isset($options['m'])) {
|
||||||
if (isset($options['v'])) {
|
$arguments['--modules'] = $options['m'];
|
||||||
Debug::setVerbose();
|
|
||||||
}
|
|
||||||
\LibreNMS\Util\OS::updateCache(true); // Force update of OS Cache
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we've specified modules with -m, use them
|
if (isset($options['q'])) {
|
||||||
$module_override = parse_modules('poller', $options);
|
$arguments['--quiet'] = true;
|
||||||
|
|
||||||
$datastore = Datastore::init($options);
|
|
||||||
|
|
||||||
echo "Starting polling run:\n\n";
|
|
||||||
$polled_devices = 0;
|
|
||||||
$unreachable_devices = 0;
|
|
||||||
if (! isset($query)) {
|
|
||||||
$query = "SELECT * FROM `devices` WHERE `disabled` = 0 $where ORDER BY `device_id` ASC";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (dbFetch($query) as $device) {
|
if (isset($options['r']) || isset($options['f']) || isset($options['p'])) {
|
||||||
DeviceCache::setPrimary($device['device_id']);
|
$arguments['--no-data'] = true;
|
||||||
|
|
||||||
if (! poll_device($device, $module_override)) {
|
|
||||||
$unreachable_devices++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update device_groups
|
|
||||||
echo "### Start Device Groups ###\n";
|
|
||||||
$dg_start = microtime(true);
|
|
||||||
$group_changes = Action::execute(UpdateDeviceGroupsAction::class);
|
|
||||||
d_echo('Groups Added: ' . implode(',', $group_changes['attached']) . PHP_EOL);
|
|
||||||
d_echo('Groups Removed: ' . implode(',', $group_changes['detached']) . PHP_EOL);
|
|
||||||
echo '### End Device Groups, runtime: ' . round(microtime(true) - $dg_start, 4) . "s ### \n\n";
|
|
||||||
|
|
||||||
echo "#### Start Alerts ####\n";
|
|
||||||
$rules = new AlertRules();
|
|
||||||
$rules->runRules($device['device_id']);
|
|
||||||
echo "#### End Alerts ####\r\n";
|
|
||||||
$polled_devices++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$poller_end = microtime(true);
|
$return = Artisan::call('device:poll', $arguments);
|
||||||
$poller_run = ($poller_end - $poller_start);
|
|
||||||
$poller_time = substr($poller_run, 0, 5);
|
|
||||||
|
|
||||||
$string = $argv[0] . " $doing " . date(Config::get('dateformat.compact')) . " - $polled_devices devices polled in $poller_time secs";
|
exit($return);
|
||||||
d_echo("$string\n");
|
|
||||||
|
|
||||||
if (! isset($options['q'])) {
|
|
||||||
echo PHP_EOL;
|
|
||||||
app(\App\Polling\Measure\MeasurementManager::class)->printStats();
|
|
||||||
}
|
|
||||||
|
|
||||||
logfile($string);
|
|
||||||
Datastore::terminate();
|
|
||||||
// Remove this for testing
|
|
||||||
// print_r(get_defined_vars());
|
|
||||||
|
|
||||||
if ($polled_devices === $unreachable_devices) {
|
|
||||||
exit(6);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
|
@ -86,28 +86,6 @@ Artisan::command('poller:discovery
|
|||||||
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
||||||
})->purpose(__('Discover information about existing devices, defines what will be polled'));
|
})->purpose(__('Discover information about existing devices, defines what will be polled'));
|
||||||
|
|
||||||
Artisan::command('poller:poll
|
|
||||||
{device spec : ' . __('Device spec to poll: device_id, hostname, wildcard, odd, even, all') . '}
|
|
||||||
{--m|modules= : ' . __('Specify single module to be run. Comma separate modules, submodules may be added with /') . '}
|
|
||||||
{--x|no-data : ' . __('Do not update datastores (RRD, InfluxDB, etc)') . '}
|
|
||||||
', function () {
|
|
||||||
$command = [base_path('poller.php'), '-h', $this->argument('device spec')];
|
|
||||||
if ($this->option('no-data')) {
|
|
||||||
array_push($command, '-r', '-f', '-p');
|
|
||||||
}
|
|
||||||
if ($this->option('modules')) {
|
|
||||||
$command[] = '-m';
|
|
||||||
$command[] = $this->option('modules');
|
|
||||||
}
|
|
||||||
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
|
|
||||||
$command[] = '-d';
|
|
||||||
if ($verbosity >= 256) {
|
|
||||||
$command[] = '-v';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
|
||||||
})->purpose(__('Poll data from devices as defined by discovery'));
|
|
||||||
|
|
||||||
Artisan::command('poller:alerts', function () {
|
Artisan::command('poller:alerts', function () {
|
||||||
$command = [base_path('alerts.php')];
|
$command = [base_path('alerts.php')];
|
||||||
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
|
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
|
||||||
|
Loading…
Reference in New Issue
Block a user