diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php index 039c9a8324..a20a7c3b8b 100644 --- a/html/pages/device.inc.php +++ b/html/pages/device.inc.php @@ -22,16 +22,13 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) { $device = device_by_id_cache($vars['device']); $attribs = get_dev_attribs($device['device_id']); + load_os($device); $entity_state = get_dev_entity_state($device['device_id']); // print_r($entity_state); $pagetitle[] = $device['hostname']; - if ($config['os'][$device['os']]['group']) { - $device['os_group'] = $config['os'][$device['os']]['group']; - } - echo '
'; echo ''; require 'includes/device-header.inc.php'; diff --git a/includes/common.php b/includes/common.php index d828361f43..cf00123f52 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1509,16 +1509,32 @@ function display($value) } /** - * @param $os - * @return array|mixed + * Load the os definition for the device and set type and os_group + * $device['os'] must be set + * + * @param array $device + * @throws Exception No OS to load */ -function load_os($os) +function load_os(&$device) { global $config; - if (isset($os)) { - return Symfony\Component\Yaml\Yaml::parse( - file_get_contents($config['install_dir'] . '/includes/definitions/' . $os . '.yaml') - ); + if (!isset($device['os'])) { + throw new Exception('No OS to load'); + } + + $config['os'][$device['os']] = Symfony\Component\Yaml\Yaml::parse( + file_get_contents($config['install_dir'] . '/includes/definitions/' . $device['os'] . '.yaml') + ); + + // Set type to a predefined type for the OS if it's not already set + if ($device['type'] == 'unknown' || $device['type'] == '') { + if ($config['os'][$device['os']]['type']) { + $device['type'] = $config['os'][$device['os']]['type']; + } + } + + if ($config['os'][$device['os']]['group']) { + $device['os_group'] = $config['os'][$device['os']]['group']; } } diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 84b3895e14..dfcfa8b5cc 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -110,23 +110,11 @@ function discover_device($device, $options = null) } } - $config['os'][$device['os']] = load_os($device['os']); + load_os($device); if (is_array($config['os'][$device['os']]['register_mibs'])) { register_mibs($device, $config['os'][$device['os']]['register_mibs'], 'includes/discovery/os/' . $device['os'] . '.inc.php'); } - // Set type to a predefined type for the OS if it's not already set - if ($device['type'] == 'unknown' || $device['type'] == '') { - if ($config['os'][$device['os']]['type']) { - $device['type'] = $config['os'][$device['os']]['type']; - } - } - - if ($config['os'][$device['os']]['group']) { - $device['os_group'] = $config['os'][$device['os']]['group']; - echo ' (' . $device['os_group'] . ')'; - } - echo "\n"; // If we've specified modules, use them, else walk the modules array diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 630b242abb..ec23a7416a 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -149,7 +149,7 @@ function poll_device($device, $options) { global $config, $device, $polled_devices, $memcache; - $config['os'][$device['os']] = load_os($device['os']); + load_os($device); $attribs = get_dev_attribs($device['device_id']); $device['snmp_max_repeaters'] = $attribs['snmp_max_repeaters']; diff --git a/includes/polling/wifi.inc.php b/includes/polling/wifi.inc.php index 4f4253a71f..2f033742bc 100644 --- a/includes/polling/wifi.inc.php +++ b/includes/polling/wifi.inc.php @@ -66,20 +66,21 @@ if ($device['type'] == 'network' || $device['type'] == 'firewall' || $device['ty echo (($wificlients1 + 0).' clients on wireless connector, '); } elseif ($device['os'] == 'unifi') { echo 'Checking Unifi Wireless clients... '; + $wificlients1 = 0; + $wificlients2 = 0; + + $clients = explode("\n", snmp_walk($device, 'unifiVapNumStations', '-Oqv', 'UBNT-UniFi-MIB')); + $bands = explode("\n", snmp_walk($device, 'unifiVapRadio', '-Oqv', 'UBNT-UniFi-MIB')); - $clients = snmp_walk($device, 'unifiVapNumStations', '-Oqv', 'UBNT-UniFi-MIB'); - $bands = snmp_walk($device, 'unifiVapRadio', '-Oqv', 'UBNT-UniFi-MIB'); - $clients = explode("\n", $clients); - $bands = explode("\n", $bands); foreach ($bands as $index => $band_index) { if ($band_index == "ng") { - $wificlients1 = $wificlients1 + $clients[$index] + 0; + $wificlients1 += $clients[$index]; } else { - $wificlients2 = $wificlients2 + $clients[$index] + 0; + $wificlients2 += $clients[$index]; } } - echo (($wificlients1 + 0).' clients on Radio0, '.($wificlients2 + 0)." clients on Radio1\n"); + echo $wificlients1 . ' clients on Radio0, ' . $wificlients2 . " clients on Radio1\n"; include 'includes/polling/mib/ubnt-unifi-mib.inc.php'; }