1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2019 Zabbix SIA
**
** 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 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/**
* A class to display Http tests table as a screen element.
*/
class CScreenHttpTest extends CScreenBase {
/**
* Screen data.
*
* @var array
*/
protected $data = [];
/**
* Init screen data.
*
* @param array $options
* @param array $options['data']
*/
public function __construct(array $options = []) {
parent::__construct($options);
$this->data = $options['data'];
}
/**
* Process screen.
*
* @return CDiv (screen inside container)
*/
public function get() {
$this->dataId = 'httptest';
$sort_field = $this->data['sort'];
$sort_order = $this->data['sortorder'];
$httptests = [];
$paging = [];
if ($this->data['hosts_selected']) {
$config = select_config();
$options = [
'output' => ['httptestid', 'name', 'hostid'],
'selectHosts' => ['name', 'status'],
'selectSteps' => API_OUTPUT_COUNT,
'templated' => false,
'preservekeys' => true,
'filter' => ['status' => HTTPTEST_STATUS_ACTIVE],
'limit' => $config['search_limit'] + 1
];
if ($this->hostid != 0) {
$options['hostids'] = [$this->hostid];
}
elseif ($this->groupid) {
$options['groupids'] = zbx_toArray($this->groupid);
}
$httptests = API::HttpTest()->get($options);
foreach ($httptests as &$httptest) {
$httptest['host'] = reset($httptest['hosts']);
$httptest['hostname'] = $httptest['host']['name'];
unset($httptest['hosts']);
}
unset($httptest);
order_result($httptests, $sort_field, $sort_order);
$url = (new CUrl('zabbix.php'))
->setArgument('action', 'web.view')
->setArgument('groupid', $this->data['groupid'])
->setArgument('hostid', $this->hostid);
$paging = getPagingLine($httptests, $sort_order, $url);
$httptests = resolveHttpTestMacros($httptests, true, false);
order_result($httptests, $sort_field, $sort_order);
// Fetch the latest results of the web scenario.
$last_httptest_data = Manager::HttpTest()->getLastData(array_keys($httptests));
foreach ($httptests as &$httptest) {
if (array_key_exists($httptest['httptestid'], $last_httptest_data)) {
$httptest['lastcheck'] = $last_httptest_data[$httptest['httptestid']]['lastcheck'];
$httptest['lastfailedstep'] = $last_httptest_data[$httptest['httptestid']]['lastfailedstep'];
$httptest['error'] = $last_httptest_data[$httptest['httptestid']]['error'];
}
}
unset($httptest);
}
// Create table.
$table = (new CTableInfo())
->setHeader([
make_sorting_header(_('Host'), 'hostname', $sort_field, $sort_order, 'zabbix.php?action=web.view'),
make_sorting_header(_('Name'), 'name', $sort_field, $sort_order, 'zabbix.php?action=web.view'),
_('Number of steps'),
_('Last check'),
_('Status')
]);
foreach ($httptests as $httptest) {
if (array_key_exists('lastfailedstep', $httptest) && $httptest['lastfailedstep'] !== null) {
$lastcheck = zbx_date2str(DATE_TIME_FORMAT_SECONDS, $httptest['lastcheck']);
if ($httptest['lastfailedstep'] != 0) {
$httpstep = get_httpstep_by_no($httptest['httptestid'], $httptest['lastfailedstep']);
$error = ($httptest['error'] === null) ? _('Unknown error') : $httptest['error'];
if ($httpstep) {
$status = new CSpan(_s('Step "%1$s" [%2$s of %3$s] failed: %4$s', $httpstep['name'],
$httptest['lastfailedstep'], $httptest['steps'], $error
));
}
else {
$status = new CSpan(_s('Unknown step failed: %1$s', $error));
}
$status->addClass(ZBX_STYLE_RED);
}
else {
$status = (new CSpan(_('OK')))->addClass(ZBX_STYLE_GREEN);
}
}
else {
$lastcheck = '';
$status = '';
}
$table->addRow(new CRow([
($httptest['host']['status'] == HOST_STATUS_NOT_MONITORED)
? (new CSpan($httptest['hostname']))->addClass(ZBX_STYLE_RED)
: $httptest['hostname'],
new CLink($httptest['name'], 'httpdetails.php?httptestid='.$httptest['httptestid']),
$httptest['steps'],
$lastcheck,
$status
]));
}
return $this->getOutput([$table, $paging], true, $this->data);
}
}
|