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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
|
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
function italic($str) {
if (is_array($str)) {
foreach ($str as $key => $val) {
if (is_string($val)) {
$em = new CTag('em', true);
$em->addItem($val);
$str[$key] = $em;
}
}
}
elseif (is_string($str)) {
$em = new CTag('em', true, '');
$em->addItem($str);
$str = $em;
}
return $str;
}
function bold($str) {
if (is_array($str)) {
foreach ($str as $key => $val) {
if (is_string($val)) {
$str[$key] = new CTag('b', true, $val);
}
}
return $str;
}
return new CTag('b', true, $str);
}
function make_decoration($haystack, $needle, $class = null) {
$result = $haystack;
$tmpHaystack = mb_strtolower($haystack);
$tmpNeedle = mb_strtolower($needle);
$pos = mb_strpos($tmpHaystack, $tmpNeedle);
if ($pos !== false) {
$start = mb_substr($haystack, 0, $pos);
$end = mb_substr($haystack, $pos + mb_strlen($needle));
$found = mb_substr($haystack, $pos, mb_strlen($needle));
if (is_null($class)) {
$result = [$start, bold($found), $end];
}
else {
$result = [$start, (new CSpan($found))->addClass($class), $end];
}
}
return $result;
}
function prepareUrlParam($value, $name = null): string {
if (is_array($value)) {
$result = '';
foreach ($value as $key => $param) {
$result .= prepareUrlParam($param, isset($name) ? $name.'['.$key.']' : $key);
}
}
else {
$result = '&'.$name.'='.urlencode($value);
}
return $result;
}
/**
* Get ready for url params.
*
* @param mixed $param Param name or array with data depends from $getFromRequest.
* @param bool $getFromRequest Detect data source - input array or $_REQUEST variable.
* @param string|null $name If $_REQUEST variable is used this variable not used.
*/
function url_param($param, bool $getFromRequest = true, ?string $name = null): string {
if (is_array($param)) {
if ($getFromRequest) {
fatal_error(_('URL parameter cannot be array.'));
}
}
elseif ($name === null) {
if (!$getFromRequest) {
fatal_error(_('URL parameter name is empty.'));
}
$name = $param;
}
if ($getFromRequest) {
$value =& $_REQUEST[$param];
}
else {
$value =& $param;
}
return isset($value) ? prepareUrlParam($value, $name) : '';
}
function url_params(array $params): string {
$result = '';
foreach ($params as $param) {
$result .= url_param($param);
}
return $result;
}
function BR(): CTag {
return new CTag('br');
}
function BULLET() {
return new CHtmlEntity('•');
}
function COPYR() {
return new CHtmlEntity('©');
}
function HELLIP() {
return new CHtmlEntity('…');
}
function LARR() {
return new CHtmlEntity('⇐');
}
function NBSP() {
return new CHtmlEntity(' ');
}
function NDASH() {
return new CHtmlEntity('–');
}
function RARR() {
return new CHtmlEntity('⇒');
}
function get_icon($type, $params = []): ?CSimpleButton {
switch ($type) {
case 'favorite':
if (CFavorite::exists($params['fav'], $params['elid'], $params['elname'])) {
$icon = (new CSimpleButton())
->addClass(ZBX_ICON_STAR_FILLED)
->setTitle(_('Remove from favorites'))
->onClick('rm4favorites("'.$params['elname'].'", "'.$params['elid'].'");');
}
else {
$icon = (new CSimpleButton())
->addClass(ZBX_ICON_STAR)
->setTitle(_('Add to favorites'))
->onClick('add2favorites("'.$params['elname'].'", "'.$params['elid'].'");');
}
$icon->setId('addrm_fav');
return $icon;
case 'kioskmode':
if ($params['mode'] == ZBX_LAYOUT_KIOSKMODE) {
$icon = (new CSimpleButton())
->addClass(ZBX_LAYOUT_MODE)
->addClass(ZBX_ICON_MINIMIZE)
->addClass(ZBX_STYLE_BTN_DASHBOARD_NORMAL)
->setTitle(_('Normal view'))
->setAttribute('data-layout-mode', ZBX_LAYOUT_NORMAL);
}
else {
$icon = (new CSimpleButton())
->addClass(ZBX_LAYOUT_MODE)
->addClass(ZBX_ICON_FULLSCREEN)
->addClass(ZBX_STYLE_BTN_KIOSK)
->setTitle(_('Kiosk mode'))
->setAttribute('data-layout-mode', ZBX_LAYOUT_KIOSKMODE);
}
return $icon;
}
return null;
}
/**
* Get host/template configuration navigation.
*
* @param string $current_element
* @param int $hostid
* @param int $lld_ruleid
*
* @throws Exception
*/
function getHostNavigation(string $current_element, $hostid, $lld_ruleid = 0): ?CList {
$options = [
'output' => [
'hostid', 'status', 'name', 'maintenance_status', 'flags', 'active_available'
],
'selectHostDiscovery' => ['status', 'ts_delete', 'ts_disable', 'disable_source'],
'selectDiscoveryRule' => ['lifetime_type', 'enabled_lifetime_type'],
'selectInterfaces' => ['interfaceid', 'type', 'useip', 'ip', 'dns', 'port', 'version', 'details', 'available',
'error'
],
'hostids' => [$hostid],
'editable' => true
];
if ($lld_ruleid == 0) {
$options['selectItems'] = API_OUTPUT_COUNT;
$options['selectTriggers'] = API_OUTPUT_COUNT;
$options['selectGraphs'] = API_OUTPUT_COUNT;
$options['selectDiscoveries'] = API_OUTPUT_COUNT;
$options['selectHttpTests'] = API_OUTPUT_COUNT;
}
// get hosts
$db_host = API::Host()->get($options);
if (!$db_host) {
$options = [
'output' => ['templateid', 'name', 'flags'],
'templateids' => [$hostid],
'editable' => true
];
if ($lld_ruleid == 0) {
$options['selectItems'] = API_OUTPUT_COUNT;
$options['selectTriggers'] = API_OUTPUT_COUNT;
$options['selectGraphs'] = API_OUTPUT_COUNT;
$options['selectDashboards'] = API_OUTPUT_COUNT;
$options['selectDiscoveries'] = API_OUTPUT_COUNT;
$options['selectHttpTests'] = API_OUTPUT_COUNT;
}
// get templates
$db_host = API::Template()->get($options);
$is_template = true;
}
else {
$is_template = false;
}
if (!$db_host) {
return null;
}
$db_host = reset($db_host);
if (!$is_template) {
$interface_enabled_items_count = getEnabledItemsCountByInterfaceIds(
array_column($db_host['interfaces'], 'interfaceid')
);
foreach ($db_host['interfaces'] as &$interface) {
$interfaceid = $interface['interfaceid'];
$interface['has_enabled_items'] = array_key_exists($interfaceid, $interface_enabled_items_count)
&& $interface_enabled_items_count[$interfaceid] > 0;
}
unset($interface);
if (getEnabledItemTypeCountByHostId(ITEM_TYPE_ZABBIX_ACTIVE, [$hostid])) {
// Add active checks interface if host have items with type ITEM_TYPE_ZABBIX_ACTIVE (7).
$db_host['interfaces'][] = [
'type' => INTERFACE_TYPE_AGENT_ACTIVE,
'available' => $db_host['active_available'],
'has_enabled_items' => true,
'error' => ''
];
unset($db_host['active_available']);
}
}
// get lld-rules
if ($lld_ruleid != 0) {
$db_discovery_rule = API::DiscoveryRule()->get([
'output' => ['name'],
'selectItems' => API_OUTPUT_COUNT,
'selectTriggers' => API_OUTPUT_COUNT,
'selectGraphs' => API_OUTPUT_COUNT,
'selectHostPrototypes' => API_OUTPUT_COUNT,
'itemids' => [$lld_ruleid],
'editable' => true
]);
$db_discovery_rule = reset($db_discovery_rule);
}
$list = new CList();
if ($is_template) {
$template = new CSpan(
(new CLink($db_host['name']))
->setAttribute('data-templateid', $db_host['templateid'])
->onClick('view.editTemplate(event, this.dataset.templateid);')
);
if ($current_element === '') {
$template->addClass(ZBX_STYLE_SELECTED);
}
$list->addItem(new CBreadcrumbs([
new CSpan(new CLink(_('All templates'), (new CUrl('zabbix.php'))->setArgument('action', 'template.list'))),
$template
]));
$db_host['hostid'] = $db_host['templateid'];
}
else {
switch ($db_host['status']) {
case HOST_STATUS_MONITORED:
if ($db_host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) {
$status = (new CSpan(_('In maintenance')))->addClass(ZBX_STYLE_ORANGE);
}
else {
$status = (new CSpan(_('Enabled')))->addClass(ZBX_STYLE_GREEN);
}
break;
case HOST_STATUS_NOT_MONITORED:
$status = (new CSpan(_('Disabled')))->addClass(ZBX_STYLE_RED);
break;
default:
$status = (new CSpan(_('Unknown')))->addClass(ZBX_STYLE_GREY);
break;
}
$host = new CSpan(
(new CLink($db_host['name'],
(new CUrl('zabbix.php'))
->setArgument('action', 'host.edit')
->setArgument('hostid', $db_host['hostid'])
))
->setAttribute('data-hostid', $db_host['hostid'])
->onClick('view.editHost(event, this.dataset.hostid);')
);
if ($current_element === '') {
$host->addClass(ZBX_STYLE_SELECTED);
}
$list
->addItem(new CBreadcrumbs([new CSpan(new CLink(_('All hosts'),
(new CUrl('zabbix.php'))->setArgument('action', 'host.list'))), $host
]))
->addItem($status)
->addItem(getHostAvailabilityTable($db_host['interfaces']));
$disable_source = $db_host['status'] == HOST_STATUS_NOT_MONITORED && $db_host['hostDiscovery']
? $db_host['hostDiscovery']['disable_source']
: '';
if ($db_host['flags'] == ZBX_FLAG_DISCOVERY_CREATED
&& $db_host['hostDiscovery']['status'] == ZBX_LLD_STATUS_LOST) {
$info_icons = [getLldLostEntityIndicator(time(), $db_host['hostDiscovery']['ts_delete'],
$db_host['hostDiscovery']['ts_disable'], $disable_source,
$db_host['status'] == HOST_STATUS_NOT_MONITORED, _('host')
)];
$list->addItem(makeInformationList($info_icons));
}
}
$content_menu = (new CList())
->setAttribute('role', 'navigation')
->setAttribute('aria-label', _('Content menu'));
$context = $is_template ? 'template' : 'host';
/*
* the count of rows
*/
if ($lld_ruleid == 0) {
// items
$items = new CSpan([
new CLink(_('Items'),
(new CUrl('zabbix.php'))
->setArgument('action', 'item.list')
->setArgument('filter_set', '1')
->setArgument('filter_hostids', [$db_host['hostid']])
->setArgument('context', $context)
),
CViewHelper::showNum($db_host['items'])
]);
if ($current_element === 'items') {
$items->addClass(ZBX_STYLE_SELECTED);
}
$content_menu->addItem($items);
// triggers
$triggers = new CSpan([
new CLink(_('Triggers'),
(new CUrl('zabbix.php'))
->setArgument('action', 'trigger.list')
->setArgument('filter_set', '1')
->setArgument('filter_hostids', [$db_host['hostid']])
->setArgument('context', $context)
),
CViewHelper::showNum($db_host['triggers'])
]);
if ($current_element === 'triggers') {
$triggers->addClass(ZBX_STYLE_SELECTED);
}
$content_menu->addItem($triggers);
// graphs
$graphs = new CSpan([
new CLink(_('Graphs'), (new CUrl('graphs.php'))
->setArgument('filter_set', '1')
->setArgument('filter_hostids', [$db_host['hostid']])
->setArgument('context', $context)
),
CViewHelper::showNum($db_host['graphs'])
]);
if ($current_element === 'graphs') {
$graphs->addClass(ZBX_STYLE_SELECTED);
}
$content_menu->addItem($graphs);
// Dashboards
if ($is_template) {
$dashboards = new CSpan([
new CLink(_('Dashboards'),
(new CUrl('zabbix.php'))
->setArgument('action', 'template.dashboard.list')
->setArgument('templateid', $db_host['hostid'])
),
CViewHelper::showNum($db_host['dashboards'])
]);
if ($current_element === 'dashboards') {
$dashboards->addClass(ZBX_STYLE_SELECTED);
}
$content_menu->addItem($dashboards);
}
// discovery rules
$lld_rules = new CSpan([
new CLink(_('Discovery rules'), (new CUrl('host_discovery.php'))
->setArgument('filter_set', '1')
->setArgument('filter_hostids', [$db_host['hostid']])
->setArgument('context', $context)
),
CViewHelper::showNum($db_host['discoveries'])
]);
if ($current_element === 'discoveries') {
$lld_rules->addClass(ZBX_STYLE_SELECTED);
}
$content_menu->addItem($lld_rules);
// web scenarios
$http_tests = new CSpan([
new CLink(_('Web scenarios'),
(new CUrl('httpconf.php'))
->setArgument('filter_set', '1')
->setArgument('filter_hostids', [$db_host['hostid']])
->setArgument('context', $context)
),
CViewHelper::showNum($db_host['httpTests'])
]);
if ($current_element === 'web') {
$http_tests->addClass(ZBX_STYLE_SELECTED);
}
$content_menu->addItem($http_tests);
}
else {
$discovery_rule = (new CSpan())->addItem(
new CLink(
$db_discovery_rule['name'],
(new CUrl('host_discovery.php'))
->setArgument('form', 'update')
->setArgument('itemid', $db_discovery_rule['itemid'])
->setArgument('context', $context)
)
);
if ($current_element === 'discoveries') {
$discovery_rule->addClass(ZBX_STYLE_SELECTED);
}
$list->addItem(new CBreadcrumbs([
(new CSpan())->addItem(new CLink(_('Discovery list'),
(new CUrl('host_discovery.php'))
->setArgument('filter_set', '1')
->setArgument('filter_hostids', [$db_host['hostid']])
->setArgument('context', $context)
)),
$discovery_rule
]));
// item prototypes
$item_prototypes = new CSpan([
new CLink(_('Item prototypes'),
(new CUrl('zabbix.php'))
->setArgument('action', 'item.prototype.list')
->setArgument('parent_discoveryid', $db_discovery_rule['itemid'])
->setArgument('context', $context)
),
CViewHelper::showNum($db_discovery_rule['items'])
]);
if ($current_element === 'items') {
$item_prototypes->addClass(ZBX_STYLE_SELECTED);
}
$content_menu->addItem($item_prototypes);
// trigger prototypes
$trigger_prototypes = new CSpan([
new CLink(_('Trigger prototypes'),
(new CUrl('zabbix.php'))
->setArgument('action', 'trigger.prototype.list')
->setArgument('parent_discoveryid', $db_discovery_rule['itemid'])
->setArgument('context', $context)
),
CViewHelper::showNum($db_discovery_rule['triggers'])
]);
if ($current_element === 'triggers') {
$trigger_prototypes->addClass(ZBX_STYLE_SELECTED);
}
$content_menu->addItem($trigger_prototypes);
// graph prototypes
$graph_prototypes = new CSpan([
new CLink(_('Graph prototypes'),
(new CUrl('graphs.php'))
->setArgument('parent_discoveryid', $db_discovery_rule['itemid'])
->setArgument('context', $context)
),
CViewHelper::showNum($db_discovery_rule['graphs'])
]);
if ($current_element === 'graphs') {
$graph_prototypes->addClass(ZBX_STYLE_SELECTED);
}
$content_menu->addItem($graph_prototypes);
// host prototypes
if ($db_host['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
$host_prototypes = new CSpan([
new CLink(_('Host prototypes'),
(new CUrl('host_prototypes.php'))
->setArgument('parent_discoveryid', $db_discovery_rule['itemid'])
->setArgument('context', $context)
),
CViewHelper::showNum($db_discovery_rule['hostPrototypes'])
]);
if ($current_element === 'hosts') {
$host_prototypes->addClass(ZBX_STYLE_SELECTED);
}
$content_menu->addItem($host_prototypes);
}
}
$list->addItem($content_menu);
return $list;
}
/**
* Get map navigation.
*
* @param int $sysmapid Used as value for sysmapid in map link generation.
* @param string $name Used as label for map link generation.
* @param int $severity_min Used as value for severity_min in map link generation.
*/
function getSysmapNavigation($sysmapid, $name, $severity_min): CList {
$list = (new CList())->addItem(new CBreadcrumbs([
(new CSpan())->addItem(new CLink(_('All maps'), new CUrl('sysmaps.php'))),
(new CSpan())
->addClass(ZBX_STYLE_SELECTED)
->addItem(new CLink($name,
(new CUrl('zabbix.php'))
->setArgument('action', 'map.view')
->setArgument('sysmapid', $sysmapid)
->setArgument('severity_min', $severity_min)
))
]));
// get map parent maps
$parent_sysmaps = get_parent_sysmaps($sysmapid);
if ($parent_sysmaps) {
$parent_maps = (new CList())
->setAttribute('aria-label', _('Upper level maps'))
->addItem((new CSpan())->addItem(_('Upper level maps').':'));
foreach ($parent_sysmaps as $parent_sysmap) {
$parent_maps->addItem((new CSpan())->addItem(new CLink($parent_sysmap['name'],
(new CUrl('zabbix.php'))
->setArgument('action', 'map.view')
->setArgument('sysmapid', $parent_sysmap['sysmapid'])
->setArgument('severity_min', $severity_min)
)));
}
$list->addItem($parent_maps);
}
return $list;
}
/**
* Renders a form footer with the given buttons.
*
* @param CButtonInterface|null $main_button Main button that will be displayed on the left.
* @param CButtonInterface[] $other_buttons
*
* @throws InvalidArgumentException if an element of $other_buttons contain something other than CButtonInterface
*/
function makeFormFooter(?CButtonInterface $main_button = null, array $other_buttons = []): CList {
foreach ($other_buttons as $other_button) {
$other_button->addClass(ZBX_STYLE_BTN_ALT);
}
if ($main_button !== null) {
array_unshift($other_buttons, $main_button);
}
return (new CList())
->addClass(ZBX_STYLE_TABLE_FORMS)
->addItem([
(new CDiv())->addClass(ZBX_STYLE_TABLE_FORMS_TD_LEFT),
(new CDiv($other_buttons))
->addClass(ZBX_STYLE_TABLE_FORMS_TD_RIGHT)
->addClass('tfoot-buttons')
]);
}
/**
* Create HTML helper element for host interfaces availability.
*
* @param array $host_interfaces
*
* @return CHostAvailability
*/
function getHostAvailabilityTable(array $host_interfaces): CHostAvailability {
$interfaces = [];
foreach ($host_interfaces as $interface) {
$description = null;
if ($interface['type'] == INTERFACE_TYPE_SNMP) {
$description = getSnmpInterfaceDescription($interface);
}
$interfaces[] = [
'type' => $interface['type'],
'available' => $interface['available'],
'interface' => getHostInterface($interface),
'has_enabled_items' => $interface['has_enabled_items'],
'description' => $description,
'error' => $interface['available'] == INTERFACE_AVAILABLE_TRUE ? '' : $interface['error']
];
}
return (new CHostAvailability())
->setInterfaces($interfaces);
}
/**
* Returns the discovered host group lifetime indicator.
*
* @param int $current_time Current Unix timestamp.
* @param int $ts_delete Deletion timestamp of the host group.
*
* @throws Exception
*/
function getHostGroupLifetimeIndicator(int $current_time, int $ts_delete): CSimpleButton {
// Check if the element should've been deleted in the past.
if ($current_time > $ts_delete) {
$warning = _s('The %1$s is not discovered anymore and %2$s.', _('host group'),
_('will be deleted the next time discovery rule is processed')
);
}
else {
$warning = _s('The %1$s is not discovered anymore and %2$s.', _('host group'),
_s('will be deleted in %1$s', zbx_date2age($current_time, $ts_delete))
);
}
return makeWarningIcon($warning);
}
/**
* Returns the indicator for lost LLD entity.
*
* @param int $current_time Current Unix timestamp.
* @param int $ts_delete Deletion timestamp of the entity.
* @param int $ts_disable Disabling timestamp of the entity.
* @param string $disable_source Indicator whether entity was disabled by an LLD rule or manually.
* @param boolean $disabled Indicator whether entity is disabled.
* @param string $entity Type of entity.
*
* @throws Exception
*/
function getLldLostEntityIndicator(int $current_time, int $ts_delete, int $ts_disable, string $disable_source,
bool $disabled, string $entity): ?CSimpleButton {
$warning = '';
if ($disable_source == ZBX_DISABLE_SOURCE_LLD) {
if ($ts_delete > 0 && $current_time < $ts_delete) {
$warning = _s('The %1$s is not discovered anymore and %2$s, %3$s.', $entity, _('has been disabled'),
_s('will be deleted in %1$s', zbx_date2age($current_time, $ts_delete))
);
}
elseif ($ts_delete == 0) {
$warning = _s('The %1$s is not discovered anymore and %2$s, %3$s.', $entity, _('has been disabled'),
_('will not be deleted')
);
}
elseif ($current_time > $ts_delete) {
$warning = _s('The %1$s is not discovered anymore and %2$s, %3$s.', $entity, _('has been disabled'),
_('will be deleted the next time discovery rule is processed')
);
}
}
elseif ($disabled && $disable_source == ZBX_DISABLE_DEFAULT && $ts_delete > 0) {
$warning = _s('The %1$s is not discovered anymore and %2$s, %3$s.', $entity, _('has been manually disabled'),
_('will not be deleted')
);
}
elseif (!$disabled && $ts_delete > 0) {
$delete_msg = _s('will be deleted in %1$s', zbx_date2age($current_time, $ts_delete));
switch (true) {
case $current_time > $ts_delete:
$warning = _s('The %1$s is not discovered anymore and %2$s.', $entity,
_('will be deleted the next time discovery rule is processed')
);
break;
case $ts_disable == 0:
$warning = _s('The %1$s is not discovered anymore and %2$s, %3$s.', $entity,
_s('will not be disabled'), $delete_msg
);
break;
case $ts_disable > 0 && $ts_disable > $current_time:
$warning = _s('The %1$s is not discovered anymore and %2$s, %3$s.', $entity,
_s('will be disabled in %1$s', zbx_date2age($current_time, $ts_disable)), $delete_msg
);
break;
case $ts_disable != 0 && $current_time > $ts_disable:
$warning = _s('The %1$s is not discovered anymore and %2$s, %3$s.', $entity,
_('will be disabled the next time discovery rule is processed'), $delete_msg
);
break;
}
}
elseif (!$disabled && $ts_delete == 0) {
$delete_msg = _('will not be deleted');
switch (true) {
case $ts_disable != 0 && $current_time > $ts_disable:
$warning = _s('The %1$s is not discovered anymore and %2$s, %3$s.', $entity,
_('will be disabled the next time discovery rule is processed'), $delete_msg
);
break;
case $ts_disable > 0:
$warning = _s('The %1$s is not discovered anymore and %2$s, %3$s.', $entity,
_s('will be disabled in %1$s', zbx_date2age($current_time, $ts_disable)), $delete_msg
);
break;
case $ts_disable == 0:
$warning = _s('The %1$s is not discovered anymore and %2$s, %3$s.', $entity,
_('will not be disabled'), $delete_msg
);
break;
}
}
return $warning === '' ? null : makeWarningIcon($warning);
}
/**
* Returns the discovered graph lifetime indicator.
*
* @param int $current_time Current Unix timestamp.
* @param int $ts_delete Deletion timestamp of the graph.
*
* @throws Exception
*/
function getGraphLifetimeIndicator(int $current_time, int $ts_delete): ?CSimpleButton {
if ($ts_delete == 0) {
$warning = _s('The %1$s is not discovered anymore and %2$s.', _('graph'),
_('will not be deleted')
);
}
elseif ($current_time > $ts_delete && $ts_delete != 0) {
$warning = _s('The %1$s is not discovered anymore and %2$s.', _('graph'),
_('will be deleted the next time discovery rule is processed')
);
}
else {
$warning = _s('The %1$s is not discovered anymore and %2$s.', _('graph'),
_s('will be deleted in %1$s', zbx_date2age($current_time, $ts_delete))
);
}
return makeWarningIcon($warning);
}
function makeServerStatusOutput(): CTag {
return (new CTag('output', true))
->setId('msg-global-footer')
->addClass(ZBX_STYLE_MSG_GLOBAL_FOOTER)
->addClass(ZBX_STYLE_MSG_WARNING);
}
/**
* Make logo of the specified type.
*
* @param int $type LOGO_TYPE_NORMAL | LOGO_TYPE_SIDEBAR | LOGO_TYPE_SIDEBAR_COMPACT.
*/
function makeLogo(int $type): CTag {
static $zabbix_logo_classes = [
LOGO_TYPE_NORMAL => ZBX_STYLE_ZABBIX_LOGO,
LOGO_TYPE_SIDEBAR => ZBX_STYLE_ZABBIX_LOGO_SIDEBAR,
LOGO_TYPE_SIDEBAR_COMPACT => ZBX_STYLE_ZABBIX_LOGO_SIDEBAR_COMPACT
];
$brand_logo = CBrandHelper::getLogo($type);
if ($brand_logo !== null) {
return (new CImg($brand_logo))->addClass($zabbix_logo_classes[$type]);
}
return (new CDiv())->addClass($zabbix_logo_classes[$type]);
}
/**
* Renders a page footer.
*/
function makePageFooter(bool $with_version = true): CTag {
return (new CTag('footer', true, CBrandHelper::getFooterContent($with_version)))
->setAttribute('role', 'contentinfo');
}
/**
* Get drop-down submenu item list for the User settings section.
*
* @throws Exception
*
* @return array Menu definition for CHtmlPage::setTitleSubmenu.
*/
function getUserSettingsSubmenu(): array {
if (!CWebUser::checkAccess(CRoleHelper::ACTIONS_MANAGE_API_TOKENS)) {
return [];
}
$profile_url = (new CUrl('zabbix.php'))
->setArgument('action', 'userprofile.edit')
->getUrl();
$tokens_url = (new CUrl('zabbix.php'))
->setArgument('action', 'user.token.list')
->getUrl();
return [
'main_section' => [
'items' => array_filter([
$profile_url => _('User profile'),
$tokens_url => _('API tokens')
])
]
];
}
/**
* Get drop-down submenu item list for the Administration->General section.
*
* @return array Menu definition for CHtmlPage::setTitleSubmenu.
*/
function getAdministrationGeneralSubmenu(): array {
$gui_url = (new CUrl('zabbix.php'))
->setArgument('action', 'gui.edit')
->getUrl();
$autoreg_url = (new CUrl('zabbix.php'))
->setArgument('action', 'autoreg.edit')
->getUrl();
$timeouts_url = (new CUrl('zabbix.php'))
->setArgument('action', 'timeouts.edit')
->getUrl();
$image_url = (new CUrl('zabbix.php'))
->setArgument('action', 'image.list')
->getUrl();
$iconmap_url = (new CUrl('zabbix.php'))
->setArgument('action', 'iconmap.list')
->getUrl();
$regex_url = (new CUrl('zabbix.php'))
->setArgument('action', 'regex.list')
->getUrl();
$trigdisplay_url = (new CUrl('zabbix.php'))
->setArgument('action', 'trigdisplay.edit')
->getUrl();
$geomap_url = (new CUrl('zabbix.php'))
->setArgument('action', 'geomaps.edit')
->getUrl();
$modules_url = (new CUrl('zabbix.php'))
->setArgument('action', 'module.list')
->getUrl();
$connectors_url = (new CUrl('zabbix.php'))
->setArgument('action', 'connector.list')
->getUrl();
$miscconfig_url = (new CUrl('zabbix.php'))
->setArgument('action', 'miscconfig.edit')
->getUrl();
return [
'main_section' => [
'items' => array_filter([
$gui_url => _('GUI'),
$autoreg_url => _('Autoregistration'),
$timeouts_url => _('Timeouts'),
$image_url => _('Images'),
$iconmap_url => _('Icon mapping'),
$regex_url => _('Regular expressions'),
$trigdisplay_url => _('Trigger displaying options'),
$geomap_url => _('Geographical maps'),
$modules_url => _('Modules'),
$connectors_url => _('Connectors'),
$miscconfig_url => _('Other')
])
]
];
}
/**
* Renders an icon list.
*
* @param array $info_icons The list of information icons.
*
* @return CDiv|string
*/
function makeInformationList($info_icons) {
return $info_icons ? (new CDiv($info_icons))->addClass(ZBX_STYLE_REL_CONTAINER) : '';
}
/**
* Renders an icon for host in maintenance.
*
* @param int|string $type Type of the maintenance.
* @param string $name Name of the maintenance.
* @param string $description Description of the maintenance.
*/
function makeMaintenanceIcon($type, string $name, string $description): CButtonIcon {
$hint = $name.' ['.($type
? _('Maintenance without data collection')
: _('Maintenance with data collection')).']';
if ($description !== '') {
$hint .= "\n".$description;
}
return (new CButtonIcon(ZBX_ICON_WRENCH_ALT_SMALL))
->addClass(ZBX_STYLE_COLOR_WARNING)
->addClass(ZBX_STYLE_NO_INDENT)
->setHint($hint);
}
/**
* Renders an icon for suppressed problem.
*
* @param array $icon_data
* string $icon_data[]['suppress_until'] Time until the problem is suppressed.
* string $icon_data[]['maintenance_name'] Name of the maintenance.
* string $icon_data[]['username'] User who created manual suppression.
* @param bool $blink Add 'blink' CSS class for jqBlink.
*
* @throws Exception
*/
function makeSuppressedProblemIcon(array $icon_data, bool $blink = false): CSimpleButton {
$suppress_until_values = array_column($icon_data, 'suppress_until');
if (in_array(ZBX_PROBLEM_SUPPRESS_TIME_INDEFINITE, $suppress_until_values)) {
$suppressed_till = _s('Indefinitely');
}
else {
$max_value = max($suppress_until_values);
$suppressed_till = $max_value < strtotime('tomorrow')
? zbx_date2str(TIME_FORMAT, $max_value)
: zbx_date2str(DATE_TIME_FORMAT, $max_value);
}
CArrayHelper::sort($icon_data, ['maintenance_name']);
$maintenance_names = [];
$username = '';
foreach ($icon_data as $suppression) {
if (array_key_exists('maintenance_name', $suppression)) {
$maintenance_names[] = $suppression['maintenance_name'];
}
elseif (array_key_exists('username', $suppression)) {
$username = $suppression['username'];
}
}
$maintenances = implode(', ', $maintenance_names);
return (new CButtonIcon(ZBX_ICON_EYE_OFF))
->addClass(ZBX_STYLE_COLOR_ICON)
->addClass($blink ? 'js-blink' : null)
->setHint(
_s('Suppressed till: %1$s', $suppressed_till).
($username !== '' ? "\n"._s('Manually by: %1$s', $username) : '').
($maintenances !== '' ? "\n"._s('Maintenance: %1$s', $maintenances) : '')
);
}
/**
* Renders an icon with question mark and text in hint.
*
* @param string|array|CTag $help_text
*/
function makeHelpIcon($help_text): CSimpleButton {
return (new CButtonIcon(ZBX_ICON_HELP_FILLED_SMALL))
->setSmall()
->setHint($help_text, ZBX_STYLE_HINTBOX_WRAP);
}
/**
* Renders an icon for a description.
*/
function makeDescriptionIcon(string $description): CButtonIcon {
return (new CButtonIcon(ZBX_ICON_ALERT_WITH_CONTENT))
->setAttribute('data-content', '?')
->setHint(zbx_str2links($description), ZBX_STYLE_HINTBOX_WRAP);
}
/**
* Renders an information icon like green [i] with message.
*
* @param string|array|CTag $message
*/
function makeInformationIcon($message): CButtonIcon {
return (new CButtonIcon(ZBX_ICON_I_POSITIVE))
->setSmall()
->setHint($message, ZBX_STYLE_HINTBOX_WRAP);
}
/**
* Renders a warning icon like yellow [i] with error message.
*
* @param string|array|CTag $warning
*/
function makeWarningIcon($warning): CButtonIcon {
return (new CButtonIcon(ZBX_ICON_I_WARNING))
->setSmall()
->setHint($warning, ZBX_STYLE_HINTBOX_WRAP);
}
/**
* Renders an error icon like red [i] with error message.
*
* @param string|array|CTag $error
*/
function makeErrorIcon($error): CButtonIcon {
return (new CButtonIcon(ZBX_ICON_I_NEGATIVE))
->setSmall()
->setHint($error, ZBX_STYLE_HINTBOX_WRAP.' '.ZBX_STYLE_RED);
}
/**
* Returns css for trigger severity backgrounds.
*/
function getTriggerSeverityCss(): string {
$css = '';
$severities = [
ZBX_STYLE_NA_BG => CSettingsHelper::getPublic(CSettingsHelper::SEVERITY_COLOR_0),
ZBX_STYLE_INFO_BG => CSettingsHelper::getPublic(CSettingsHelper::SEVERITY_COLOR_1),
ZBX_STYLE_WARNING_BG => CSettingsHelper::getPublic(CSettingsHelper::SEVERITY_COLOR_2),
ZBX_STYLE_AVERAGE_BG => CSettingsHelper::getPublic(CSettingsHelper::SEVERITY_COLOR_3),
ZBX_STYLE_HIGH_BG => CSettingsHelper::getPublic(CSettingsHelper::SEVERITY_COLOR_4),
ZBX_STYLE_DISASTER_BG => CSettingsHelper::getPublic(CSettingsHelper::SEVERITY_COLOR_5)
];
$css .= ':root {'."\n";
foreach ($severities as $class => $color) {
$css .= '--severity-color-'.$class.': #'.$color.';'."\n";
}
$css .= '}'."\n";
foreach ($severities as $class => $color) {
$css .= '.'.$class.', .'.$class.' input[type="radio"]:checked + label, .'.$class.':before, .flh-'.$class.
', .status-'.$class.', .status-'.$class.':before { background-color: #'.$color.' }'."\n";
}
return $css;
}
/**
* Returns css for trigger status colors, if those are customized.
*/
function getTriggerStatusCss(): string {
$css = '';
if (CSettingsHelper::getPublic(CSettingsHelper::CUSTOM_COLOR) == EVENT_CUSTOM_COLOR_ENABLED) {
$event_statuses = [
ZBX_STYLE_PROBLEM_UNACK_FG => CSettingsHelper::getPublic(CSettingsHelper::PROBLEM_UNACK_COLOR),
ZBX_STYLE_PROBLEM_ACK_FG => CSettingsHelper::getPublic(CSettingsHelper::PROBLEM_ACK_COLOR),
ZBX_STYLE_OK_UNACK_FG => CSettingsHelper::getPublic(CSettingsHelper::OK_UNACK_COLOR),
ZBX_STYLE_OK_ACK_FG => CSettingsHelper::getPublic(CSettingsHelper::OK_ACK_COLOR)
];
foreach ($event_statuses as $class => $color) {
$css .= '.' . $class . ' {color: #' . $color . ';}' . "\n";
}
}
return $css;
}
|