* Copyright (c) 2016 Jens Langhammer * Copyright (c) 2016 Cercel Valentin * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ use LibreNMS\Authentication\LegacyAuth; use LibreNMS\Config; if (isset($settings['mode_select']) && $settings['mode_select'] !== '') { $mode = $settings['mode_select']; } elseif (isset($_SESSION["map_view"]) && is_numeric($_SESSION["map_view"])) { $mode = $_SESSION["map_view"]; } else { $mode = 0; } $select_modes = array( '0' => 'only devices', '1' => 'only services', '2' => 'devices and services', ); if (Config::get('webui.availability_map_compact') == 1) { $compact_tile = $settings['tile_size']; } $show_disabled_ignored = $settings['show_disabled_and_ignored']; if (defined('SHOW_SETTINGS')) { $common_output[] = '
'; if (Config::get('webui.availability_map_compact') === false) { $common_output[] = '
'; } if (Config::get('webui.availability_map_compact') == 1) { $common_output[] = '
'; } if ($show_disabled_ignored == 1) { $selected_yes = 'selected'; $selected_no = ''; } else { $selected_yes = ''; $selected_no = 'selected'; } $common_output[] = '
'; $common_output[] = '
'; if (Config::get('webui.availability_map_compact') == 1) { $common_outputp[] = '
'; } $common_output[] = '
'; } else { require_once 'includes/html/object-cache.inc.php'; $host_up_count = 0; $host_warn_count = 0; $host_down_count = 0; $host_ignored_count = 0; $host_disabled_count = 0; $service_up_count = 0; $service_warn_count = 0; $service_down_count = 0; $service_ignored_count = 0; $service_disabled_count = 0; if (Config::get('webui.availability_map_sort_status') == 1) { $deviceOrderBy = 'status'; $serviceOrderBy = '`S`.`service_status` DESC'; } else { $deviceOrderBy = 'hostname'; $serviceOrderBy = '`D`.`hostname`'; } if ($mode == 0 || $mode == 2) { // Only show devices if mode is 0 or 2 (Only Devices or both) if (Config::get('webui.availability_map_use_device_groups') != 0) { $device_group = 'SELECT `D`.`device_id` FROM `device_group_device` AS `D` WHERE `device_group_id` = ?'; $in_devices = dbFetchColumn($device_group, [$_SESSION['group_view']]); } $sql = 'SELECT `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`status`, `D`.`uptime`, `D`.`os`, `D`.`icon`, `D`.`ignore`, `D`.`disabled` FROM `devices` AS `D`'; if (!LegacyAuth::user()->hasGlobalRead()) { $sql .= ' , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND '; $param = [LegacyAuth::id()]; } else { $sql .= ' WHERE '; $param = []; } if ($show_disabled_ignored != 1) { $sql .= '`D`.`ignore` = 0 AND `D`.`disabled` = 0 '; } else { $sql .= '(`D`.`status` IN (0,1,2) OR `D`.`ignore` = 1 OR `D`.`disabled` = 1)'; } if (Config::get('webui.availability_map_use_device_groups') != 0 && !empty($in_devices)) { $sql .= " AND `D`.`device_id` IN " . dbGenPlaceholders(count($in_devices)); $param = array_merge($param, $in_devices); } $sql .= " ORDER BY `".$deviceOrderBy."`"; $temp_output = array(); foreach (dbFetchRows($sql, $param) as $device) { if ($device['disabled'] == '1') { $deviceState = "disabled"; $deviceLabel = "blackbg"; $host_disabled_count++; } elseif ($device['ignore'] == '1') { $deviceState = "ignored"; $deviceLabel = "label-default"; $host_ignored_count++; } elseif ($device['status'] == '1') { if (($device['uptime'] < Config::get('uptime_warning')) && ($device['uptime'] != 0)) { $deviceState = 'warn'; $deviceLabel = 'label-warning'; $deviceLabelOld = 'availability-map-oldview-box-warn'; $host_warn_count++; } else { $deviceState = 'up'; $deviceLabel = 'label-success'; $deviceLabelOld = 'availability-map-oldview-box-up'; $host_up_count++; } } else { $deviceState = 'down'; $deviceLabel = 'label-danger'; $deviceLabelOld = 'availability-map-oldview-box-down'; $host_down_count++; } $device_system_name = format_hostname($device); if (Config::get('webui.availability_map_compact') == 0) { if ($directpage == "yes") { $deviceIcon = getIconTag($device); $temp_output[] = '
' . $deviceState . ' ' . $deviceIcon . '
' . shorthost($device_system_name) . '
'; } else { if ($settings['color_only_select'] == 1) { $deviceState = ' '; $deviceLabel .= ' widget-availability-fixed'; } $temp_output[] = ' ' . $deviceState . ' '; } } else { $temp_output[] = "
"; } } } if (($mode == 1 || $mode == 2) && (Config::get('show_services') != 0)) { if (LegacyAuth::user()->hasGlobalRead()) { $service_query = 'select `S`.`service_type`, `S`.`service_id`, `S`.`service_desc`, `S`.`service_status`, `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`os`, `D`.`icon` from services S, devices D where `S`.`device_id` = `D`.`device_id` ORDER BY '.$serviceOrderBy.';'; $service_par = array(); } else { $service_query = 'select `S`.`service_type`, `S`.`service_id`, `S`.`service_desc`, `S`.`service_status`, `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`os`, `D`.`icon` from services S, devices D, devices_perms P where `S`.`device_id` = `D`.`device_id` AND D.device_id = P.device_id AND P.user_id = ? ORDER BY '.$serviceOrderBy.';'; $service_par = array(LegacyAuth::id()); } $services = dbFetchRows($service_query, $service_par); if (count($services) > 0) { foreach ($services as $service) { if ($service['service_status'] == '0') { $serviceLabel = "label-success"; $serviceLabelOld = 'availability-map-oldview-box-up'; $serviceState = "up"; $service_up_count++; } elseif ($service['service_status'] == '1') { $serviceLabel = "label-warning"; $serviceLabelOld = 'availability-map-oldview-box-warn'; $serviceState = "warn"; $service_warn_count++; } else { $serviceLabel = "label-danger"; $serviceLabelOld = 'availability-map-oldview-box-down'; $serviceState = "down"; $service_down_count++; } $service_system_name = format_hostname($service); if (Config::get('webui.availability_map_compact') == 0) { if ($directpage == "yes") { $deviceIcon = getIconTag($service); $temp_output[] = '
' . $service["service_type"] . ' ' . $serviceState . ' ' . $deviceIcon . '
' . shorthost($service_system_name) . '
'; } else { $serviceText = $service['service_type'] . ' - ' . $serviceState; if ($settings['color_only_select'] == 1) { $serviceText = ' '; $serviceLabel .= ' widget-availability-fixed'; } $temp_output[] = ' ' . $serviceText . ' '; } } else { $temp_output[] = " 'device', 'tab' => 'services', 'device' => $service['device_id'])) . "' title='${service_system_name} - ${service['service_type']} - ${service['service_desc']}'>
"; } } } else { $temp_output [] = ''; } } if ($directpage == "yes") { $temp_header[] = '
Availability map for
'; if ((Config::get('webui.availability_map_use_device_groups') != 0) && ($mode == 0 || $mode == 2)) { $sql = 'SELECT `G`.`id`, `G`.`name` FROM `device_groups` AS `G`'; $dev_groups = dbFetchRows($sql); if ($_SESSION['group_view'] == 0) { $selected = 'selected'; } else { $selected = ''; } $temp_header[] = ' Device group '; } } if ($directpage == "yes") { $deviceClass = 'page-availability-report-host'; $serviceClass = 'page-availability-report-host'; } else { $deviceClass = 'widget-availability-host'; $serviceClass = 'widget-availability-service'; } if ($show_disabled_ignored == 1) { $disabled_ignored_header = ' ignored: '.$host_ignored_count.' disabled: '.$host_disabled_count.''; } if ($mode == 0 || $mode == 2) { $temp_header[] = '
Total hosts up: '.$host_up_count.' warn: '.$host_warn_count.' down: '.$host_down_count.' '.$disabled_ignored_header.'
'; } if (($mode == 1 || $mode == 2) && (Config::get('show_services') != 0)) { $temp_header[] = '
Total services up: '.$service_up_count.' warn: '.$service_warn_count.' down: '.$service_down_count.'
'; } $temp_header[] = '
'; $temp_header[] = '
'; $common_output = array_merge($temp_header, $temp_output); }