2018-05-09 13:05:17 +00:00
|
|
|
<?php
|
|
|
|
|
2021-10-02 23:04:59 +00:00
|
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
use Symfony\Component\Process\Process;
|
|
|
|
|
2018-05-09 13:05:17 +00:00
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Console Routes
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
| This file is where you may define all of your Closure based console
|
|
|
|
| commands. Each Closure is bound to a command instance allowing a
|
|
|
|
| simple approach to interacting with each command's IO methods.
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2020-10-03 16:27:59 +00:00
|
|
|
Artisan::command('device:rename
|
2019-01-24 05:52:08 +00:00
|
|
|
{old hostname : ' . __('The existing hostname, IP, or device id') . '}
|
|
|
|
{new hostname : ' . __('The new hostname or IP') . '}
|
|
|
|
', function () {
|
|
|
|
/** @var \Illuminate\Console\Command $this */
|
|
|
|
(new Process([
|
|
|
|
base_path('renamehost.php'),
|
|
|
|
$this->argument('old hostname'),
|
|
|
|
$this->argument('new hostname'),
|
2021-07-30 17:20:09 +00:00
|
|
|
]))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
2020-11-03 16:18:31 +00:00
|
|
|
})->purpose(__('Rename a device, this can be used to change the hostname or IP of a device'));
|
2019-01-24 05:52:08 +00:00
|
|
|
|
|
|
|
Artisan::command('device:remove
|
|
|
|
{device spec : ' . __('Hostname, IP, or device id to remove') . '}
|
|
|
|
', function () {
|
|
|
|
/** @var \Illuminate\Console\Command $this */
|
|
|
|
(new Process([
|
|
|
|
base_path('delhost.php'),
|
|
|
|
$this->argument('device spec'),
|
2021-07-30 17:20:09 +00:00
|
|
|
]))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
2020-11-03 16:18:31 +00:00
|
|
|
})->purpose('Remove a device');
|
2019-01-24 05:52:08 +00:00
|
|
|
|
|
|
|
Artisan::command('update', function () {
|
2021-07-30 17:20:09 +00:00
|
|
|
(new Process([base_path('daily.sh')]))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
2020-11-03 16:18:31 +00:00
|
|
|
})->purpose(__('Update LibreNMS and run maintenance routines'));
|
2019-01-24 05:52:08 +00:00
|
|
|
|
2020-10-03 16:27:59 +00:00
|
|
|
Artisan::command('poller:ping
|
2019-01-24 05:52:08 +00:00
|
|
|
{groups?* : ' . __('Optional List of distributed poller groups to poll') . '}
|
|
|
|
', function () {
|
2019-01-09 03:42:56 +00:00
|
|
|
// PingCheck::dispatch(new PingCheck($this->argument('groups')));
|
2019-01-24 05:52:08 +00:00
|
|
|
$command = [base_path('ping.php')];
|
|
|
|
if ($this->argument('groups')) {
|
|
|
|
$command[] = '-g';
|
|
|
|
$command[] = implode(',', $this->argument('groups'));
|
|
|
|
}
|
|
|
|
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
|
|
|
|
$command[] = '-d';
|
|
|
|
if ($verbosity >= 256) {
|
|
|
|
$command[] = '-v';
|
|
|
|
}
|
|
|
|
}
|
2021-07-30 17:20:09 +00:00
|
|
|
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
2020-11-03 16:18:31 +00:00
|
|
|
})->purpose(__('Check if devices are up or down via icmp'));
|
2019-01-24 05:52:08 +00:00
|
|
|
|
|
|
|
Artisan::command('poller:discovery
|
|
|
|
{device spec : ' . __('Device spec to discover: device_id, hostname, wildcard, odd, even, all, new') . '}
|
|
|
|
{--o|os= : ' . __('Only devices with the specified operating system') . '}
|
|
|
|
{--t|type= : ' . __('Only devices with the specified type') . '}
|
|
|
|
{--m|modules= : ' . __('Specify single module to be run. Comma separate modules, submodules may be added with /') . '}
|
|
|
|
', function () {
|
|
|
|
$command = [base_path('discovery.php'), '-h', $this->argument('device spec')];
|
|
|
|
if ($this->option('os')) {
|
|
|
|
$command[] = '-o';
|
|
|
|
$command[] = $this->option('os');
|
|
|
|
}
|
|
|
|
if ($this->option('type')) {
|
|
|
|
$command[] = '-t';
|
|
|
|
$command[] = $this->option('type');
|
|
|
|
}
|
|
|
|
if ($this->option('modules')) {
|
|
|
|
$command[] = '-m';
|
|
|
|
$command[] = $this->option('modules');
|
|
|
|
}
|
|
|
|
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
|
|
|
|
$command[] = '-d';
|
|
|
|
if ($verbosity >= 256) {
|
|
|
|
$command[] = '-v';
|
|
|
|
}
|
|
|
|
}
|
2021-07-30 17:20:09 +00:00
|
|
|
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
2020-11-03 16:18:31 +00:00
|
|
|
})->purpose(__('Discover information about existing devices, defines what will be polled'));
|
2019-01-24 05:52:08 +00:00
|
|
|
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
}
|
2021-07-30 17:20:09 +00:00
|
|
|
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
2020-11-03 16:18:31 +00:00
|
|
|
})->purpose(__('Poll data from devices as defined by discovery'));
|
2019-01-24 05:52:08 +00:00
|
|
|
|
|
|
|
Artisan::command('poller:alerts', function () {
|
|
|
|
$command = [base_path('alerts.php')];
|
|
|
|
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
|
|
|
|
$command[] = '-d';
|
|
|
|
if ($verbosity >= 256) {
|
|
|
|
$command[] = '-v';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-30 17:20:09 +00:00
|
|
|
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
2020-11-03 16:18:31 +00:00
|
|
|
})->purpose(__('Check for any pending alerts and deliver them via defined transports'));
|
2019-01-24 05:52:08 +00:00
|
|
|
|
|
|
|
Artisan::command('poller:billing
|
|
|
|
{bill id? : ' . __('The bill id to poll') . '}
|
|
|
|
', function () {
|
|
|
|
/** @var \Illuminate\Console\Command $this */
|
|
|
|
$command = [base_path('poll-billing.php')];
|
|
|
|
if ($this->argument('bill id')) {
|
|
|
|
$command[] = '-b';
|
|
|
|
$command[] = $this->argument('bill id');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
|
|
|
|
$command[] = '-d';
|
|
|
|
if ($verbosity >= 256) {
|
|
|
|
$command[] = '-v';
|
|
|
|
}
|
|
|
|
}
|
2021-07-30 17:20:09 +00:00
|
|
|
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
2020-11-03 16:18:31 +00:00
|
|
|
})->purpose(__('Collect billing data'));
|
2019-01-24 05:52:08 +00:00
|
|
|
|
|
|
|
Artisan::command('poller:services
|
|
|
|
{device spec : ' . __('Device spec to poll: device_id, hostname, wildcard, all') . '}
|
|
|
|
{--x|no-data : ' . __('Do not update datastores (RRD, InfluxDB, etc)') . '}
|
|
|
|
', function () {
|
|
|
|
/** @var \Illuminate\Console\Command $this */
|
|
|
|
$command = [base_path('check-services.php')];
|
|
|
|
if ($this->option('no-data')) {
|
|
|
|
array_push($command, '-r', '-f', '-p');
|
|
|
|
}
|
|
|
|
if ($this->argument('device spec') !== 'all') {
|
|
|
|
$command[] = '-h';
|
|
|
|
$command[] = $this->argument('device spec');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
|
|
|
|
$command[] = '-d';
|
|
|
|
if ($verbosity >= 256) {
|
|
|
|
$command[] = '-v';
|
|
|
|
}
|
|
|
|
}
|
2021-07-30 17:20:09 +00:00
|
|
|
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
2020-11-03 16:18:31 +00:00
|
|
|
})->purpose(__('Update LibreNMS and run maintenance routines'));
|
2019-01-24 05:52:08 +00:00
|
|
|
|
|
|
|
Artisan::command('poller:billing-calculate
|
|
|
|
{--c|clear-history : ' . __('Delete all billing history') . '}
|
|
|
|
', function () {
|
|
|
|
/** @var \Illuminate\Console\Command $this */
|
|
|
|
$command = [base_path('billing-calculate.php')];
|
|
|
|
if ($this->option('clear-history')) {
|
|
|
|
$command[] = '-r';
|
|
|
|
}
|
|
|
|
|
2021-07-30 17:20:09 +00:00
|
|
|
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
2020-11-03 16:18:31 +00:00
|
|
|
})->purpose(__('Run billing calculations'));
|
2019-01-24 05:52:08 +00:00
|
|
|
|
|
|
|
Artisan::command('scan
|
|
|
|
{network?* : ' . __('CIDR notation network(s) to scan, can be ommited if \'nets\' config is set') . '}
|
|
|
|
{--P|ping-only : ' . __('Add the device as a ping only device if it replies to ping but not SNMP') . '}
|
|
|
|
{--t|threads=32 : ' . __('How many IPs to scan at a time, more will increase the scan speed, but could overload your system') . '}
|
|
|
|
{--l|legend : ' . __('Print the legend') . '}
|
|
|
|
', function () {
|
|
|
|
/** @var \Illuminate\Console\Command $this */
|
|
|
|
$command = [base_path('snmp-scan.py')];
|
|
|
|
|
2021-08-12 00:01:52 +00:00
|
|
|
if (empty($this->argument('network')) && ! \LibreNMS\Config::has('nets')) {
|
2019-01-24 05:52:08 +00:00
|
|
|
$this->error(__('Network is required if \'nets\' is not set in the config'));
|
2020-09-21 12:54:51 +00:00
|
|
|
|
2019-01-24 05:52:08 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->option('ping-only')) {
|
|
|
|
$command[] = '-P';
|
|
|
|
}
|
|
|
|
|
|
|
|
$command[] = '-t';
|
|
|
|
$command[] = $this->option('threads');
|
|
|
|
|
|
|
|
if ($this->option('legend')) {
|
|
|
|
$command[] = '-l';
|
|
|
|
}
|
|
|
|
|
|
|
|
$verbosity = $this->getOutput()->getVerbosity();
|
|
|
|
if ($verbosity >= 64) {
|
|
|
|
$command[] = '-v';
|
|
|
|
if ($verbosity >= 128) {
|
|
|
|
$command[] = '-v';
|
|
|
|
if ($verbosity >= 256) {
|
|
|
|
$command[] = '-v';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$command = array_merge($command, $this->argument('network'));
|
|
|
|
|
2021-07-30 17:20:09 +00:00
|
|
|
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
|
2020-11-03 16:18:31 +00:00
|
|
|
})->purpose(__('Scan the network for hosts and try to add them to LibreNMS'));
|