/** * Format server data for display * @param array $server * @return array */ protected function formatServer($server) { $server['rtime'] = round((double) $server['rtime'], 4); $server['last_online'] = psm_timespan($server['last_online']); $server['last_check'] = psm_timespan($server['last_check']); $server['active'] = psm_get_lang('system', $server['active']); $server['email'] = psm_get_lang('system', $server['email']); $server['sms'] = psm_get_lang('system', $server['sms']); $server['pushover'] = psm_get_lang('system', $server['pushover']); if ($server['status'] == 'on' && $server['warning_threshold_counter'] > 0) { $server['status'] = 'warning'; } $server['error'] = htmlentities($server['error']); $server['type'] = psm_get_lang('servers', 'type_' . $server['type']); $server['timeout'] = $server['timeout'] > 0 ? $server['timeout'] : PSM_CURL_TIMEOUT; $url_actions = array('delete', 'edit', 'view'); foreach ($url_actions as $action) { $server['url_' . $action] = psm_build_url(array('mod' => 'server', 'action' => $action, 'id' => $server['server_id'])); } return $server; }
/** * Prepare the template to show a list of all servers * @todo move the background colurs to the config */ protected function executeIndex() { // set background color to black $this->black_background = true; $this->twig->addGlobal('subtitle', psm_get_lang('menu', 'server_status')); // add header accessories $layout = $this->getUser()->getUserPref('status_layout', 0); $layout_data = array('label_last_check' => psm_get_lang('servers', 'last_check'), 'label_last_online' => psm_get_lang('servers', 'last_online'), 'label_rtime' => psm_get_lang('servers', 'latency'), 'block_layout_active' => $layout == 0 ? 'active' : '', 'list_layout_active' => $layout != 0 ? 'active' : ''); $this->setHeaderAccessories($this->twig->render('module/server/status/header.tpl.html', $layout_data)); $this->addFooter(false); // get the active servers from database $servers = $this->getServers(); $layout_data['servers_offline'] = array(); $layout_data['servers_online'] = array(); foreach ($servers as $server) { if ($server['active'] == 'no') { continue; } $server['last_checked_nice'] = psm_timespan($server['last_check']); $server['last_online_nice'] = psm_timespan($server['last_online']); $server['url_view'] = psm_build_url(array('mod' => 'server', 'action' => 'view', 'id' => $server['server_id'], 'back_to' => 'server_status')); if ($server['status'] == "off") { $layout_data['servers_offline'][] = $server; } elseif ($server['warning_threshold_counter'] > 0) { $server['class_warning'] = 'warning'; $layout_data['servers_offline'][] = $server; } else { $layout_data['servers_online'][] = $server; } } $auto_refresh_seconds = psm_get_conf('auto_refresh_servers'); if (intval($auto_refresh_seconds) > 0) { $this->twig->addGlobal('auto_refresh', true); $this->twig->addGlobal('auto_refresh_seconds', $auto_refresh_seconds); } return $this->twig->render('module/server/status/index.tpl.html', $layout_data); }