1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 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 22class CTriggersInfo extends CTable { 23 24 private $style = STYLE_HORIZONTAL; 25 private $groupid; 26 27 public function __construct($groupid) { 28 parent::__construct(); 29 30 $this->addClass(ZBX_STYLE_LIST_TABLE); 31 $this->groupid = $groupid; 32 } 33 34 public function setOrientation($value) { 35 $this->style = $value; 36 return $this; 37 } 38 39 protected function bodyToString() { 40 $this->cleanItems(); 41 42 $config = select_config(); 43 44 // array of triggers (not classified, information, warning, average, high, disaster) in problem state 45 $triggersProblemState = []; 46 47 // number of triggers in OK state 48 $triggersOkState = 0; 49 50 $options = [ 51 'output' => ['triggerid', 'priority', 'value'], 52 'monitored' => true, 53 'skipDependent' => true 54 ]; 55 56 if ($this->groupid != 0) { 57 $options['groupids'] = $this->groupid; 58 } 59 $triggers = API::Trigger()->get($options); 60 61 foreach ($triggers as $trigger) { 62 switch ($trigger['value']) { 63 case TRIGGER_VALUE_TRUE: 64 if (!array_key_exists($trigger['priority'], $triggersProblemState)) { 65 $triggersProblemState[$trigger['priority']] = 0; 66 } 67 68 $triggersProblemState[$trigger['priority']]++; 69 break; 70 71 case TRIGGER_VALUE_FALSE: 72 $triggersOkState++; 73 } 74 } 75 76 $severityCells = [getSeverityCell(null, $config, $triggersOkState.SPACE._('Ok'), true)]; 77 78 for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { 79 $severityCount = isset($triggersProblemState[$severity]) ? $triggersProblemState[$severity] : 0; 80 81 $severityCells[] = getSeverityCell($severity, 82 $config, 83 $severityCount.SPACE.getSeverityName($severity, $config), 84 !$severityCount 85 ); 86 } 87 88 if ($this->style == STYLE_HORIZONTAL) { 89 $this->addRow($severityCells); 90 } 91 else { 92 foreach ($severityCells as $severityCell) { 93 $this->addRow($severityCell); 94 } 95 } 96 97 return parent::bodyToString(); 98 } 99} 100