mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
+28
-18
@@ -11,6 +11,7 @@
|
||||
* @copyright (C) 2006 - 2012 Adam Armstrong
|
||||
*/
|
||||
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Exceptions\HostUnreachableException;
|
||||
|
||||
$init_modules = array();
|
||||
@@ -24,8 +25,8 @@ if (isset($options['g']) && $options['g'] >= 0) {
|
||||
array_shift($argv);
|
||||
array_unshift($argv, $cmd);
|
||||
$poller_group = $options['g'];
|
||||
} elseif ($config['distributed_poller'] === true) {
|
||||
$poller_group = $config['distributed_poller_group'];
|
||||
} elseif (Config::get('distributed_poller') === true) {
|
||||
$poller_group = Config::get('distributed_poller_group');
|
||||
} else {
|
||||
$poller_group = 0;
|
||||
}
|
||||
@@ -39,7 +40,7 @@ if (isset($options['f']) && $options['f'] == 0) {
|
||||
$force_add = false;
|
||||
}
|
||||
|
||||
$port_assoc_mode = $config['default_port_association_mode'];
|
||||
$port_assoc_mode = Config::get('default_port_association_mode');
|
||||
$valid_assoc_modes = get_port_assoc_modes();
|
||||
if (isset($options['p'])) {
|
||||
$port_assoc_mode = $options['p'];
|
||||
@@ -67,6 +68,7 @@ if (isset($options['b'])) {
|
||||
array_unshift($argv, $cmd);
|
||||
}
|
||||
|
||||
$transports_regex = implode('|', Config::get('snmp.transports'));
|
||||
if (!empty($argv[1])) {
|
||||
$host = strtolower($argv[1]);
|
||||
$community = $argv[2];
|
||||
@@ -111,7 +113,7 @@ if (!empty($argv[1])) {
|
||||
// parse all remaining args
|
||||
if (is_numeric($arg)) {
|
||||
$port = $arg;
|
||||
} elseif (preg_match('/^('.implode('|', $config['snmp']['transports']).')$/', $arg)) {
|
||||
} elseif (preg_match('/^(' . $transports_regex . ')$/', $arg)) {
|
||||
$transport = $arg;
|
||||
} else {
|
||||
// should add a sanity check of chars allowed in user
|
||||
@@ -120,7 +122,9 @@ if (!empty($argv[1])) {
|
||||
}
|
||||
|
||||
if ($seclevel === 'nanp') {
|
||||
array_unshift($config['snmp']['v3'], $v3);
|
||||
$v3_config = Config::get('snmp.v3');
|
||||
array_unshift($v3_config, $v3);
|
||||
Config::set('snmp.v3', $v3_config);
|
||||
}
|
||||
} elseif ($seclevel === 'anp' or $seclevel === 'authNoPriv') {
|
||||
$v3['authlevel'] = 'authNoPriv';
|
||||
@@ -132,7 +136,7 @@ if (!empty($argv[1])) {
|
||||
// parse all remaining args
|
||||
if (is_numeric($arg)) {
|
||||
$port = $arg;
|
||||
} elseif (preg_match('/^('.implode('|', $config['snmp']['transports']).')$/i', $arg)) {
|
||||
} elseif (preg_match('/^(' . $transports_regex . ')$/i', $arg)) {
|
||||
$transport = $arg;
|
||||
} elseif (preg_match('/^(sha|md5)$/i', $arg)) {
|
||||
$v3['authalgo'] = $arg;
|
||||
@@ -142,7 +146,9 @@ if (!empty($argv[1])) {
|
||||
}
|
||||
}
|
||||
|
||||
array_unshift($config['snmp']['v3'], $v3);
|
||||
$v3_config = Config::get('snmp.v3');
|
||||
array_unshift($v3_config, $v3);
|
||||
Config::set('snmp.v3', $v3_config);
|
||||
} elseif ($seclevel === 'ap' or $seclevel === 'authPriv') {
|
||||
$v3['authlevel'] = 'authPriv';
|
||||
$v3args = array_slice($argv, 4);
|
||||
@@ -154,7 +160,7 @@ if (!empty($argv[1])) {
|
||||
// parse all remaining args
|
||||
if (is_numeric($arg)) {
|
||||
$port = $arg;
|
||||
} elseif (preg_match('/^('.implode('|', $config['snmp']['transports']).')$/i', $arg)) {
|
||||
} elseif (preg_match('/^(' . $transports_regex . ')$/i', $arg)) {
|
||||
$transport = $arg;
|
||||
} elseif (preg_match('/^(sha|md5)$/i', $arg)) {
|
||||
$v3['authalgo'] = $arg;
|
||||
@@ -166,7 +172,9 @@ if (!empty($argv[1])) {
|
||||
}
|
||||
}//end while
|
||||
|
||||
array_unshift($config['snmp']['v3'], $v3);
|
||||
$v3_config = Config::get('snmp.v3');
|
||||
array_unshift($v3_config, $v3);
|
||||
Config::set('snmp.v3', $v3_config);
|
||||
}
|
||||
} else {
|
||||
// v2c or v1
|
||||
@@ -176,7 +184,7 @@ if (!empty($argv[1])) {
|
||||
// parse all remaining args
|
||||
if (is_numeric($arg)) {
|
||||
$port = $arg;
|
||||
} elseif (preg_match('/('.implode('|', $config['snmp']['transports']).')/i', $arg)) {
|
||||
} elseif (preg_match('/(' . $transports_regex . ')/i', $arg)) {
|
||||
$transport = $arg;
|
||||
} elseif (preg_match('/^(v1|v2c)$/i', $arg)) {
|
||||
$snmpver = $arg;
|
||||
@@ -184,7 +192,9 @@ if (!empty($argv[1])) {
|
||||
}
|
||||
|
||||
if ($community) {
|
||||
array_unshift($config['snmp']['community'], $community);
|
||||
$comm_config = Config::get('snmp.community');
|
||||
array_unshift($comm_config, $community);
|
||||
Config::set('snmp.community', $comm_config);
|
||||
}
|
||||
}//end if
|
||||
|
||||
@@ -205,21 +215,21 @@ if (!empty($argv[1])) {
|
||||
}
|
||||
} else {
|
||||
c_echo(
|
||||
"\n".$config['project_name_version'].' Add Host Tool
|
||||
"\n" . Config::get('project_name_version') . ' Add Host Tool
|
||||
|
||||
Usage (SNMPv1/2c) : ./addhost.php [-g <poller group>] [-f] [-b] [-p <port assoc mode>] <%Whostname%n> [community] [v1|v2c] [port] ['.implode('|', $config['snmp']['transports']).']
|
||||
Usage (SNMPv1/2c) : ./addhost.php [-g <poller group>] [-f] [-b] [-p <port assoc mode>] <%Whostname%n> [community] [v1|v2c] [port] [' . $transports_regex . ']
|
||||
Usage (SNMPv3) :
|
||||
Config Defaults : ./addhost.php [-g <poller group>] [-f] [-b] [-p <port assoc mode>] <%Whostname%n> any v3 [user] [port] ['.implode('|', $config['snmp']['transports']).']
|
||||
No Auth, No Priv : ./addhost.php [-g <poller group>] [-f] [-b] [-p <port assoc mode>] <%Whostname%n> nanp v3 [user] [port] ['.implode('|', $config['snmp']['transports']).']
|
||||
Auth, No Priv : ./addhost.php [-g <poller group>] [-f] [-b] [-p <port assoc mode>] <%Whostname%n> anp v3 <user> <password> [md5|sha] [port] ['.implode('|', $config['snmp']['transports']).']
|
||||
Auth, Priv : ./addhost.php [-g <poller group>] [-f] [-b] [-p <port assoc mode>] <%Whostname%n> ap v3 <user> <password> <enckey> [md5|sha] [aes|dsa] [port] ['.implode('|', $config['snmp']['transports']).']
|
||||
Config Defaults : ./addhost.php [-g <poller group>] [-f] [-b] [-p <port assoc mode>] <%Whostname%n> any v3 [user] [port] [' . $transports_regex . ']
|
||||
No Auth, No Priv : ./addhost.php [-g <poller group>] [-f] [-b] [-p <port assoc mode>] <%Whostname%n> nanp v3 [user] [port] [' . $transports_regex . ']
|
||||
Auth, No Priv : ./addhost.php [-g <poller group>] [-f] [-b] [-p <port assoc mode>] <%Whostname%n> anp v3 <user> <password> [md5|sha] [port] [' . $transports_regex . ']
|
||||
Auth, Priv : ./addhost.php [-g <poller group>] [-f] [-b] [-p <port assoc mode>] <%Whostname%n> ap v3 <user> <password> <enckey> [md5|sha] [aes|dsa] [port] [' . $transports_regex . ']
|
||||
Usage (ICMP only) : ./addhost.php [-g <poller group>] [-f] -P <%Whostname%n> [os] [hardware]
|
||||
|
||||
-g <poller group> allows you to add a device to be pinned to a specific poller when using distributed polling. X can be any number associated with a poller group
|
||||
-f forces the device to be added by skipping the icmp and snmp check against the host.
|
||||
-p <port assoc mode> allow you to set a port association mode for this device. By default ports are associated by \'ifIndex\'.
|
||||
For Linux/Unix based devices \'ifName\' or \'ifDescr\' might be useful for a stable iface mapping.
|
||||
The default for this installation is \'' . $config['default_port_association_mode'] . '\'
|
||||
The default for this installation is \'' . Config::get('default_port_association_mode') . '\'
|
||||
Valid port assoc modes are: ' . join(', ', $valid_assoc_modes) . '
|
||||
-b Add the host with SNMP if it replies to it, otherwise only ICMP.
|
||||
-P Add the host with only ICMP, no SNMP or OS discovery.
|
||||
|
||||
Reference in New Issue
Block a user