fix: Changing device type now is persistant (#5529)

This commit is contained in:
Neil Lathwood
2017-01-22 09:49:13 +00:00
committed by GitHub
parent 53df1d0b2c
commit 32da1bceea
5 changed files with 18 additions and 4 deletions

View File

@@ -22,6 +22,7 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) {
$device = device_by_id_cache($vars['device']);
$attribs = get_dev_attribs($device['device_id']);
$device['attribs'] = $attribs;
load_os($device);
$entity_state = get_dev_entity_state($device['device_id']);

View File

@@ -24,17 +24,27 @@ if ($_POST['editing']) {
dbUpdate(array('location'=>$override_sysLocation_string), 'devices', '`device_id`=?', array($device['device_id']));
}
if ($device['type'] != $vars['type']) {
$param['type'] = $vars['type'];
$update_type = true;
}
#FIXME needs more sanity checking! and better feedback
$param = array('purpose' => $vars['descr'], 'type' => $vars['type'], 'ignore' => set_numeric($vars['ignore']), 'disabled' => set_numeric($vars['disabled']));
$param['purpose'] = $vars['descr'];
$param['ignore'] = set_numeric($vars['ignore']);
$param['disabled'] = set_numeric($vars['disabled']);
$rows_updated = dbUpdate($param, 'devices', '`device_id` = ?', array($device['device_id']));
if ($rows_updated > 0 || $updated) {
if ($update_type === true) {
set_dev_attrib($device, 'override_device_type', true);
}
$update_message = "Device record updated.";
$updated = 1;
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id']));
} elseif ($rows_updated = '-1') {
} elseif ($rows_updated == 0) {
$update_message = "Device record unchanged. No update necessary.";
$updated = -1;
} else {

View File

@@ -1533,7 +1533,7 @@ function load_os(&$device)
}
// Set type to a predefined type for the OS if it's not already set
if ($config['os'][$device['os']]['type'] != $device['type']) {
if ($device['attribs']['override_device_type'] != 1 && $config['os'][$device['os']]['type'] != $device['type']) {
log_event('Device type changed '.$device['type'].' => '.$config['os'][$device['os']]['type'], $device, 'system');
$device['type'] = $config['os'][$device['os']]['type'];
dbUpdate(array('type' => $device['type']), 'devices', 'device_id=?', array($device['device_id']));

View File

@@ -94,6 +94,7 @@ function discover_device($device, $options = null)
$valid = array();
// Reset $valid array
$attribs = get_dev_attribs($device['device_id']);
$device['attribs'] = $attribs;
$device['snmp_max_repeaters'] = $attribs['snmp_max_repeaters'];
$device_start = microtime(true);

View File

@@ -165,9 +165,11 @@ function poll_device($device, $options)
{
global $config, $device, $polled_devices, $memcache;
$attribs = get_dev_attribs($device['device_id']);
$device['attribs'] = $attribs;
load_os($device);
$attribs = get_dev_attribs($device['device_id']);
$device['snmp_max_repeaters'] = $attribs['snmp_max_repeaters'];
$device['snmp_max_oid'] = $attribs['snmp_max_oid'];