Source
xxxxxxxxxx
287
287
* @param int $i['iconid_disabled'] Icon ID for disabled element.
288
288
* @param bool $i['latelyChanged'] Whether trigger status has changed recently.
289
289
* @param int $i['priority'] Problem severity. Possible values:
290
290
* TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_INFORMATION,
291
291
* TRIGGER_SEVERITY_WARNING, TRIGGER_SEVERITY_AVERAGE, TRIGGER_SEVERITY_HIGH,
292
292
* TRIGGER_SEVERITY_DISASTER.
293
293
* @param int $i['expandproblem'] Map "Display problems" option. Possible values:
294
294
* SYSMAP_SINGLE_PROBLEM, SYSMAP_PROBLEMS_NUMBER,
295
295
* SYSMAP_PROBLEMS_NUMBER_CRITICAL.
296
296
* @param string $i['problem_title'] (optional) The name of the most critical problem.
297
+
* @param int $host_count (optional) Number of unique hosts that the current selement is related to.
297
298
* @param int|null $show_unack (optional) Map "Problem display" option. Possible values:
298
299
* EXTACK_OPTION_ALL, EXTACK_OPTION_UNACK, EXTACK_OPTION_BOTH.
299
300
*
300
301
* @return array
301
302
*/
302
-
function getSelementInfo(array $i, ?int $show_unack = null): array {
303
+
function getSelementInfo(array $i, int $host_count = 0, int $show_unack = null): array {
303
304
if ($i['elementtype'] == SYSMAP_ELEMENT_TYPE_IMAGE) {
304
305
return [
305
306
'iconid' => $i['iconid_off'],
306
307
'icon_type' => SYSMAP_ELEMENT_ICON_OFF,
307
308
'name' => _('Image'),
308
309
'latelyChanged' => false
309
310
];
310
311
}
311
312
312
313
$info = [
394
395
$info['iconid'] = $i['iconid_on'];
395
396
$info['icon_type'] = SYSMAP_ELEMENT_ICON_ON;
396
397
$has_problem = true;
397
398
}
398
399
399
400
$info['aria_label'] = ($i['problem'] > 1)
400
401
? _n('%1$s problem', '%1$s problems', $i['problem'])
401
402
: $i['problem_title'];
402
403
}
403
404
405
+
$all_hosts_in_maintenance = $i['maintenance'] && ($host_count == $i['disabled'] + $i['maintenance']);
406
+
404
407
if ($i['maintenance']) {
405
-
$info['iconid'] = $i['iconid_maintenance'];
406
-
$info['icon_type'] = SYSMAP_ELEMENT_ICON_MAINTENANCE;
408
+
if (!$has_problem && $all_hosts_in_maintenance) {
409
+
$info['iconid'] = $i['iconid_maintenance'];
410
+
$info['icon_type'] = SYSMAP_ELEMENT_ICON_MAINTENANCE;
411
+
}
412
+
407
413
$info['info']['maintenance'] = [
408
414
'msg' => ($i['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST)
409
415
? _('In maintenance')
410
416
: _n('%1$s host in maintenance', '%1$s hosts in maintenance', $i['maintenance']),
411
417
'color' => 'EE9600'
412
418
];
413
419
}
414
420
415
421
if (!$has_problem) {
416
-
if (!$i['maintenance']) {
422
+
if (!$all_hosts_in_maintenance) {
417
423
$info['iconid'] = $i['iconid_off'];
418
424
$info['icon_type'] = SYSMAP_ELEMENT_ICON_OFF;
419
425
}
420
426
421
427
$info['info']['ok'] = [
422
428
'msg' => _('OK'),
423
429
'color' => getSelementLabelColor(false, $info['ack'])
424
430
];
425
431
}
426
432
605
611
$all_triggerid_to_selementids[$triggerid] = $selementids;
606
612
}
607
613
else {
608
614
$all_triggerid_to_selementids[$triggerid] += $selementids;
609
615
}
610
616
}
611
617
}
612
618
613
619
$triggers = API::Trigger()->get([
614
620
'output' => ['triggerid', 'status', 'value', 'priority', 'description', 'expression'],
615
-
'selectHosts' => ['hostid', 'maintenance_status'],
621
+
'selectHosts' => ['hostid', 'status', 'maintenance_status'],
616
622
'triggerids' => array_keys($all_triggerid_to_selementids),
617
623
'filter' => ['state' => null],
618
624
'preservekeys' => true
619
625
]);
620
626
621
627
$monitored_triggers = API::Trigger()->get([
622
628
'output' => [],
623
629
'triggerids' => array_keys($triggers),
624
630
'monitored' => true,
625
631
'skipDependent' => true,
646
652
foreach ($allHosts as $hostid => $host) {
647
653
if ($host['status'] == HOST_STATUS_MONITORED) {
648
654
$monitored_hostids[$hostid] = true;
649
655
}
650
656
}
651
657
652
658
// triggers from all hosts/hostgroups, skip dependent
653
659
if ($monitored_hostids) {
654
660
$triggers = API::Trigger()->get([
655
661
'output' => ['triggerid', 'status', 'value', 'priority', 'description', 'expression'],
656
-
'selectHosts' => ['hostid', 'maintenance_status'],
662
+
'selectHosts' => ['hostid', 'status', 'maintenance_status'],
657
663
'selectItems' => ['itemid'],
658
664
'hostids' => array_keys($monitored_hostids),
659
665
'filter' => ['state' => null],
660
666
'monitored' => true,
661
667
'skipDependent' => true,
662
668
'only_true' => true,
663
669
'preservekeys' => true
664
670
]);
665
671
666
672
foreach ($triggers as $triggerid => $trigger) {
738
744
/*
739
745
* If user has no rights to see the details of particular selement, add only info that is needed to render map
740
746
* icons.
741
747
*/
742
748
if (PERM_READ > $selement['permission']) {
743
749
$info[$selementId] = getSelementInfo($i + ['iconid_off' => $selement['iconid_off']]);
744
750
745
751
continue;
746
752
}
747
753
754
+
$host_count = count($selement['hosts']);
755
+
748
756
if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER
749
757
|| $selement['elementtype'] == SYSMAP_ELEMENT_TYPE_MAP) {
750
758
$trigger_hosts = [];
751
759
foreach ($selement['triggers'] as $trigger) {
752
760
foreach ($trigger['hosts'] as $host) {
753
761
if (!array_key_exists($host['hostid'], $trigger_hosts)
754
762
&& !array_key_exists($host['hostid'], $selement['hosts'])) {
755
763
$trigger_hosts[$host['hostid']] = true;
764
+
$host_count++;
756
765
757
-
if ($host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON
766
+
if ($host['status'] == HOST_STATUS_MONITORED
767
+
&& $host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON
758
768
&& ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER
759
-
|| ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_MAP
760
-
&& array_key_exists(SYSMAP_ELEMENT_TYPE_TRIGGER, $trigger['source'])))) {
769
+
|| ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_MAP
770
+
&& array_key_exists(SYSMAP_ELEMENT_TYPE_TRIGGER, $trigger['source'])))) {
761
771
$i['maintenance']++;
762
772
}
763
773
}
764
774
}
765
775
}
766
776
}
767
777
768
778
foreach ($selement['hosts'] as $hostId) {
769
779
$host = $allHosts[$hostId];
770
780
844
854
}
845
855
if (!$selement['iconid_disabled']) {
846
856
$selement['iconid_disabled'] = $selement['iconid_off'];
847
857
}
848
858
849
859
$i['iconid_off'] = $selement['iconid_off'];
850
860
$i['iconid_on'] = $selement['iconid_on'];
851
861
$i['iconid_maintenance'] = $selement['iconid_maintenance'];
852
862
$i['iconid_disabled'] = $selement['iconid_disabled'];
853
863
854
-
$info[$selementId] = getSelementInfo($i, $sysmap['show_unack']);
864
+
$info[$selementId] = getSelementInfo($i, $host_count, $sysmap['show_unack']);
855
865
856
866
if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST && $sysmap['iconmapid'] && $selement['use_iconmap']) {
857
867
$host_inventory = $host_inventories[$selement['elements'][0]['hostid']];
858
868
$info[$selementId]['iconid'] = getIconByMapping($iconMap, $host_inventory);
859
869
}
860
870
861
871
$info[$selementId]['problems_total'] = $i['problem'];
862
872
}
863
873
864
874
if ($sysmap['label_format'] == SYSMAP_LABEL_ADVANCED_OFF) {