mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #4013 from murrant/fix-4001
Fix addHost force_add logic
This commit is contained in:
@@ -37,9 +37,9 @@ if (isset($options['f']) && $options['f'] == 0) {
|
|||||||
$cmd = array_shift($argv);
|
$cmd = array_shift($argv);
|
||||||
array_shift($argv);
|
array_shift($argv);
|
||||||
array_unshift($argv, $cmd);
|
array_unshift($argv, $cmd);
|
||||||
$force_add = 1;
|
$force_add = true;
|
||||||
} else {
|
} else {
|
||||||
$force_add = 0;
|
$force_add = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$port_assoc_mode = $config['default_port_association_mode'];
|
$port_assoc_mode = $config['default_port_association_mode'];
|
||||||
|
|||||||
@@ -57,13 +57,7 @@ if ($_POST['hostname']) {
|
|||||||
print_error('Unsupported SNMP Version. There was a dropdown menu, how did you reach this error ?');
|
print_error('Unsupported SNMP Version. There was a dropdown menu, how did you reach this error ?');
|
||||||
}//end if
|
}//end if
|
||||||
$poller_group = $_POST['poller_group'];
|
$poller_group = $_POST['poller_group'];
|
||||||
$force_add = $_POST['force_add'];
|
$force_add = ($_POST['force_add'] == 'on');
|
||||||
if ($force_add == 'on') {
|
|
||||||
$force_add = 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$force_add = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$port_assoc_mode = $_POST['port_assoc_mode'];
|
$port_assoc_mode = $_POST['port_assoc_mode'];
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ function delete_device($id) {
|
|||||||
* @param string $port the port to connect to for snmp
|
* @param string $port the port to connect to for snmp
|
||||||
* @param string $transport udp or tcp
|
* @param string $transport udp or tcp
|
||||||
* @param string $poller_group the poller group this device will belong to
|
* @param string $poller_group the poller group this device will belong to
|
||||||
* @param string $force_add add even if the device isn't pingable
|
* @param boolean $force_add add even if the device isn't reachable
|
||||||
* @param string $port_assoc_mode snmp field to use to determine unique ports
|
* @param string $port_assoc_mode snmp field to use to determine unique ports
|
||||||
*
|
*
|
||||||
* @return int returns the device_id of the added device
|
* @return int returns the device_id of the added device
|
||||||
@@ -267,7 +267,7 @@ function delete_device($id) {
|
|||||||
* @throws InvalidPortAssocModeException The given port association mode was invalid
|
* @throws InvalidPortAssocModeException The given port association mode was invalid
|
||||||
* @throws SnmpVersionUnsupportedException The given snmp version was invalid
|
* @throws SnmpVersionUnsupportedException The given snmp version was invalid
|
||||||
*/
|
*/
|
||||||
function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $poller_group = '0', $force_add = '0', $port_assoc_mode = 'ifIndex') {
|
function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $poller_group = '0', $force_add = false, $port_assoc_mode = 'ifIndex') {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
// Test Database Exists
|
// Test Database Exists
|
||||||
@@ -291,10 +291,12 @@ function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test reachability
|
// Test reachability
|
||||||
$address_family = snmpTransportToAddressFamily($transport);
|
if (!$force_add) {
|
||||||
$ping_result = isPingable($host, $address_family);
|
$address_family = snmpTransportToAddressFamily($transport);
|
||||||
if ($force_add == 1 || !$ping_result['result']) {
|
$ping_result = isPingable($host, $address_family);
|
||||||
throw new HostUnreachablePingException("Could not ping $host");
|
if (!$ping_result['result']) {
|
||||||
|
throw new HostUnreachablePingException("Could not ping $host");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if $snmpver isn't set, try each version of snmp
|
// if $snmpver isn't set, try each version of snmp
|
||||||
@@ -311,7 +313,7 @@ function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $
|
|||||||
// Try each set of parameters from config
|
// Try each set of parameters from config
|
||||||
foreach ($config['snmp']['v3'] as $v3) {
|
foreach ($config['snmp']['v3'] as $v3) {
|
||||||
$device = deviceArray($host, null, $snmpver, $port, $transport, $v3, $port_assoc_mode);
|
$device = deviceArray($host, null, $snmpver, $port, $transport, $v3, $port_assoc_mode);
|
||||||
if ($force_add == 1 || isSNMPable($device)) {
|
if ($force_add || isSNMPable($device)) {
|
||||||
$snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB");
|
$snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB");
|
||||||
$result = createHost($host, null, $snmpver, $port, $transport, $v3, $poller_group, $port_assoc_mode, $snmphost);
|
$result = createHost($host, null, $snmpver, $port, $transport, $v3, $poller_group, $port_assoc_mode, $snmphost);
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
@@ -326,7 +328,7 @@ function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $
|
|||||||
foreach ($config['snmp']['community'] as $community) {
|
foreach ($config['snmp']['community'] as $community) {
|
||||||
$device = deviceArray($host, $community, $snmpver, $port, $transport, null, $port_assoc_mode);
|
$device = deviceArray($host, $community, $snmpver, $port, $transport, null, $port_assoc_mode);
|
||||||
|
|
||||||
if ($force_add == 1 || isSNMPable($device)) {
|
if ($force_add || isSNMPable($device)) {
|
||||||
$snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB");
|
$snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB");
|
||||||
$result = createHost($host, $community, $snmpver, $port, $transport, array(), $poller_group, $port_assoc_mode, $snmphost);
|
$result = createHost($host, $community, $snmpver, $port, $transport, array(), $poller_group, $port_assoc_mode, $snmphost);
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
|
|||||||
Reference in New Issue
Block a user