diff --git a/addhost.php b/addhost.php index 2280c54e32..381c602daf 100755 --- a/addhost.php +++ b/addhost.php @@ -19,7 +19,7 @@ require 'config.php'; require 'includes/definitions.inc.php'; require 'includes/functions.php'; -$options = getopt('g:f::'); +$options = getopt('g:p:f::'); if (isset($options['g']) && $options['g'] >= 0) { $cmd = array_shift($argv); @@ -39,6 +39,22 @@ if (isset($options['f']) && $options['f'] == 0) { $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])) { $host = strtolower($argv[1]); $community = $argv[2]; @@ -82,7 +98,7 @@ if (!empty($argv[1])) { 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') { $v3['authlevel'] = 'authNoPriv'; @@ -108,7 +124,7 @@ if (!empty($argv[1])) { } 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') { $v3['authlevel'] = 'authPriv'; @@ -138,7 +154,7 @@ if (!empty($argv[1])) { }//end while 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 { // Error or do nothing ? @@ -164,7 +180,7 @@ if (!empty($argv[1])) { $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 if ($snmpver) { @@ -180,7 +196,7 @@ if (!empty($argv[1])) { while (!$device_id && count($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) { @@ -193,14 +209,18 @@ if (!empty($argv[1])) { print $console_color->convert( "\n".$config['project_name_version'].' Add Host Tool - Usage (SNMPv1/2c): ./addhost.php [-g ] [-f] <%Whostname%n> [community] [v1|v2c] [port] ['.implode('|', $config['snmp']['transports']).'] - Usage (SNMPv3) : Config Defaults : ./addhost.php [-g ] [-f]<%Whostname%n> any v3 [user] [port] ['.implode('|', $config['snmp']['transports']).'] - No Auth, No Priv : ./addhost.php [-g ] [-f]<%Whostname%n> nanp v3 [user] [port] ['.implode('|', $config['snmp']['transports']).'] - Auth, No Priv : ./addhost.php [-g ] [-f]<%Whostname%n> anp v3 [md5|sha] [port] ['.implode('|', $config['snmp']['transports']).'] - Auth, Priv : ./addhost.php [-g ] [-f]<%Whostname%n> ap v3 [md5|sha] [aes|dsa] [port] ['.implode('|', $config['snmp']['transports']).'] + Usage (SNMPv1/2c): ./addhost.php [-g ] [-f] [-p ] <%Whostname%n> [community] [v1|v2c] [port] ['.implode('|', $config['snmp']['transports']).'] + Usage (SNMPv3) : Config Defaults : ./addhost.php [-g ] [-f] [-p ] <%Whostname%n> any v3 [user] [port] ['.implode('|', $config['snmp']['transports']).'] + No Auth, No Priv : ./addhost.php [-g ] [-f] [-p ] <%Whostname%n> nanp v3 [user] [port] ['.implode('|', $config['snmp']['transports']).'] + Auth, No Priv : ./addhost.php [-g ] [-f] [-p ] <%Whostname%n> anp v3 [md5|sha] [port] ['.implode('|', $config['snmp']['transports']).'] + Auth, Priv : ./addhost.php [-g ] [-f] [-p ] <%Whostname%n> ap v3 [md5|sha] [aes|dsa] [port] ['.implode('|', $config['snmp']['transports']).'] -g 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 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 ' diff --git a/html/pages/addhost.inc.php b/html/pages/addhost.inc.php index 2844982d79..fdbf9b0e32 100644 --- a/html/pages/addhost.inc.php +++ b/html/pages/addhost.inc.php @@ -65,7 +65,8 @@ if ($_POST['hostname']) { $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) { print_message("Device added ($result)"); } @@ -120,6 +121,24 @@ foreach ($config['snmp']['transports'] as $transport) { echo '>'.$transport.''; } +?> + + + +
+ +
+