function stage5() { $this->setConfig('ZBX_CONFIG_FILE_CORRECT', true); $config_file_name = Z::getInstance()->getRootDir() . CConfigFile::CONFIG_FILE_PATH; $config = new CConfigFile($config_file_name); $config->config = ['DB' => ['TYPE' => $this->getConfig('DB_TYPE'), 'SERVER' => $this->getConfig('DB_SERVER'), 'PORT' => $this->getConfig('DB_PORT'), 'DATABASE' => $this->getConfig('DB_DATABASE'), 'USER' => $this->getConfig('DB_USER'), 'PASSWORD' => $this->getConfig('DB_PASSWORD'), 'SCHEMA' => $this->getConfig('DB_SCHEMA')], 'ZBX_SERVER' => $this->getConfig('ZBX_SERVER'), 'ZBX_SERVER_PORT' => $this->getConfig('ZBX_SERVER_PORT'), 'ZBX_SERVER_NAME' => $this->getConfig('ZBX_SERVER_NAME')]; $error = false; if (!$config->save()) { $error = true; $messages[] = ['type' => 'error', 'message' => $config->error]; } if ($error) { $this->SHOW_RETRY_BUTTON = true; $this->setConfig('ZBX_CONFIG_FILE_CORRECT', false); $message_box = makeMessageBox(false, $messages, _('Cannot create the configuration file.'), false, true); $message = [new CTag('p', true, _('Alternatively, you can install it manually:')), new CTag('ol', true, [new CTag('li', true, new CLink(_('Download the configuration file'), 'setup.php?save_config=1')), new CTag('li', true, _s('Save it as "%1$s"', $config_file_name))])]; } else { $this->DISABLE_CANCEL_BUTTON = true; $this->DISABLE_BACK_BUTTON = true; $message_box = null; $message = [(new CTag('h1', true, _('Congratulations! You have successfully installed Zabbix frontend.')))->addClass(ZBX_STYLE_GREEN), new CTag('p', true, _s('Configuration file "%1$s" created.', $config_file_name))]; } return [new CTag('h1', true, _('Install')), (new CDiv([$message_box, $message]))->addClass(ZBX_STYLE_SETUP_RIGHT_BODY)]; }
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $this->dataId = 'httptest_details'; $httptest = API::HttpTest()->get(['output' => ['httptestid', 'name', 'hostid'], 'selectSteps' => ['httpstepid', 'name', 'no'], 'httptestids' => $this->profileIdx2, 'preservekeys' => true]); $httptest = reset($httptest); if (!$httptest) { $messages = [['type' => 'error', 'message' => _('No permissions to referred object or it does not exist!')]]; return $this->getOutput(makeMessageBox(false, $messages, null, false, false)); } $httptest['lastfailedstep'] = 0; $httptest['error'] = ''; // fetch http test execution data $httptest_data = Manager::HttpTest()->getLastData([$httptest['httptestid']]); if ($httptest_data) { $httptest_data = reset($httptest_data); } // fetch HTTP step items $items = DBfetchArray(DBselect('SELECT i.value_type,i.valuemapid,i.units,i.itemid,hi.type,hs.httpstepid' . ' FROM items i,httpstepitem hi,httpstep hs' . ' WHERE hi.itemid=i.itemid' . ' AND hi.httpstepid=hs.httpstepid' . ' AND hs.httptestid=' . zbx_dbstr($httptest['httptestid']))); $step_items = []; foreach ($items as $item) { $step_items[$item['httpstepid']][$item['type']] = $item; } // fetch HTTP item history $item_history = Manager::History()->getLast($items); $table = (new CTableInfo())->setHeader([_('Step'), _('Speed'), _('Response time'), _('Response code'), _('Status')]); $total_time = ['value' => 0, 'value_type' => null, 'valuemapid' => null, 'units' => null]; order_result($httptest['steps'], 'no'); foreach ($httptest['steps'] as $step_data) { $items_by_type = $step_items[$step_data['httpstepid']]; $status['msg'] = _('OK'); $status['style'] = ZBX_STYLE_GREEN; $status['afterError'] = false; if (!array_key_exists('lastfailedstep', $httptest_data)) { $status['msg'] = _('Never executed'); $status['style'] = ZBX_STYLE_GREY; } elseif ($httptest_data['lastfailedstep'] != 0) { if ($httptest_data['lastfailedstep'] == $step_data['no']) { $status['msg'] = $httptest_data['error'] === null ? _('Unknown error') : _s('Error: %1$s', $httptest_data['error']); $status['style'] = ZBX_STYLE_RED; } elseif ($httptest_data['lastfailedstep'] < $step_data['no']) { $status['msg'] = _('Unknown'); $status['style'] = ZBX_STYLE_GREY; $status['afterError'] = true; } } foreach ($items_by_type as &$item) { // Calculate the total time it took to execute the scenario. // Skip steps that come after a failed step. if (!$status['afterError'] && $item['type'] == HTTPSTEP_ITEM_TYPE_TIME) { $total_time['value_type'] = $item['value_type']; $total_time['valuemapid'] = $item['valuemapid']; $total_time['units'] = $item['units']; if (array_key_exists($item['itemid'], $item_history)) { $history = $item_history[$item['itemid']][0]; $total_time['value'] += $history['value']; } } } unset($item); // step speed $speed_item = $items_by_type[HTTPSTEP_ITEM_TYPE_IN]; if (!$status['afterError'] && array_key_exists($speed_item['itemid'], $item_history) && $item_history[$speed_item['itemid']][0]['value'] > 0) { $speed = formatHistoryValue($item_history[$speed_item['itemid']][0]['value'], $speed_item); } else { $speed = UNKNOWN_VALUE; } // step response time $resptime_item = $items_by_type[HTTPSTEP_ITEM_TYPE_TIME]; if (!$status['afterError'] && array_key_exists($resptime_item['itemid'], $item_history) && $item_history[$resptime_item['itemid']][0]['value'] > 0) { $resp_time = formatHistoryValue($item_history[$resptime_item['itemid']][0]['value'], $resptime_item); } else { $resp_time = UNKNOWN_VALUE; } // step response code $resp_item = $items_by_type[HTTPSTEP_ITEM_TYPE_RSPCODE]; if (!$status['afterError'] && array_key_exists($resp_item['itemid'], $item_history) && $item_history[$resp_item['itemid']][0]['value'] > 0) { $resp = formatHistoryValue($item_history[$resp_item['itemid']][0]['value'], $resp_item); } else { $resp = UNKNOWN_VALUE; } $table->addRow([CMacrosResolverHelper::resolveHttpTestName($httptest['hostid'], $step_data['name']), $speed, $resp_time, $resp, (new CSpan($status['msg']))->addClass($status['style'])]); } if (!array_key_exists('lastfailedstep', $httptest_data)) { $status['msg'] = _('Never executed'); $status['style'] = ZBX_STYLE_GREY; } elseif ($httptest_data['lastfailedstep'] != 0) { $status['msg'] = $httptest_data['error'] === null ? _('Unknown error') : _s('Error: %1$s', $httptest_data['error']); $status['style'] = ZBX_STYLE_RED; } else { $status['msg'] = _('OK'); $status['style'] = ZBX_STYLE_GREEN; } $table->addRow([bold(_('TOTAL')), '', bold($total_time['value'] ? formatHistoryValue($total_time['value'], $total_time) : UNKNOWN_VALUE), '', (new CSpan($status['msg']))->addClass($status['style'])]); return $this->getOutput($table); }
function getSessionMessages($clear = true) { $types = array('alert', 'notice', 'success'); $messages = array(); foreach ($types as $type) { if (isset($_SESSION[SESSION_NAME]['messages'][$type]) && count($_SESSION[SESSION_NAME]['messages'][$type])) { $messages[] = makeMessageBox($_SESSION[SESSION_NAME]['messages'][$type], $type); } } $result = count($messages) ? implode("\n", $messages) : ''; // Clear out the session messages if ($clear) { $_SESSION[SESSION_NAME]['messages'] = array(); } return $result; }
function show_messages($good = false, $okmsg = null, $errmsg = null) { global $page, $ZBX_MESSAGES; if (!defined('PAGE_HEADER_LOADED')) { // return null; } if (defined('ZBX_API_REQUEST')) { return null; } if (!isset($page['type'])) { $page['type'] = PAGE_TYPE_HTML; } $imageMessages = []; $title = $good ? $okmsg : $errmsg; $messages = isset($ZBX_MESSAGES) ? $ZBX_MESSAGES : []; $ZBX_MESSAGES = []; switch ($page['type']) { case PAGE_TYPE_IMAGE: if ($title !== null) { $imageMessages[] = ['text' => $title, 'color' => !$good ? ['R' => 255, 'G' => 0, 'B' => 0] : ['R' => 34, 'G' => 51, 'B' => 68]]; } foreach ($messages as $message) { $imageMessages[] = ['text' => $message['message'], 'color' => $message['type'] == 'error' ? ['R' => 255, 'G' => 55, 'B' => 55] : ['R' => 155, 'G' => 155, 'B' => 55]]; } break; case PAGE_TYPE_XML: if ($title !== null) { echo htmlspecialchars($title) . "\n"; } foreach ($messages as $message) { echo '[' . $message['type'] . '] ' . $message['message'] . "\n"; } break; case PAGE_TYPE_HTML: default: if ($title || $messages) { makeMessageBox($good, $messages, $title, true, !$good)->show(); } break; } // draw an image with the messages if ($imageMessages) { $imageFontSize = 8; // calculate the size of the text $imageWidth = 0; $imageHeight = 0; foreach ($imageMessages as &$msg) { $size = imageTextSize($imageFontSize, 0, $msg['text']); $msg['height'] = $size['height'] - $size['baseline']; // calculate the total size of the image $imageWidth = max($imageWidth, $size['width']); $imageHeight += $size['height'] + 1; } unset($msg); // additional padding $imageWidth += 2; $imageHeight += 2; // create the image $canvas = imagecreate($imageWidth, $imageHeight); imagefilledrectangle($canvas, 0, 0, $imageWidth, $imageHeight, imagecolorallocate($canvas, 255, 255, 255)); // draw each message $y = 1; foreach ($imageMessages as $msg) { $y += $msg['height']; imageText($canvas, $imageFontSize, 0, 1, $y, imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']), $msg['text']); } imageOut($canvas); imagedestroy($canvas); } }