mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add support for setting port association mode when adding a host.
This adds a '-p' switch to addhost.php and a select box to the WebUI to set the port association mode for newly added devices. Signed-off-by: Maximilian Wilhelm <max@rfc2324.org>
This commit is contained in:
42
addhost.php
42
addhost.php
@@ -19,7 +19,7 @@ require 'config.php';
|
|||||||
require 'includes/definitions.inc.php';
|
require 'includes/definitions.inc.php';
|
||||||
require 'includes/functions.php';
|
require 'includes/functions.php';
|
||||||
|
|
||||||
$options = getopt('g:f::');
|
$options = getopt('g:p:f::');
|
||||||
|
|
||||||
if (isset($options['g']) && $options['g'] >= 0) {
|
if (isset($options['g']) && $options['g'] >= 0) {
|
||||||
$cmd = array_shift($argv);
|
$cmd = array_shift($argv);
|
||||||
@@ -39,6 +39,22 @@ if (isset($options['f']) && $options['f'] == 0) {
|
|||||||
$force_add = 1;
|
$force_add = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$port_assoc_mode = $config['default_port_association_mode'];
|
||||||
|
$valid_assoc_modes = get_port_assoc_modes ();
|
||||||
|
if (isset ($options['p'])) {
|
||||||
|
$port_assoc_mode = $options['p'];
|
||||||
|
if (! in_array ($port_assoc_mode, $valid_assoc_modes)) {
|
||||||
|
echo "Invalid port association mode '" . $port_assoc_mode . "'\n";
|
||||||
|
echo 'Valid modes: ' . join (', ', $valid_assoc_modes) . "\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cmd = array_shift($argv);
|
||||||
|
array_shift($argv);
|
||||||
|
array_shift($argv);
|
||||||
|
array_unshift($argv, $cmd);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($argv[1])) {
|
if (!empty($argv[1])) {
|
||||||
$host = strtolower($argv[1]);
|
$host = strtolower($argv[1]);
|
||||||
$community = $argv[2];
|
$community = $argv[2];
|
||||||
@@ -82,7 +98,7 @@ if (!empty($argv[1])) {
|
|||||||
array_push($config['snmp']['v3'], $v3);
|
array_push($config['snmp']['v3'], $v3);
|
||||||
}
|
}
|
||||||
|
|
||||||
$device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add);
|
$device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add, $port_assoc_mode);
|
||||||
}
|
}
|
||||||
else if ($seclevel === 'anp' or $seclevel === 'authNoPriv') {
|
else if ($seclevel === 'anp' or $seclevel === 'authNoPriv') {
|
||||||
$v3['authlevel'] = 'authNoPriv';
|
$v3['authlevel'] = 'authNoPriv';
|
||||||
@@ -108,7 +124,7 @@ if (!empty($argv[1])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
array_push($config['snmp']['v3'], $v3);
|
array_push($config['snmp']['v3'], $v3);
|
||||||
$device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add);
|
$device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add, $port_assoc_mode);
|
||||||
}
|
}
|
||||||
else if ($seclevel === 'ap' or $seclevel === 'authPriv') {
|
else if ($seclevel === 'ap' or $seclevel === 'authPriv') {
|
||||||
$v3['authlevel'] = 'authPriv';
|
$v3['authlevel'] = 'authPriv';
|
||||||
@@ -138,7 +154,7 @@ if (!empty($argv[1])) {
|
|||||||
}//end while
|
}//end while
|
||||||
|
|
||||||
array_push($config['snmp']['v3'], $v3);
|
array_push($config['snmp']['v3'], $v3);
|
||||||
$device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add);
|
$device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add, $port_assoc_mode);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Error or do nothing ?
|
// Error or do nothing ?
|
||||||
@@ -164,7 +180,7 @@ if (!empty($argv[1])) {
|
|||||||
$config['snmp']['community'] = array($community);
|
$config['snmp']['community'] = array($community);
|
||||||
}
|
}
|
||||||
|
|
||||||
$device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add);
|
$device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add, $port_assoc_mode);
|
||||||
}//end if
|
}//end if
|
||||||
|
|
||||||
if ($snmpver) {
|
if ($snmpver) {
|
||||||
@@ -180,7 +196,7 @@ if (!empty($argv[1])) {
|
|||||||
|
|
||||||
while (!$device_id && count($snmpversions)) {
|
while (!$device_id && count($snmpversions)) {
|
||||||
$snmpver = array_shift($snmpversions);
|
$snmpver = array_shift($snmpversions);
|
||||||
$device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add);
|
$device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add, $port_assoc_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($device_id) {
|
if ($device_id) {
|
||||||
@@ -193,14 +209,18 @@ if (!empty($argv[1])) {
|
|||||||
print $console_color->convert(
|
print $console_color->convert(
|
||||||
"\n".$config['project_name_version'].' Add Host Tool
|
"\n".$config['project_name_version'].' Add Host Tool
|
||||||
|
|
||||||
Usage (SNMPv1/2c): ./addhost.php [-g <poller group>] [-f] <%Whostname%n> [community] [v1|v2c] [port] ['.implode('|', $config['snmp']['transports']).']
|
Usage (SNMPv1/2c): ./addhost.php [-g <poller group>] [-f] [-p <port assoc mode>] <%Whostname%n> [community] [v1|v2c] [port] ['.implode('|', $config['snmp']['transports']).']
|
||||||
Usage (SNMPv3) : Config Defaults : ./addhost.php [-g <poller group>] [-f]<%Whostname%n> any v3 [user] [port] ['.implode('|', $config['snmp']['transports']).']
|
Usage (SNMPv3) : Config Defaults : ./addhost.php [-g <poller group>] [-f] [-p <port assoc mode>] <%Whostname%n> any v3 [user] [port] ['.implode('|', $config['snmp']['transports']).']
|
||||||
No Auth, No Priv : ./addhost.php [-g <poller group>] [-f]<%Whostname%n> nanp v3 [user] [port] ['.implode('|', $config['snmp']['transports']).']
|
No Auth, No Priv : ./addhost.php [-g <poller group>] [-f] [-p <port assoc mode>] <%Whostname%n> nanp v3 [user] [port] ['.implode('|', $config['snmp']['transports']).']
|
||||||
Auth, No Priv : ./addhost.php [-g <poller group>] [-f]<%Whostname%n> anp v3 <user> <password> [md5|sha] [port] ['.implode('|', $config['snmp']['transports']).']
|
Auth, No Priv : ./addhost.php [-g <poller group>] [-f] [-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]<%Whostname%n> ap v3 <user> <password> <enckey> [md5|sha] [aes|dsa] [port] ['.implode('|', $config['snmp']['transports']).']
|
Auth, Priv : ./addhost.php [-g <poller group>] [-f] [-p <port assoc mode>] <%Whostname%n> ap v3 <user> <password> <enckey> [md5|sha] [aes|dsa] [port] ['.implode('|', $config['snmp']['transports']).']
|
||||||
|
|
||||||
-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
|
-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.
|
-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'] . '\'
|
||||||
|
Valid port assoc modes are: ' . join (', ', $valid_assoc_modes) . '
|
||||||
|
|
||||||
%rRemember to run discovery for the host afterwards.%n
|
%rRemember to run discovery for the host afterwards.%n
|
||||||
'
|
'
|
||||||
|
@@ -65,7 +65,8 @@ if ($_POST['hostname']) {
|
|||||||
$force_add = 0;
|
$force_add = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = addHost($hostname, $snmpver, $port, $transport, 0, $poller_group, $force_add);
|
$port_assoc_mode = $_POST['port_assoc_mode'];
|
||||||
|
$result = addHost($hostname, $snmpver, $port, $transport, 0, $poller_group, $force_add, $port_assoc_mode);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
print_message("Device added ($result)");
|
print_message("Device added ($result)");
|
||||||
}
|
}
|
||||||
@@ -120,6 +121,24 @@ foreach ($config['snmp']['transports'] as $transport) {
|
|||||||
|
|
||||||
echo '>'.$transport.'</option>';
|
echo '>'.$transport.'</option>';
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="port_association_mode" class="col-sm-3 control-label">Port Association Mode</label>
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<select name="port_assoc_mode" id="port_assoc_mode" class="form-control input-sm">
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
foreach (get_port_assoc_modes() as $mode) {
|
||||||
|
$selected = "";
|
||||||
|
if ($mode == $config['default_port_association_mode'])
|
||||||
|
$selected = "selected";
|
||||||
|
|
||||||
|
echo " <option value=\"$mode\" $selected>$mode</option>\n";
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user