PageRenderTime 69ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/zabbix-2.0.1/frontends/php/include/blocks.inc.php

#
PHP | 1333 lines | 1133 code | 146 blank | 54 comment | 135 complexity | 4c314549a22f6ef2b72f87760ff72a9d MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. <?php
  2. /*
  3. ** Zabbix
  4. ** Copyright (C) 2001-2011 Zabbix SIA
  5. **
  6. ** This program is free software; you can redistribute it and/or modify
  7. ** it under the terms of the GNU General Public License as published by
  8. ** the Free Software Foundation; either version 2 of the License, or
  9. ** (at your option) any later version.
  10. **
  11. ** This program is distributed in the hope that it will be useful,
  12. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ** GNU General Public License for more details.
  15. **
  16. ** You should have received a copy of the GNU General Public License
  17. ** along with this program; if not, write to the Free Software
  18. ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. **/
  20. ?>
  21. <?php
  22. require_once dirname(__FILE__).'/graphs.inc.php';
  23. require_once dirname(__FILE__).'/screens.inc.php';
  24. require_once dirname(__FILE__).'/maps.inc.php';
  25. require_once dirname(__FILE__).'/users.inc.php';
  26. function make_favorite_graphs() {
  27. $favList = new CList(null, 'favorites');
  28. $graphids = array();
  29. $itemids = array();
  30. $fav_graphs = get_favorites('web.favorite.graphids');
  31. foreach ($fav_graphs as $favorite) {
  32. if ('itemid' == $favorite['source']) {
  33. $itemids[$favorite['value']] = $favorite['value'];
  34. }
  35. else {
  36. $graphids[$favorite['value']] = $favorite['value'];
  37. }
  38. }
  39. $options = array(
  40. 'graphids' => $graphids,
  41. 'selectHosts' => API_OUTPUT_EXTEND,
  42. 'output' => API_OUTPUT_EXTEND
  43. );
  44. $graphs = API::Graph()->get($options);
  45. $graphs = zbx_toHash($graphs, 'graphid');
  46. $options = array(
  47. 'itemids' => $itemids,
  48. 'selectHosts' => API_OUTPUT_EXTEND,
  49. 'filter' => array('flags' => array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)),
  50. 'output' => API_OUTPUT_EXTEND,
  51. 'webitems' => 1
  52. );
  53. $items = API::Item()->get($options);
  54. $items = zbx_toHash($items, 'itemid');
  55. foreach ($fav_graphs as $favorite) {
  56. $sourceid = $favorite['value'];
  57. if ('itemid' == $favorite['source']) {
  58. if (!isset($items[$sourceid])) {
  59. continue;
  60. }
  61. $item = $items[$sourceid];
  62. $host = reset($item['hosts']);
  63. $item['name'] = itemName($item);
  64. $link = new CLink(get_node_name_by_elid($sourceid, null, ': ').$host['name'].':'.$item['name'], 'history.php?action=showgraph&itemid='.$sourceid);
  65. $link->setTarget('blank');
  66. }
  67. else {
  68. if (!isset($graphs[$sourceid])) {
  69. continue;
  70. }
  71. $graph = $graphs[$sourceid];
  72. $ghost = reset($graph['hosts']);
  73. $link = new CLink(get_node_name_by_elid($sourceid, null, ': ').$ghost['name'].':'.$graph['name'], 'charts.php?graphid='.$sourceid);
  74. $link->setTarget('blank');
  75. }
  76. $favList->addItem($link, 'nowrap');
  77. }
  78. return $favList;
  79. }
  80. function make_favorite_screens() {
  81. $favList = new CList(null, 'favorites');
  82. $fav_screens = get_favorites('web.favorite.screenids');
  83. $screenids = array();
  84. foreach ($fav_screens as $favorite) {
  85. if ('screenid' == $favorite['source']) {
  86. $screenids[$favorite['value']] = $favorite['value'];
  87. }
  88. }
  89. $options = array(
  90. 'screenids' => $screenids,
  91. 'output' => API_OUTPUT_EXTEND
  92. );
  93. $screens = API::Screen()->get($options);
  94. $screens = zbx_toHash($screens, 'screenid');
  95. foreach ($fav_screens as $favorite) {
  96. $source = $favorite['source'];
  97. $sourceid = $favorite['value'];
  98. if ('slideshowid' == $source) {
  99. if (!slideshow_accessible($sourceid, PERM_READ_ONLY)) {
  100. continue;
  101. }
  102. if (!$slide = get_slideshow_by_slideshowid($sourceid)) {
  103. continue;
  104. }
  105. $link = new CLink(get_node_name_by_elid($sourceid, null, ': ').$slide['name'], 'slides.php?elementid='.$sourceid);
  106. $link->setTarget('blank');
  107. }
  108. else {
  109. if (!isset($screens[$sourceid])) {
  110. continue;
  111. }
  112. $screen = $screens[$sourceid];
  113. $link = new CLink(get_node_name_by_elid($sourceid, null, ': ').$screen['name'], 'screens.php?elementid='.$sourceid);
  114. $link->setTarget('blank');
  115. }
  116. $favList->addItem($link, 'nowrap');
  117. }
  118. return $favList;
  119. }
  120. function make_favorite_maps() {
  121. $favList = new CList(null, 'favorites');
  122. $fav_sysmaps = get_favorites('web.favorite.sysmapids');
  123. $sysmapids = array();
  124. foreach ($fav_sysmaps as $favorite) {
  125. $sysmapids[$favorite['value']] = $favorite['value'];
  126. }
  127. $options = array(
  128. 'sysmapids' => $sysmapids,
  129. 'output' => API_OUTPUT_EXTEND
  130. );
  131. $sysmaps = API::Map()->get($options);
  132. foreach ($sysmaps as $sysmap) {
  133. $sysmapid = $sysmap['sysmapid'];
  134. $link = new CLink(get_node_name_by_elid($sysmapid, null, ': ').$sysmap['name'], 'maps.php?sysmapid='.$sysmapid);
  135. $link->setTarget('blank');
  136. $favList->addItem($link, 'nowrap');
  137. }
  138. return $favList;
  139. }
  140. function make_system_status($filter) {
  141. $ackParams = array();
  142. if (!empty($filter['screenid'])) {
  143. $ackParams['screenid'] = $filter['screenid'];
  144. }
  145. $table = new CTableInfo();
  146. $table->setHeader(array(
  147. is_show_all_nodes() ? _('Node') : null,
  148. _('Host group'),
  149. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_DISASTER]) ? getSeverityCaption(TRIGGER_SEVERITY_DISASTER) : null,
  150. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_HIGH]) ? getSeverityCaption(TRIGGER_SEVERITY_HIGH) : null,
  151. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_AVERAGE]) ? getSeverityCaption(TRIGGER_SEVERITY_AVERAGE) : null,
  152. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_WARNING]) ? getSeverityCaption(TRIGGER_SEVERITY_WARNING) : null,
  153. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_INFORMATION]) ? getSeverityCaption(TRIGGER_SEVERITY_INFORMATION) : null,
  154. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_NOT_CLASSIFIED]) ? getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED) : null
  155. ));
  156. // get host groups
  157. $options = array(
  158. 'nodeids' => get_current_nodeid(),
  159. 'monitored_hosts' => 1,
  160. 'groupids' => $filter['groupids'],
  161. 'output' => array('groupid', 'name'),
  162. 'preservekeys' => true
  163. );
  164. $groups = API::HostGroup()->get($options);
  165. // we need natural sort
  166. order_result($groups, 'name');
  167. $groupids = array();
  168. foreach ($groups as $group) {
  169. $groupids[] = $group['groupid'];
  170. $group['tab_priority'] = array();
  171. $group['tab_priority'][TRIGGER_SEVERITY_DISASTER] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
  172. $group['tab_priority'][TRIGGER_SEVERITY_HIGH] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
  173. $group['tab_priority'][TRIGGER_SEVERITY_AVERAGE] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
  174. $group['tab_priority'][TRIGGER_SEVERITY_WARNING] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
  175. $group['tab_priority'][TRIGGER_SEVERITY_INFORMATION] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
  176. $group['tab_priority'][TRIGGER_SEVERITY_NOT_CLASSIFIED] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
  177. $groups[$group['groupid']] = $group;
  178. }
  179. // get triggers
  180. $options = array(
  181. 'nodeids' => get_current_nodeid(),
  182. 'groupids' => $groupids,
  183. 'monitored' => true,
  184. 'maintenance' => $filter['maintenance'],
  185. 'skipDependent' => true,
  186. 'expandDescription' => true,
  187. 'filter' => array(
  188. 'priority' => $filter['severity'],
  189. 'value' => TRIGGER_VALUE_TRUE
  190. ),
  191. 'sortfield' => 'lastchange',
  192. 'sortorder' => ZBX_SORT_DOWN,
  193. 'output' => API_OUTPUT_EXTEND,
  194. 'selectHosts' => array('name'),
  195. 'preservekeys' => true
  196. );
  197. if ($filter['extAck'] == EXTACK_OPTION_UNACK) {
  198. $options['withLastEventUnacknowledged'] = 1;
  199. }
  200. $triggers = API::Trigger()->get($options);
  201. foreach ($triggers as $trigger) {
  202. $options = array(
  203. 'nodeids' => get_current_nodeid(),
  204. 'object' => EVENT_SOURCE_TRIGGERS,
  205. 'triggerids' => $trigger['triggerid'],
  206. 'filter'=> array(
  207. 'value' => TRIGGER_VALUE_TRUE,
  208. 'value_changed' => TRIGGER_VALUE_CHANGED_YES
  209. ),
  210. 'output' => API_OUTPUT_EXTEND,
  211. 'nopermissions' => true,
  212. 'select_acknowledges' => API_OUTPUT_COUNT,
  213. 'sortfield' => 'eventid',
  214. 'sortorder' => ZBX_SORT_DOWN,
  215. 'preservekeys' => true,
  216. 'limit' => 1
  217. );
  218. $events = API::Event()->get($options);
  219. if (empty($events)) {
  220. $trigger['event'] = array(
  221. 'value_changed' => 0,
  222. 'value' => $trigger['value'],
  223. 'acknowledged' => true,
  224. 'clock' => $trigger['lastchange']
  225. );
  226. }
  227. else {
  228. $trigger['event'] = reset($events);
  229. }
  230. foreach ($trigger['groups'] as $group) {
  231. if (in_array($filter['extAck'], array(EXTACK_OPTION_ALL, EXTACK_OPTION_BOTH))) {
  232. $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count']++;
  233. if ($groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count'] < 30) {
  234. $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['triggers'][] = $trigger;
  235. }
  236. }
  237. if (in_array($filter['extAck'], array(EXTACK_OPTION_UNACK, EXTACK_OPTION_BOTH))
  238. && !$trigger['event']['acknowledged']) {
  239. $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count_unack']++;
  240. if ($groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count_unack'] < 30) {
  241. $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['triggers_unack'][] = $trigger;
  242. }
  243. }
  244. }
  245. }
  246. unset($triggers);
  247. foreach ($groups as $group) {
  248. $group_row = new CRow();
  249. if (is_show_all_nodes()) {
  250. $group_row->addItem(get_node_name_by_elid($group['groupid']));
  251. }
  252. $name = new CLink($group['name'], 'tr_status.php?groupid='.$group['groupid'].'&hostid=0&show_triggers='.TRIGGERS_OPTION_ONLYTRUE);
  253. $group_row->addItem($name);
  254. foreach ($group['tab_priority'] as $severity => $data) {
  255. if (!is_null($filter['severity']) && !isset($filter['severity'][$severity])) {
  256. continue;
  257. }
  258. $allTriggersNum = $data['count'];
  259. if ($allTriggersNum) {
  260. $allTriggersNum = new CSpan($allTriggersNum, 'pointer');
  261. $allTriggersNum->setHint(makeTriggersPopup($data['triggers'], $ackParams));
  262. }
  263. $unackTriggersNum = $data['count_unack'];
  264. if ($unackTriggersNum) {
  265. $unackTriggersNum = new CSpan($unackTriggersNum, 'pointer red bold');
  266. $unackTriggersNum->setHint(makeTriggersPopup($data['triggers_unack'], $ackParams));
  267. }
  268. switch ($filter['extAck']) {
  269. case EXTACK_OPTION_ALL:
  270. $group_row->addItem(getSeverityCell($severity, $allTriggersNum, !$allTriggersNum));
  271. break;
  272. case EXTACK_OPTION_UNACK:
  273. $group_row->addItem(getSeverityCell($severity, $unackTriggersNum, !$unackTriggersNum));
  274. break;
  275. case EXTACK_OPTION_BOTH:
  276. if ($unackTriggersNum) {
  277. $span = new Cspan(SPACE._('of').SPACE);
  278. $unackTriggersNum = new CSpan($unackTriggersNum);
  279. }
  280. else {
  281. $span = null;
  282. $unackTriggersNum = null;
  283. }
  284. $group_row->addItem(getSeverityCell($severity, array($unackTriggersNum, $span, $allTriggersNum), !$allTriggersNum));
  285. break;
  286. }
  287. }
  288. $table->addRow($group_row);
  289. }
  290. $script = new CJSScript(get_js("jQuery('#hat_syssum_footer').html('"._s('Updated: %s', zbx_date2str(_('H:i:s')))."')"));
  291. return new CDiv(array($table, $script));
  292. }
  293. function make_hoststat_summary($filter) {
  294. $table = new CTableInfo();
  295. $table->setHeader(array(
  296. is_show_all_nodes() ? _('Node') : null,
  297. _('Host group'),
  298. _('Without problems'),
  299. _('With problems'),
  300. _('Total')
  301. ));
  302. // get host groups
  303. $options = array(
  304. 'nodeids' => get_current_nodeid(),
  305. 'groupids' => $filter['groupids'],
  306. 'monitored_hosts' => 1,
  307. 'output' => API_OUTPUT_EXTEND
  308. );
  309. $groups = API::HostGroup()->get($options);
  310. $groups = zbx_toHash($groups, 'groupid');
  311. order_result($groups, 'name');
  312. // get hosts
  313. $options = array(
  314. 'nodeids' => get_current_nodeid(),
  315. 'groupids' => zbx_objectValues($groups, 'groupid'),
  316. 'monitored_hosts' => 1,
  317. 'filter' => array('maintenance_status' => $filter['maintenance']),
  318. 'output' => array('hostid', 'name')
  319. );
  320. $hosts = API::Host()->get($options);
  321. $hosts = zbx_toHash($hosts, 'hostid');
  322. // get triggers
  323. $options = array(
  324. 'nodeids' => get_current_nodeid(),
  325. 'monitored' => 1,
  326. 'maintenance' => $filter['maintenance'],
  327. 'expandData' => 1,
  328. 'filter' => array(
  329. 'priority' => $filter['severity'],
  330. 'value' => TRIGGER_VALUE_TRUE
  331. ),
  332. 'output' => API_OUTPUT_EXTEND
  333. );
  334. $triggers = API::Trigger()->get($options);
  335. if ($filter['extAck']) {
  336. $options = array(
  337. 'nodeids' => get_current_nodeid(),
  338. 'monitored' => 1,
  339. 'maintenance' => $filter['maintenance'],
  340. 'withLastEventUnacknowledged' => 1,
  341. 'selectHosts' => API_OUTPUT_REFER,
  342. 'filter' => array(
  343. 'priority' => $filter['severity'],
  344. 'value' => TRIGGER_VALUE_TRUE
  345. ),
  346. 'output' => API_OUTPUT_REFER
  347. );
  348. $triggers_unack = API::Trigger()->get($options);
  349. $triggers_unack = zbx_toHash($triggers_unack, 'triggerid');
  350. foreach ($triggers_unack as $tunack) {
  351. foreach ($tunack['hosts'] as $unack_host) {
  352. $hosts_with_unack_triggers[$unack_host['hostid']] = $unack_host['hostid'];
  353. }
  354. }
  355. }
  356. $hosts_data = array();
  357. $problematic_host_list = array();
  358. $lastUnack_host_list = array();
  359. $highest_severity = array();
  360. $highest_severity2 = array();
  361. foreach ($triggers as $trigger) {
  362. foreach ($trigger['hosts'] as $trigger_host) {
  363. if (!isset($hosts[$trigger_host['hostid']])) {
  364. continue;
  365. }
  366. else {
  367. $host = $hosts[$trigger_host['hostid']];
  368. }
  369. if ($filter['extAck'] && isset($hosts_with_unack_triggers[$host['hostid']])) {
  370. if (!isset($lastUnack_host_list[$host['hostid']])) {
  371. $lastUnack_host_list[$host['hostid']] = array();
  372. $lastUnack_host_list[$host['hostid']]['host'] = $host['name'];
  373. $lastUnack_host_list[$host['hostid']]['hostid'] = $host['hostid'];
  374. $lastUnack_host_list[$host['hostid']]['severities'] = array();
  375. $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_DISASTER] = 0;
  376. $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_HIGH] = 0;
  377. $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_AVERAGE] = 0;
  378. $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_WARNING] = 0;
  379. $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_INFORMATION] = 0;
  380. $lastUnack_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_NOT_CLASSIFIED] = 0;
  381. }
  382. if (isset($triggers_unack[$trigger['triggerid']])) {
  383. $lastUnack_host_list[$host['hostid']]['severities'][$trigger['priority']]++;
  384. }
  385. foreach ($host['groups'] as $gnum => $group) {
  386. if (!isset($highest_severity2[$group['groupid']])) {
  387. $highest_severity2[$group['groupid']] = 0;
  388. }
  389. if ($trigger['priority'] > $highest_severity2[$group['groupid']]) {
  390. $highest_severity2[$group['groupid']] = $trigger['priority'];
  391. }
  392. if (!isset($hosts_data[$group['groupid']])) {
  393. $hosts_data[$group['groupid']] = array(
  394. 'problematic' => 0,
  395. 'ok' => 0,
  396. 'lastUnack' => 0,
  397. 'hostids_all' => array(),
  398. 'hostids_unack' => array()
  399. );
  400. }
  401. if (!isset($hosts_data[$group['groupid']]['hostids_unack'][$host['hostid']])) {
  402. $hosts_data[$group['groupid']]['hostids_unack'][$host['hostid']] = $host['hostid'];
  403. $hosts_data[$group['groupid']]['lastUnack']++;
  404. }
  405. }
  406. }
  407. if (!isset($problematic_host_list[$host['hostid']])) {
  408. $problematic_host_list[$host['hostid']] = array();
  409. $problematic_host_list[$host['hostid']]['host'] = $host['name'];
  410. $problematic_host_list[$host['hostid']]['hostid'] = $host['hostid'];
  411. $problematic_host_list[$host['hostid']]['severities'] = array();
  412. $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_DISASTER] = 0;
  413. $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_HIGH] = 0;
  414. $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_AVERAGE] = 0;
  415. $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_WARNING] = 0;
  416. $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_INFORMATION] = 0;
  417. $problematic_host_list[$host['hostid']]['severities'][TRIGGER_SEVERITY_NOT_CLASSIFIED] = 0;
  418. }
  419. $problematic_host_list[$host['hostid']]['severities'][$trigger['priority']]++;
  420. foreach ($host['groups'] as $gnum => $group) {
  421. if (!isset($highest_severity[$group['groupid']])) {
  422. $highest_severity[$group['groupid']] = 0;
  423. }
  424. if ($trigger['priority'] > $highest_severity[$group['groupid']]) {
  425. $highest_severity[$group['groupid']] = $trigger['priority'];
  426. }
  427. if (!isset($hosts_data[$group['groupid']])) {
  428. $hosts_data[$group['groupid']] = array(
  429. 'problematic' => 0,
  430. 'ok' => 0,
  431. 'lastUnack' => 0,
  432. 'hostids_all' => array(),
  433. 'hostids_unack' => array()
  434. );
  435. }
  436. if (!isset($hosts_data[$group['groupid']]['hostids_all'][$host['hostid']])) {
  437. $hosts_data[$group['groupid']]['hostids_all'][$host['hostid']] = $host['hostid'];
  438. $hosts_data[$group['groupid']]['problematic']++;
  439. }
  440. }
  441. }
  442. }
  443. foreach ($hosts as $host) {
  444. foreach ($host['groups'] as $group) {
  445. if (!isset($groups[$group['groupid']]['hosts'])) {
  446. $groups[$group['groupid']]['hosts'] = array();
  447. }
  448. $groups[$group['groupid']]['hosts'][$host['hostid']] = array('hostid' => $host['hostid']);
  449. if (!isset($highest_severity[$group['groupid']])) {
  450. $highest_severity[$group['groupid']] = 0;
  451. }
  452. if (!isset($hosts_data[$group['groupid']])) {
  453. $hosts_data[$group['groupid']] = array('problematic' => 0, 'ok' => 0, 'lastUnack' => 0);
  454. }
  455. if (!isset($problematic_host_list[$host['hostid']])) {
  456. $hosts_data[$group['groupid']]['ok']++;
  457. }
  458. }
  459. }
  460. foreach ($groups as $gnum => $group) {
  461. if (!isset($hosts_data[$group['groupid']])) {
  462. continue;
  463. }
  464. $group_row = new CRow();
  465. if (is_show_all_nodes()) {
  466. $group_row->addItem(get_node_name_by_elid($group['groupid']));
  467. }
  468. $name = new CLink($group['name'], 'tr_status.php?groupid='.$group['groupid'].'&hostid=0&show_triggers='.TRIGGERS_OPTION_ONLYTRUE);
  469. $group_row->addItem($name);
  470. $group_row->addItem(new CCol($hosts_data[$group['groupid']]['ok'], 'normal'));
  471. if ($filter['extAck']) {
  472. if ($hosts_data[$group['groupid']]['lastUnack']) {
  473. $table_inf = new CTableInfo();
  474. $table_inf->setAttribute('style', 'width: 400px;');
  475. $table_inf->setHeader(array(
  476. _('Host'),
  477. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_DISASTER]) ? getSeverityCaption(TRIGGER_SEVERITY_DISASTER) : null,
  478. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_HIGH]) ? getSeverityCaption(TRIGGER_SEVERITY_HIGH) : null,
  479. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_AVERAGE]) ? getSeverityCaption(TRIGGER_SEVERITY_AVERAGE) : null,
  480. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_WARNING]) ? getSeverityCaption(TRIGGER_SEVERITY_WARNING) : null,
  481. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_INFORMATION]) ? getSeverityCaption(TRIGGER_SEVERITY_INFORMATION) : null,
  482. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_NOT_CLASSIFIED]) ? getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED) : null
  483. ));
  484. $popup_rows = 0;
  485. foreach ($group['hosts'] as $host) {
  486. $hostid = $host['hostid'];
  487. if (!isset($lastUnack_host_list[$hostid])) {
  488. continue;
  489. }
  490. if ($popup_rows >= ZBX_WIDGET_ROWS) {
  491. break;
  492. }
  493. $popup_rows++;
  494. $host_data = $lastUnack_host_list[$hostid];
  495. $r = new CRow();
  496. $r->addItem(new CLink($host_data['host'], 'tr_status.php?groupid='.$group['groupid'].'&hostid='.$hostid.'&show_triggers='.TRIGGERS_OPTION_ONLYTRUE));
  497. foreach ($lastUnack_host_list[$host['hostid']]['severities'] as $severity => $trigger_count) {
  498. if (!is_null($filter['severity']) && !isset($filter['severity'][$severity])) {
  499. continue;
  500. }
  501. $r->addItem(new CCol($trigger_count, getSeverityStyle($severity, $trigger_count)));
  502. }
  503. $table_inf->addRow($r);
  504. }
  505. $lastUnack_count = new CSpan($hosts_data[$group['groupid']]['lastUnack'], 'pointer red bold');
  506. $lastUnack_count->setHint($table_inf);
  507. }
  508. else {
  509. $lastUnack_count = 0;
  510. }
  511. }
  512. // if hostgroup contains problematic hosts, hint should be built
  513. if ($hosts_data[$group['groupid']]['problematic']) {
  514. $table_inf = new CTableInfo();
  515. $table_inf->setAttribute('style', 'width: 400px;');
  516. $table_inf->setHeader(array(
  517. _('Host'),
  518. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_DISASTER]) ? getSeverityCaption(TRIGGER_SEVERITY_DISASTER) : null,
  519. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_HIGH]) ? getSeverityCaption(TRIGGER_SEVERITY_HIGH) : null,
  520. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_AVERAGE]) ? getSeverityCaption(TRIGGER_SEVERITY_AVERAGE) : null,
  521. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_WARNING]) ? getSeverityCaption(TRIGGER_SEVERITY_WARNING) : null,
  522. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_INFORMATION]) ? getSeverityCaption(TRIGGER_SEVERITY_INFORMATION) : null,
  523. is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_NOT_CLASSIFIED]) ? getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED) : null
  524. ));
  525. $popup_rows = 0;
  526. foreach ($group['hosts'] as $host) {
  527. $hostid = $host['hostid'];
  528. if (!isset($problematic_host_list[$hostid])) {
  529. continue;
  530. }
  531. if ($popup_rows >= ZBX_WIDGET_ROWS) {
  532. break;
  533. }
  534. $popup_rows++;
  535. $host_data = $problematic_host_list[$hostid];
  536. $r = new CRow();
  537. $r->addItem(new CLink($host_data['host'], 'tr_status.php?groupid='.$group['groupid'].'&hostid='.$hostid.'&show_triggers='.TRIGGERS_OPTION_ONLYTRUE));
  538. foreach ($problematic_host_list[$host['hostid']]['severities'] as $severity => $trigger_count) {
  539. if (!is_null($filter['severity'])&&!isset($filter['severity'][$severity])) {
  540. continue;
  541. }
  542. $r->addItem(new CCol($trigger_count, getSeverityStyle($severity, $trigger_count)));
  543. }
  544. $table_inf->addRow($r);
  545. }
  546. $problematic_count = new CSpan($hosts_data[$group['groupid']]['problematic'], 'pointer');
  547. $problematic_count->setHint($table_inf);
  548. }
  549. else {
  550. $problematic_count = 0;
  551. }
  552. switch ($filter['extAck']) {
  553. case EXTACK_OPTION_ALL:
  554. $group_row->addItem(new CCol(
  555. $problematic_count,
  556. getSeverityStyle($highest_severity[$group['groupid']], $hosts_data[$group['groupid']]['problematic']))
  557. );
  558. $group_row->addItem($hosts_data[$group['groupid']]['problematic'] + $hosts_data[$group['groupid']]['ok']);
  559. break;
  560. case EXTACK_OPTION_UNACK:
  561. $group_row->addItem(new CCol(
  562. $lastUnack_count,
  563. getSeverityStyle((isset($highest_severity2[$group['groupid']]) ? $highest_severity2[$group['groupid']] : 0),
  564. $hosts_data[$group['groupid']]['lastUnack']))
  565. );
  566. $group_row->addItem($hosts_data[$group['groupid']]['lastUnack'] + $hosts_data[$group['groupid']]['ok']);
  567. break;
  568. case EXTACK_OPTION_BOTH:
  569. $unackspan = $lastUnack_count ? new CSpan(array($lastUnack_count, SPACE._('of').SPACE)) : null;
  570. $group_row->addItem(new CCol(array(
  571. $unackspan, $problematic_count),
  572. getSeverityStyle($highest_severity[$group['groupid']], $hosts_data[$group['groupid']]['problematic']))
  573. );
  574. $group_row->addItem($hosts_data[$group['groupid']]['problematic'] + $hosts_data[$group['groupid']]['ok']);
  575. break;
  576. }
  577. $table->addRow($group_row);
  578. }
  579. $script = new CJSScript(get_js("jQuery('#hat_hoststat_footer').html('"._s('Updated: %s', zbx_date2str(_('H:i:s')))."')"));
  580. return new CDiv(array($table, $script));
  581. }
  582. function make_status_of_zbx() {
  583. global $ZBX_SERVER, $ZBX_SERVER_PORT;
  584. $table = new CTableInfo();
  585. $table->setHeader(array(
  586. _('Parameter'),
  587. _('Value'),
  588. _('Details')
  589. ));
  590. show_messages(); // because in function get_status(); function clear_messages() is called when fsockopen() fails.
  591. $status = get_status();
  592. $table->addRow(array(
  593. _('Zabbix server is running'),
  594. new CSpan($status['zabbix_server'], ($status['zabbix_server'] == _('Yes') ? 'off' : 'on')),
  595. isset($ZBX_SERVER, $ZBX_SERVER_PORT) ? $ZBX_SERVER.':'.$ZBX_SERVER_PORT : _('Zabbix server IP or port is not set!')
  596. ));
  597. $title = new CSpan(_('Number of hosts (monitored/not monitored/templates)'));
  598. $title->setAttribute('title', 'asdad');
  599. $table->addRow(array(_('Number of hosts (monitored/not monitored/templates)'), $status['hosts_count'],
  600. array(
  601. new CSpan($status['hosts_count_monitored'], 'off'), ' / ',
  602. new CSpan($status['hosts_count_not_monitored'], 'on'), ' / ',
  603. new CSpan($status['hosts_count_template'], 'unknown')
  604. )
  605. ));
  606. $title = new CSpan(_('Number of items (monitored/disabled/not supported)'));
  607. $title->setAttribute('title', _('Only items assigned to enabled hosts are counted'));
  608. $table->addRow(array($title, $status['items_count'],
  609. array(
  610. new CSpan($status['items_count_monitored'], 'off'), ' / ',
  611. new CSpan($status['items_count_disabled'], 'on'), ' / ',
  612. new CSpan($status['items_count_not_supported'], 'unknown')
  613. )
  614. ));
  615. $title = new CSpan(_('Number of triggers (enabled/disabled)[problem/unknown/ok]'));
  616. $title->setAttribute('title', _('Only triggers assigned to enabled hosts and depending on enabled items are counted'));
  617. $table->addRow(array($title, $status['triggers_count'],
  618. array(
  619. $status['triggers_count_enabled'], ' / ',
  620. $status['triggers_count_disabled'].SPACE.SPACE.'[',
  621. new CSpan($status['triggers_count_on'], 'on'), ' / ',
  622. new CSpan($status['triggers_count_unknown'], 'unknown'), ' / ',
  623. new CSpan($status['triggers_count_off'], 'off'), ']'
  624. )
  625. ));
  626. $table->addRow(array(_('Number of users (online)'), $status['users_count'], new CSpan($status['users_online'], 'green')));
  627. $table->addRow(array(_('Required server performance, new values per second'), $status['qps_total'], ' - '));
  628. // check requirements
  629. if (CWebUser::$data['type'] == USER_TYPE_SUPER_ADMIN) {
  630. $reqs = FrontendSetup::i()->checkRequirements();
  631. foreach ($reqs as $req) {
  632. if ($req['result'] == false) {
  633. $table->addRow(array(
  634. new CSpan($req['name'], 'red'),
  635. new CSpan($req['current'], 'red'),
  636. new CSpan($req['error'], 'red')
  637. ));
  638. }
  639. }
  640. }
  641. $script = new CJSScript(get_js("jQuery('#hat_stszbx_footer').html('"._s('Updated: %s', zbx_date2str(_('H:i:s')))."')"));
  642. return new CDiv(array($table, $script));
  643. }
  644. /**
  645. * Create and return a DIV with latest problem triggers
  646. * @author Aly
  647. * @param array $filter
  648. * @return CDiv
  649. */
  650. function make_latest_issues(array $filter = array()) {
  651. $config = select_config();
  652. $ackParams = array();
  653. if (!empty($filter['screenid'])) {
  654. $ackParams['screenid'] = $filter['screenid'];
  655. }
  656. $options = array(
  657. 'groupids' => $filter['groupids'],
  658. 'monitored' => true,
  659. 'maintenance' => $filter['maintenance'],
  660. 'skipDependent' => true,
  661. 'filter' => array(
  662. 'priority' => $filter['severity'],
  663. 'value' => TRIGGER_VALUE_TRUE
  664. ),
  665. 'selectHosts' => array('hostid', 'name'),
  666. 'output' => API_OUTPUT_EXTEND
  667. );
  668. $options['sortfield'] = isset($filter['sortfield']) ? $filter['sortfield'] : 'lastchange';
  669. $options['sortorder'] = isset($filter['sortorder']) ? $filter['sortorder'] : ZBX_SORT_DOWN;
  670. $options['limit'] = isset($filter['limit']) ? $filter['limit'] : DEFAULT_LATEST_ISSUES_CNT;
  671. if (isset($filter['hostids'])) {
  672. $options['hostids'] = $filter['hostids'];
  673. }
  674. $triggers = API::Trigger()->get($options);
  675. // how many issues are there at all with given parameters
  676. $options['countOutput'] = true;
  677. unset($options['limit']);
  678. $triggersTotalCount = API::Trigger()->get($options);
  679. foreach($triggers as $tnum => $trigger) {
  680. // if trigger is lost(broken expression) we skip it
  681. if (empty($trigger['hosts'])) {
  682. unset($triggers[$tnum]);
  683. continue;
  684. }
  685. $host = reset($trigger['hosts']);
  686. $trigger['hostid'] = $host['hostid'];
  687. $trigger['hostname'] = $host['name'];
  688. $triggers[$tnum] = $trigger;
  689. }
  690. $hostIds = zbx_objectValues($triggers, 'hostid');
  691. // fetch trigger hosts
  692. $hosts = API::Host()->get(array(
  693. 'hostids' => $hostIds,
  694. 'output' => array('hostid', 'name', 'maintenance_status', 'maintenance_type', 'maintenanceid'),
  695. 'selectInventory' => true,
  696. 'selectScreens' => API_OUTPUT_COUNT,
  697. 'preservekeys' => true
  698. ));
  699. // fetch trigger scripts
  700. $scripts_by_hosts = API::Script()->getScriptsByHosts($hostIds);
  701. // indicator of sort field
  702. $sortDiv = new CDiv(SPACE, $options['sortorder'] === ZBX_SORT_DOWN ? 'icon_sortdown default_cursor' : 'icon_sortup default_cursor');
  703. $sortDiv->addStyle('float: left');
  704. $hostHeaderDiv = new CDiv(array(_('Host'), SPACE));
  705. $hostHeaderDiv->addStyle('float: left');
  706. $issueHeaderDiv = new CDiv(array(_('Issue'), SPACE));
  707. $issueHeaderDiv->addStyle('float: left');
  708. $lastChangeHeaderDiv = new CDiv(array(_('Last change'), SPACE));
  709. $lastChangeHeaderDiv->addStyle('float: left');
  710. $table = new CTableInfo();
  711. $table->setHeader(
  712. array(
  713. is_show_all_nodes() ? _('Node') : null,
  714. $options['sortfield'] === 'hostname' ? array($hostHeaderDiv, $sortDiv) : _('Host'),
  715. $options['sortfield'] === 'priority' ? array($issueHeaderDiv, $sortDiv) : _('Issue'),
  716. $options['sortfield'] === 'lastchange' ? array($lastChangeHeaderDiv, $sortDiv) : _('Last change'),
  717. _('Age'),
  718. _('Info'),
  719. $config['event_ack_enable'] ? _('Ack') : null,
  720. _('Actions')
  721. )
  722. );
  723. foreach ($triggers as $trigger) {
  724. // check for dependencies
  725. $host = $hosts[$trigger['hostid']];
  726. // maintenance
  727. $trigger_host = $hosts[$trigger['hostid']];
  728. $text = null;
  729. $style = 'link_menu';
  730. if ($trigger_host['maintenance_status']) {
  731. $style .= ' orange';
  732. // get maintenance
  733. $maintenances = API::Maintenance()->get(array(
  734. 'maintenanceids' => $trigger_host['maintenanceid'],
  735. 'output' => API_OUTPUT_EXTEND
  736. ));
  737. $maintenance = reset($maintenances);
  738. $text = $maintenance['name'].' ['.($trigger_host['maintenance_type']
  739. ? _('Maintenance without data collection')
  740. : _('Maintenance with data collection')).']';
  741. }
  742. $hostSpan = new CSpan($host['name'], 'link_menu menu-host');
  743. $scripts = ($scripts_by_hosts[$host['hostid']]) ? $scripts_by_hosts[$host['hostid']] : array();
  744. $hostSpan->setAttribute('data-menu', hostMenuData($host, $scripts));
  745. if (!is_null($text)) {
  746. $hostSpan->setHint($text, '', '', false);
  747. }
  748. // unknown triggers
  749. $unknown = SPACE;
  750. if ($trigger['value_flags'] == TRIGGER_VALUE_FLAG_UNKNOWN) {
  751. $unknown = new CDiv(SPACE, 'status_icon iconunknown');
  752. $unknown->setHint($trigger['error'], '', 'on');
  753. }
  754. $events = API::Event()->get(array(
  755. 'output' => API_OUTPUT_EXTEND,
  756. 'select_acknowledges' => API_OUTPUT_EXTEND,
  757. 'triggerids' => $trigger['triggerid'],
  758. 'filter' => array(
  759. 'object' => EVENT_OBJECT_TRIGGER,
  760. 'value' => TRIGGER_VALUE_TRUE,
  761. 'value_changed' => TRIGGER_VALUE_CHANGED_YES
  762. ),
  763. 'sortfield' => array('object', 'objectid', 'eventid'),
  764. 'sortorder' => ZBX_SORT_DOWN,
  765. 'limit' => 1
  766. ));
  767. if ($event = reset($events)) {
  768. $ack = getEventAckState($event, true, true, $ackParams);
  769. $description = expand_trigger_description_by_data(zbx_array_merge($trigger, array('clock' => $event['clock'], 'ns' => $event['ns'])), ZBX_FLAG_EVENT);
  770. // actions
  771. $actions = get_event_actions_stat_hints($event['eventid']);
  772. $clock = new CLink(zbx_date2str(_('d M Y H:i:s'), $event['clock']), 'events.php?triggerid='.$trigger['triggerid'].'&source=0&show_unknown=1&nav_time='.$event['clock']);
  773. if ($trigger['url']) {
  774. $description = new CLink($description, resolveTriggerUrl($trigger), null, null, true);
  775. }
  776. else {
  777. $description = new CSpan($description, 'pointer');
  778. }
  779. $description = new CCol($description, getSeverityStyle($trigger['priority']));
  780. $description->setHint(make_popup_eventlist($event['eventid'], $trigger['type'], $trigger['triggerid']), '', '', false);
  781. $table->addRow(array(
  782. get_node_name_by_elid($trigger['triggerid']),
  783. $hostSpan,
  784. $description,
  785. $clock,
  786. zbx_date2age($event['clock']),
  787. $unknown,
  788. $ack,
  789. $actions
  790. ));
  791. }
  792. unset($trigger, $description, $actions);
  793. }
  794. // initialize blinking
  795. zbx_add_post_js('jqBlink.blink();');
  796. $script = new CJSScript(get_js("jQuery('#hat_lastiss_footer').html('"._s('Updated: %s', zbx_date2str(_('H:i:s')))."')"));
  797. $infoDiv = new CDiv(_n('%2$d of %1$d issue is shown', '%2$d of %1$d issues are shown', $triggersTotalCount, count($triggers)));
  798. $infoDiv->addStyle('text-align: right; padding-right: 3px;');
  799. $widgetDiv = new CDiv(array($table, $infoDiv, $script));
  800. return $widgetDiv;
  801. }
  802. function make_webmon_overview($filter) {
  803. $groups = API::HostGroup()->get(array(
  804. 'groupids' => $filter['groupids'],
  805. 'monitored_hosts' => true,
  806. 'with_monitored_httptests' => true,
  807. 'output' => array('groupid', 'name'),
  808. 'preservekeys' => true
  809. ));
  810. $availableHosts = API::Host()->get(array(
  811. 'groupids' => array_keys($groups),
  812. 'monitored_hosts' => true,
  813. 'filter' => array('maintenance_status' => $filter['maintenance']),
  814. 'output' => API_OUTPUT_SHORTEN,
  815. 'preservekeys' => true
  816. ));
  817. $availableHostIds = array_keys($availableHosts);
  818. $table = new CTableInfo();
  819. $table->setHeader(array(
  820. is_show_all_nodes() ? _('Node') : null,
  821. _('Host group'),
  822. _('Ok'),
  823. _('Failed'),
  824. _('Unknown')
  825. ));
  826. foreach ($groups as $group) {
  827. $showGroup = false;
  828. $okCount = 0;
  829. $failedCount = 0;
  830. $unknownCount = 0;
  831. $result = DBselect(
  832. 'SELECT DISTINCT ht.httptestid,i.lastclock,i.lastvalue'.
  833. ' FROM items i,httptestitem hti,httptest ht,applications a,hosts_groups hg'.
  834. ' WHERE i.itemid=hti.itemid'.
  835. ' AND hti.httptestid=ht.httptestid'.
  836. ' AND ht.applicationid=a.applicationid'.
  837. ' AND a.hostid=hg.hostid'.
  838. ' AND hti.type='.HTTPSTEP_ITEM_TYPE_LASTSTEP.
  839. ' AND ht.status='.HTTPTEST_STATUS_ACTIVE.
  840. ' AND '.DBcondition('hg.hostid', $availableHostIds).
  841. ' AND hg.groupid='.$group['groupid']
  842. );
  843. while ($row = DBfetch($result)) {
  844. $showGroup = true;
  845. if (!$row['lastclock']) {
  846. $unknownCount++;
  847. }
  848. elseif ($row['lastvalue'] != 0) {
  849. $failedCount++;
  850. }
  851. else {
  852. $okCount++;
  853. }
  854. }
  855. if ($showGroup) {
  856. $table->addRow(array(
  857. is_show_all_nodes() ? get_node_name_by_elid($group['groupid']) : null,
  858. $group['name'],
  859. new CSpan($okCount, 'off'),
  860. new CSpan($failedCount, $failedCount ? 'on' : 'off'),
  861. new CSpan($unknownCount, 'unknown')
  862. ));
  863. }
  864. }
  865. $script = new CJSScript(get_js("jQuery('#hat_webovr_footer').html('"._s('Updated: %s', zbx_date2str(_('H:i:s')))."')"));
  866. return new CDiv(array($table, $script));
  867. }
  868. function make_discovery_status() {
  869. $options = array(
  870. 'filter' => array('status' => DHOST_STATUS_ACTIVE),
  871. 'selectDHosts' => API_OUTPUT_EXTEND,
  872. 'output' => API_OUTPUT_EXTEND
  873. );
  874. $drules = API::DRule()->get($options);
  875. order_result($drules, 'name');
  876. foreach ($drules as $drnum => $drule) {
  877. $drules[$drnum]['up'] = 0;
  878. $drules[$drnum]['down'] = 0;
  879. foreach ($drule['dhosts'] as $dhost){
  880. if (DRULE_STATUS_DISABLED == $dhost['status']) {
  881. $drules[$drnum]['down']++;
  882. }
  883. else {
  884. $drules[$drnum]['up']++;
  885. }
  886. }
  887. }
  888. $header = array(
  889. is_show_all_nodes() ? new CCol(_('Node'), 'center') : null,
  890. new CCol(_('Discovery rule'), 'center'),
  891. new CCol(_x('Up', 'discovery results in dashboard')),
  892. new CCol(_x('Down', 'discovery results in dashboard'))
  893. );
  894. $table = new CTableInfo();
  895. $table->setHeader($header,'header');
  896. foreach ($drules as $drule) {
  897. $table->addRow(array(
  898. get_node_name_by_elid($drule['druleid']),
  899. new CLink(get_node_name_by_elid($drule['druleid'], null, ': ').$drule['name'], 'discovery.php?druleid='.$drule['druleid']),
  900. new CSpan($drule['up'], 'green'),
  901. new CSpan($drule['down'], ($drule['down'] > 0) ? 'red' : 'green')
  902. ));
  903. }
  904. $script = new CJSScript(get_js("jQuery('#hat_dscvry_footer').html('"._s('Updated: %s', zbx_date2str(_('H:i:s')))."')"));
  905. return new CDiv(array($table, $script));
  906. }
  907. function make_graph_menu(&$menu, &$submenu) {
  908. $menu['menu_graphs'][] = array(
  909. _('Favourite graphs'),
  910. null,
  911. null,
  912. array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))
  913. );
  914. $menu['menu_graphs'][] = array(
  915. _('Add').' '._('Graph'),
  916. 'javascript: PopUp(\'popup.php?srctbl=graphs&srcfld1=graphid&reference=graphid&monitored_hosts=1&multiselect=1\',800,450); void(0);',
  917. null,
  918. array('outer' => 'pum_o_submenu', 'inner' => array('pum_i_submenu'))
  919. );
  920. $menu['menu_graphs'][] = array(
  921. _('Add').' '._('Simple graph'),
  922. 'javascript: PopUp(\'popup.php?srctbl=simple_graph&srcfld1=itemid&monitored_hosts=1&reference=itemid&multiselect=1\',800,450); void(0);',
  923. null,
  924. array('outer' => 'pum_o_submenu', 'inner' => array('pum_i_submenu'))
  925. );
  926. $menu['menu_graphs'][] = array(
  927. _('Remove'),
  928. null,
  929. null,
  930. array('outer' => 'pum_o_submenu', 'inner' => array('pum_i_submenu'))
  931. );
  932. $submenu['menu_graphs'] = make_graph_submenu();
  933. }
  934. function make_graph_submenu() {
  935. $graphids = array();
  936. $itemids = array();
  937. $fav_graphs = get_favorites('web.favorite.graphids');
  938. foreach ($fav_graphs as $key => $favorite) {
  939. if ('itemid' == $favorite['source']) {
  940. $itemids[$favorite['value']] = $favorite['value'];
  941. }
  942. else {
  943. $graphids[$favorite['value']] = $favorite['value'];
  944. }
  945. }
  946. $options = array(
  947. 'graphids' => $graphids,
  948. 'selectHosts' => array('hostid', 'host'),
  949. 'output' => API_OUTPUT_EXTEND
  950. );
  951. $graphs = API::Graph()->get($options);
  952. $graphs = zbx_toHash($graphs, 'graphid');
  953. $options = array(
  954. 'itemids' => $itemids,
  955. 'selectHosts' => array('hostid', 'host'),
  956. 'filter' => array('flags' => array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)),
  957. 'output' => API_OUTPUT_EXTEND,
  958. 'webitems' => 1
  959. );
  960. $items = API::Item()->get($options);
  961. $items = zbx_toHash($items, 'itemid');
  962. $favGraphs = array();
  963. foreach ($fav_graphs as $favorite) {
  964. $source = $favorite['source'];
  965. $sourceid = $favorite['value'];
  966. if ('itemid' == $source) {
  967. if (!isset($items[$sourceid])) {
  968. continue;
  969. }
  970. $item_added = true;
  971. $item = $items[$sourceid];
  972. $host = reset($item['hosts']);
  973. $item['name'] = itemName($item);
  974. $favGraphs[] = array(
  975. 'name' => $host['host'].':'.$item['name'],
  976. 'favobj' => 'itemid',
  977. 'favid' => $sourceid,
  978. 'favaction' => 'remove'
  979. );
  980. }
  981. else {
  982. if (!isset($graphs[$sourceid])) {
  983. continue;
  984. }
  985. $graph_added = true;
  986. $graph = $graphs[$sourceid];
  987. $ghost = reset($graph['hosts']);
  988. $favGraphs[] = array(
  989. 'name' => $ghost['host'].':'.$graph['name'],
  990. 'favobj' => 'graphid',
  991. 'favid' => $sourceid,
  992. 'favaction' => 'remove'
  993. );
  994. }
  995. }
  996. if (isset($graph_added)) {
  997. $favGraphs[] = array(
  998. 'name' => _('Remove').' '._('All').' '._('Graphs'),
  999. 'favobj' => 'graphid',
  1000. 'favid' => 0,
  1001. 'favaction' => 'remove'
  1002. );
  1003. }
  1004. if (isset($item_added)) {
  1005. $favGraphs[] = array(
  1006. 'name' => _('Remove').' '._('All').' '._('Simple graphs'),
  1007. 'favobj' => 'itemid',
  1008. 'favid' => 0,
  1009. 'favaction' => 'remove'
  1010. );
  1011. }
  1012. return $favGraphs;
  1013. }
  1014. function make_sysmap_menu(&$menu, &$submenu) {
  1015. $menu['menu_sysmaps'][] = array(_('Favourite maps'), null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader')));
  1016. $menu['menu_sysmaps'][] = array(
  1017. _('Add').' '._('Map'),
  1018. 'javascript: PopUp(\'popup.php?srctbl=sysmaps&srcfld1=sysmapid&reference=sysmapid&multiselect=1\',800,450); void(0);',
  1019. null,
  1020. array('outer' => 'pum_o_submenu', 'inner' => array('pum_i_submenu')
  1021. ));
  1022. $menu['menu_sysmaps'][] = array(_('Remove'), null, null, array('outer' => 'pum_o_submenu', 'inner' => array('pum_i_submenu')));
  1023. $submenu['menu_sysmaps'] = make_sysmap_submenu();
  1024. }
  1025. function make_sysmap_submenu() {
  1026. $fav_sysmaps = get_favorites('web.favorite.sysmapids');
  1027. $favMaps = array();
  1028. $sysmapids = array();
  1029. foreach ($fav_sysmaps as $favorite) {
  1030. $sysmapids[$favorite['value']] = $favorite['value'];
  1031. }
  1032. $options = array(
  1033. 'sysmapids' => $sysmapids,
  1034. 'output' => API_OUTPUT_EXTEND
  1035. );
  1036. $sysmaps = API::Map()->get($options);
  1037. foreach ($sysmaps as $sysmap) {
  1038. $favMaps[] = array(
  1039. 'name' => $sysmap['name'],
  1040. 'favobj' => 'sysmapid',
  1041. 'favid' => $sysmap['sysmapid'],
  1042. 'favaction' => 'remove'
  1043. );
  1044. }
  1045. if (!empty($favMaps)) {
  1046. $favMaps[] = array(
  1047. 'name' => _('Remove').' '._('All').' '._('Maps'),
  1048. 'favobj' => 'sysmapid',
  1049. 'favid' => 0,
  1050. 'favaction' => 'remove'
  1051. );
  1052. }
  1053. return $favMaps;
  1054. }
  1055. function make_screen_menu(&$menu, &$submenu) {
  1056. $menu['menu_screens'][] = array(_('Favourite screens'), null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader')));
  1057. $menu['menu_screens'][] = array(
  1058. _('Add').' '._('Screen'),
  1059. 'javascript: PopUp(\'popup.php?srctbl=screens&srcfld1=screenid&reference=screenid&multiselect=1\', 800, 450); void(0);',
  1060. null,
  1061. array('outer' => 'pum_o_submenu', 'inner' => array('pum_i_submenu')
  1062. ));
  1063. $menu['menu_screens'][] = array(
  1064. _('Add').' '._('Slide show'),
  1065. 'javascript: PopUp(\'popup.php?srctbl=slides&srcfld1=slideshowid&reference=slideshowid&multiselect=1\', 800, 450); void(0);',
  1066. null,
  1067. array('outer' => 'pum_o_submenu', 'inner' => array('pum_i_submenu')
  1068. ));
  1069. $menu['menu_screens'][] = array(_('Remove'), null, null, array('outer' => 'pum_o_submenu', 'inner' => array('pum_i_submenu')));
  1070. $submenu['menu_screens'] = make_screen_submenu();
  1071. }
  1072. function make_screen_submenu() {
  1073. $fav_screens = get_favorites('web.favorite.screenids');
  1074. $screenids = array();
  1075. foreach ($fav_screens as $favorite) {
  1076. if ('screenid' == $favorite['source']) {
  1077. $screenids[$favorite['value']] = $favorite['value'];
  1078. }
  1079. }
  1080. $options = array(
  1081. 'screenids' => $screenids,
  1082. 'output' => API_OUTPUT_EXTEND
  1083. );
  1084. $screens = API::Screen()->get($options);
  1085. $screens = zbx_toHash($screens, 'screenid');
  1086. $favScreens = array();
  1087. foreach ($fav_screens as $favorite) {
  1088. $source = $favorite['source'];
  1089. $sourceid = $favorite['value'];
  1090. if ('slideshowid' == $source) {
  1091. if (!slideshow_accessible($sourceid, PERM_READ_ONLY)) {
  1092. continue;
  1093. }
  1094. if (!$slide = get_slideshow_by_slideshowid($sourceid)) {
  1095. continue;
  1096. }
  1097. $slide_added = true;
  1098. $favScreens[] = array(
  1099. 'name' => $slide['name'],
  1100. 'favobj' => 'slideshowid',
  1101. 'favid' => $slide['slideshowid'],
  1102. 'favaction' => 'remove'
  1103. );
  1104. }
  1105. else {
  1106. if (!isset($screens[$sourceid])) {
  1107. continue;
  1108. }
  1109. $screen = $screens[$sourceid];
  1110. $screen_added = true;
  1111. $favScreens[] = array(
  1112. 'name' => $screen['name'],
  1113. 'favobj' => 'screenid',
  1114. 'favid' => $screen['screenid'],
  1115. 'favaction' => 'remove'
  1116. );
  1117. }
  1118. }
  1119. if (isset($screen_added)) {
  1120. $favScreens[] = array(
  1121. 'name' => _('Remove').' '._('All').' '._('Screens'),
  1122. 'favobj' => 'screenid',
  1123. 'favid' => 0,
  1124. 'favaction' => 'remove'
  1125. );
  1126. }
  1127. if (isset($slide_added)) {
  1128. $favScreens[] = array(
  1129. 'name' => _('Remove').' '._('All').' '._('Slides'),
  1130. 'favobj' => 'slideshowid',
  1131. 'favid' => 0,
  1132. 'favaction' => 'remove'
  1133. );
  1134. }
  1135. return $favScreens;
  1136. }
  1137. /**
  1138. * Generate table for dashboard triggers popup.
  1139. *
  1140. * @see make_system_status
  1141. *
  1142. * @param array $triggers
  1143. * @param array $ackParams
  1144. *
  1145. * @return CTableInfo
  1146. */
  1147. function makeTriggersPopup(array $triggers, array $ackParams) {
  1148. $config = select_config();
  1149. $popupTable = new CTableInfo();
  1150. $popupTable->setAttribute('style', 'width: 400px;');
  1151. $popupTable->setHeader(array(
  1152. is_show_all_nodes() ? _('Node') : null,
  1153. _('Host'),
  1154. _('Issue'),
  1155. _('Age'),
  1156. _('Info'),
  1157. $config['event_ack_enable'] ? _('Ack') : null,
  1158. _('Actions')
  1159. ));
  1160. foreach ($triggers as $trigger) {
  1161. $event = $trigger['event'];
  1162. $ack = getEventAckState($event, true, true, $ackParams);
  1163. if (isset($event['eventid'])) {
  1164. $actions = get_event_actions_status($event['eventid']);
  1165. }
  1166. else {
  1167. $actions = _('no data');
  1168. }
  1169. // unknown triggers
  1170. $unknown = SPACE;
  1171. if ($trigger['value_flags'] == TRIGGER_VALUE_FLAG_UNKNOWN) {
  1172. $unknown = new CDiv(SPACE, 'status_icon iconunknown');
  1173. $unknown->setHint($trigger['error'], '', 'on');
  1174. }
  1175. $trigger['hostname'] = $trigger['hosts'][0]['name'];
  1176. $popupTable->addRow(array(
  1177. get_node_name_by_elid($trigger['triggerid']),
  1178. $trigger['hostname'],
  1179. getSeverityCell($trigger['priority'], $trigger['description']),
  1180. zbx_date2age($event['clock']),
  1181. $unknown,
  1182. $config['event_ack_enable'] ? $ack : null,
  1183. $actions
  1184. ));
  1185. }
  1186. return $popupTable;
  1187. }