Beispiel #1
0
 /**
  * @param string $options['name']
  * @param int    $options['value']		(optional) Default: TRIGGER_SEVERITY_NOT_CLASSIFIED
  * @param bool   $options['all']		(optional)
  */
 public function __construct(array $options = [])
 {
     parent::__construct();
     $id = zbx_formatDomId($options['name']);
     $this->addClass(ZBX_STYLE_RADIO_SEGMENTED);
     $this->setId($id);
     if (!array_key_exists('value', $options)) {
         $options['value'] = TRIGGER_SEVERITY_NOT_CLASSIFIED;
     }
     $severity_from = array_key_exists('all', $options) && $options['all'] ? -1 : TRIGGER_SEVERITY_NOT_CLASSIFIED;
     $config = select_config();
     for ($severity = $severity_from; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
         $name = $severity == -1 ? _('all') : getSeverityName($severity, $config);
         $class = $severity == -1 ? null : getSeverityStyle($severity);
         $radio = (new CInput('radio', $options['name'], $severity))->setId(zbx_formatDomId($options['name'] . '_' . $severity));
         if ($severity === $options['value']) {
             $radio->setAttribute('checked', 'checked');
         }
         parent::addItem((new CListItem([$radio, new CLabel($name, $options['name'] . '_' . $severity)]))->addClass($class));
     }
 }
 public function bodyToString()
 {
     $this->cleanItems();
     $config = select_config();
     // array of triggers (not classified, information, warning, average, high, disaster) in problem state
     $triggersProblemState = [];
     // number of triggers in OK state
     $triggersOkState = 0;
     $options = ['output' => ['triggerid', 'priority', 'value'], 'monitored' => true, 'skipDependent' => true];
     if ($this->groupid != 0) {
         $options['groupids'] = $this->groupid;
     }
     $triggers = API::Trigger()->get($options);
     foreach ($triggers as $trigger) {
         switch ($trigger['value']) {
             case TRIGGER_VALUE_TRUE:
                 if (!array_key_exists($trigger['priority'], $triggersProblemState)) {
                     $triggersProblemState[$trigger['priority']] = 0;
                 }
                 $triggersProblemState[$trigger['priority']]++;
                 break;
             case TRIGGER_VALUE_FALSE:
                 $triggersOkState++;
         }
     }
     $severityCells = [getSeverityCell(null, $config, $triggersOkState . SPACE . _('Ok'), true)];
     for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
         $severityCount = isset($triggersProblemState[$severity]) ? $triggersProblemState[$severity] : 0;
         $severityCells[] = getSeverityCell($severity, $config, $severityCount . SPACE . getSeverityName($severity, $config), !$severityCount);
     }
     if ($this->style == STYLE_HORIZONTAL) {
         $this->addRow($severityCells);
     } else {
         foreach ($severityCells as $severityCell) {
             $this->addRow($severityCell);
         }
     }
     return parent::bodyToString();
 }
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
require_once dirname(__FILE__) . '/js/reports.toptriggers.js.php';
$topTriggers = (new CWidget())->setTitle(_('100 busiest triggers'));
$filterForm = (new CFilter('web.toptriggers.filter.state'))->addVar('filter_from', date(TIMESTAMP_FORMAT, $this->data['filter']['filter_from']))->addVar('filter_till', date(TIMESTAMP_FORMAT, $this->data['filter']['filter_till']));
$filterColumn1 = new CFormList();
$filterColumn2 = new CFormList();
$filterColumn2->addRow(_('From'), createDateSelector('filter_from', $this->data['filter']['filter_from']));
$filterColumn2->addRow(_('Till'), createDateSelector('filter_till', $this->data['filter']['filter_till']));
$filterColumn2->addRow(null, [new CHorList([(new CButton(null, _('Today')))->onClick('javascript: setPeriod(' . REPORT_PERIOD_TODAY . ');')->addClass(ZBX_STYLE_BTN_LINK), (new CButton(null, _('Yesterday')))->onClick('javascript: setPeriod(' . REPORT_PERIOD_YESTERDAY . ');')->addClass(ZBX_STYLE_BTN_LINK), (new CButton(null, _('Current week')))->onClick('javascript: setPeriod(' . REPORT_PERIOD_CURRENT_WEEK . ');')->addClass(ZBX_STYLE_BTN_LINK), (new CButton(null, _('Current month')))->onClick('javascript: setPeriod(' . REPORT_PERIOD_CURRENT_MONTH . ');')->addClass(ZBX_STYLE_BTN_LINK), (new CButton(null, _('Current year')))->onClick('javascript: setPeriod(' . REPORT_PERIOD_CURRENT_YEAR . ');')->addClass(ZBX_STYLE_BTN_LINK)]), new CHorList([(new CButton(null, _('Last week')))->onClick('javascript: setPeriod(' . REPORT_PERIOD_LAST_WEEK . ');')->addClass(ZBX_STYLE_BTN_LINK), (new CButton(null, _('Last month')))->onClick('javascript: setPeriod(' . REPORT_PERIOD_LAST_MONTH . ');')->addClass(ZBX_STYLE_BTN_LINK), (new CButton(null, _('Last year')))->onClick('javascript: setPeriod(' . REPORT_PERIOD_LAST_YEAR . ');')->addClass(ZBX_STYLE_BTN_LINK)])]);
$filterColumn1->addRow(_('Host groups'), (new CMultiSelect(['name' => 'groupids[]', 'objectName' => 'hostGroup', 'data' => $this->data['multiSelectHostGroupData'], 'popup' => ['parameters' => 'srctbl=host_groups&dstfrm=' . $filterForm->getName() . '&dstfld1=groupids_' . '&srcfld1=groupid&multiselect=1']]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH));
$filterColumn1->addRow(_('Hosts'), (new CMultiSelect(['name' => 'hostids[]', 'objectName' => 'hosts', 'data' => $this->data['multiSelectHostData'], 'popup' => ['parameters' => 'srctbl=hosts&dstfrm=' . $filterForm->getName() . '&dstfld1=hostids_&srcfld1=hostid' . '&real_hosts=1&multiselect=1']]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH));
// severities
$severity_columns = [0 => [], 1 => []];
for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
    $severity_columns[$severity % 2][] = new CLabel([(new CCheckBox('severities[' . $severity . ']'))->setChecked(in_array($severity, $this->data['filter']['severities'])), getSeverityName($severity, $this->data['config'])], 'severities[' . $severity . ']');
}
$filterColumn1->addRow(_('Severity'), (new CTable())->addRow($severity_columns[0])->addRow($severity_columns[1]));
$filterForm->addColumn($filterColumn1)->addColumn($filterColumn2);
$topTriggers->addItem($filterForm);
// table
$table = (new CTableInfo())->setHeader([_('Host'), _('Trigger'), _('Severity'), _('Number of status changes')]);
foreach ($this->data['triggers'] as $trigger) {
    foreach ($trigger['hosts'] as $host) {
        if ($host['status'] == HOST_STATUS_MONITORED) {
            // Pass a monitored 'hostid' and corresponding first 'groupid' to menu pop-up "Events" link.
            $trigger['hostid'] = $host['hostid'];
            $trigger['groupid'] = $data['monitored_hosts'][$trigger['hostid']]['groups'][0]['groupid'];
            break;
        } else {
            // Unmonitored will have disabled "Events" link and there is no 'groupid' or 'hostid'.
             if (++$popup_rows == ZBX_WIDGET_ROWS) {
                 break;
             }
         }
         $lastUnack_count = (new CSpan($hosts_data[$group['groupid']]['lastUnack']))->addClass(ZBX_STYLE_LINK_ACTION)->setHint($table_inf);
     } else {
         $lastUnack_count = 0;
     }
 }
 // if hostgroup contains problematic hosts, hint should be built
 if ($hosts_data[$group['groupid']]['problematic']) {
     $table_inf = new CTableInfo();
     // set trigger severities as table header starting from highest severity
     $header = [];
     for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
         $header[] = $data['filter']['severity'] === null || isset($data['filter']['severity'][$severity]) ? getSeverityName($severity, $data['config']) : null;
     }
     krsort($header);
     array_unshift($header, _('Host'));
     $table_inf->setHeader($header);
     $popup_rows = 0;
     foreach ($group['hosts'] as $host) {
         $hostid = $host['hostid'];
         if (!isset($problematic_host_list[$hostid])) {
             continue;
         }
         $host_data = $problematic_host_list[$hostid];
         $r = new CRow();
         $r->addItem(new CLink($host_data['host'], 'tr_status.php?filter_set=1&groupid=' . $group['groupid'] . '&hostid=' . $hostid . '&show_triggers=' . TRIGGERS_OPTION_RECENT_PROBLEM));
         foreach ($problematic_host_list[$host['hostid']]['severities'] as $severity => $trigger_count) {
             if (!is_null($data['filter']['severity']) && !isset($data['filter']['severity'][$severity])) {
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
zbx_add_post_js('jqBlink.blink();');
// hint table
$help_hint = (new CList())->addClass(ZBX_STYLE_NOTIF_BODY)->addStyle('min-width: ' . ZBX_OVERVIEW_HELP_MIN_WIDTH . 'px')->addItem([(new CDiv())->addClass(ZBX_STYLE_NOTIF_INDIC)->addClass(getSeverityStyle(null, false)), new CTag('h4', true, _('OK')), (new CTag('p', true, ''))->addClass(ZBX_STYLE_GREY)]);
for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
    $help_hint->addItem([(new CDiv())->addClass(ZBX_STYLE_NOTIF_INDIC)->addClass(getSeverityStyle($severity)), new CTag('h4', true, getSeverityName($severity, $data['config'])), (new CTag('p', true, _('PROBLEM')))->addClass(ZBX_STYLE_GREY)]);
}
// blinking preview in help popup (only if blinking is enabled)
if ($data['config']['blink_period'] > 0) {
    $indic_container = (new CDiv())->addClass(ZBX_STYLE_NOTIF_INDIC_CONTAINER)->addItem((new CDiv())->addClass(ZBX_STYLE_NOTIF_INDIC)->addClass(getSeverityStyle(null, false))->addClass('blink'));
    for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
        $indic_container->addItem((new CDiv())->addClass(ZBX_STYLE_NOTIF_INDIC)->addClass(getSeverityStyle($severity))->addClass('blink'));
    }
    $indic_container->addItem((new CTag('p', true, _s('Age less than %s', convertUnitsS($data['config']['blink_period']))))->addClass(ZBX_STYLE_GREY));
    $help_hint->addItem($indic_container);
}
// header right
$help = get_icon('overviewhelp');
$help->setHint($help_hint);
$widget = (new CWidget())->setTitle(_('Overview'))->setControls((new CForm('get'))->cleanItems()->addItem((new CList())->addItem([_('Group'), SPACE, $this->data['pageFilter']->getGroupsCB()])->addItem([_('Type'), SPACE, new CComboBox('type', $this->data['type'], 'submit()', [SHOW_TRIGGERS => _('Triggers'), SHOW_DATA => _('Data')])])->addItem([_('Hosts location'), SPACE, new CComboBox('view_style', $this->data['view_style'], 'submit()', [STYLE_TOP => _('Top'), STYLE_LEFT => _('Left')])])->addItem(get_icon('fullscreen', ['fullscreen' => $this->data['fullscreen']]))->addItem($help)));
// filter
Beispiel #6
0
function make_system_status($filter, $backurl)
{
    $config = select_config();
    $table = new CTableInfo();
    // set trigger severities as table header starting from highest severity
    $header = [];
    for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
        $header[] = $filter['severity'] === null || isset($filter['severity'][$severity]) ? getSeverityName($severity, $config) : null;
    }
    krsort($header);
    array_unshift($header, _('Host group'));
    $table->setHeader($header);
    // get host groups
    $groups = API::HostGroup()->get(['groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'output' => ['groupid', 'name'], 'preservekeys' => true]);
    CArrayHelper::sort($groups, [['field' => 'name', 'order' => ZBX_SORT_UP]]);
    $groupIds = [];
    foreach ($groups as $group) {
        $groupIds[$group['groupid']] = $group['groupid'];
        $group['tab_priority'] = [TRIGGER_SEVERITY_DISASTER => ['count' => 0, 'triggers' => [], 'count_unack' => 0, 'triggers_unack' => []], TRIGGER_SEVERITY_HIGH => ['count' => 0, 'triggers' => [], 'count_unack' => 0, 'triggers_unack' => []], TRIGGER_SEVERITY_AVERAGE => ['count' => 0, 'triggers' => [], 'count_unack' => 0, 'triggers_unack' => []], TRIGGER_SEVERITY_WARNING => ['count' => 0, 'triggers' => [], 'count_unack' => 0, 'triggers_unack' => []], TRIGGER_SEVERITY_INFORMATION => ['count' => 0, 'triggers' => [], 'count_unack' => 0, 'triggers_unack' => []], TRIGGER_SEVERITY_NOT_CLASSIFIED => ['count' => 0, 'triggers' => [], 'count_unack' => 0, 'triggers_unack' => []]];
        $groups[$group['groupid']] = $group;
    }
    // get triggers
    $triggers = API::Trigger()->get(['output' => ['triggerid', 'priority', 'state', 'description', 'error', 'value', 'lastchange', 'expression'], 'selectGroups' => ['groupid'], 'selectHosts' => ['name'], 'selectLastEvent' => ['eventid', 'acknowledged', 'objectid', 'clock', 'ns'], 'withLastEventUnacknowledged' => $filter['extAck'] == EXTACK_OPTION_UNACK ? true : null, 'skipDependent' => true, 'groupids' => $groupIds, 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored' => true, 'maintenance' => $filter['maintenance'], 'search' => $filter['trigger_name'] !== '' ? ['description' => $filter['trigger_name']] : null, 'filter' => ['priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE], 'sortfield' => 'lastchange', 'sortorder' => ZBX_SORT_DOWN, 'preservekeys' => true]);
    $eventIds = [];
    foreach ($triggers as $triggerId => $trigger) {
        if ($trigger['lastEvent']) {
            $eventIds[$trigger['lastEvent']['eventid']] = $trigger['lastEvent']['eventid'];
        }
        $triggers[$triggerId]['event'] = $trigger['lastEvent'];
        unset($triggers[$triggerId]['lastEvent']);
    }
    // get acknowledges
    if ($eventIds) {
        $eventAcknowledges = API::Event()->get(['output' => ['eventid'], 'eventids' => $eventIds, 'select_acknowledges' => ['eventid', 'clock', 'message', 'alias', 'name', 'surname'], 'preservekeys' => true]);
    }
    // actions
    $actions = makeEventsActions($eventIds);
    // triggers
    foreach ($triggers as $trigger) {
        // event
        if ($trigger['event']) {
            $trigger['event']['acknowledges'] = isset($eventAcknowledges[$trigger['event']['eventid']]) ? $eventAcknowledges[$trigger['event']['eventid']]['acknowledges'] : 0;
        } else {
            $trigger['event'] = ['acknowledged' => false, 'clock' => $trigger['lastchange'], 'ns' => '999999999', 'value' => $trigger['value']];
        }
        // groups
        foreach ($trigger['groups'] as $group) {
            if (!isset($groups[$group['groupid']])) {
                continue;
            }
            if (in_array($filter['extAck'], [EXTACK_OPTION_ALL, EXTACK_OPTION_BOTH])) {
                if ($groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count'] < ZBX_WIDGET_ROWS) {
                    $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['triggers'][] = $trigger;
                }
                $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count']++;
            }
            if (in_array($filter['extAck'], [EXTACK_OPTION_UNACK, EXTACK_OPTION_BOTH]) && isset($trigger['event']) && !$trigger['event']['acknowledged']) {
                if ($groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count_unack'] < ZBX_WIDGET_ROWS) {
                    $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['triggers_unack'][] = $trigger;
                }
                $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count_unack']++;
            }
        }
    }
    unset($triggers);
    foreach ($groups as $group) {
        $groupRow = new CRow();
        $name = new CLink($group['name'], 'tr_status.php?filter_set=1&groupid=' . $group['groupid'] . '&hostid=0' . '&show_triggers=' . TRIGGERS_OPTION_RECENT_PROBLEM);
        $groupRow->addItem($name);
        foreach ($group['tab_priority'] as $severity => $data) {
            if (!is_null($filter['severity']) && !isset($filter['severity'][$severity])) {
                continue;
            }
            $allTriggersNum = $data['count'];
            if ($allTriggersNum) {
                $allTriggersNum = (new CSpan($allTriggersNum))->addClass(ZBX_STYLE_LINK_ACTION)->setHint(makeTriggersPopup($data['triggers'], $backurl, $actions, $config));
            }
            $unackTriggersNum = $data['count_unack'];
            if ($unackTriggersNum) {
                $unackTriggersNum = (new CSpan($unackTriggersNum))->addClass(ZBX_STYLE_LINK_ACTION)->setHint(makeTriggersPopup($data['triggers_unack'], $backurl, $actions, $config));
            }
            switch ($filter['extAck']) {
                case EXTACK_OPTION_ALL:
                    $groupRow->addItem(getSeverityCell($severity, $config, $allTriggersNum, $data['count'] == 0));
                    break;
                case EXTACK_OPTION_UNACK:
                    $groupRow->addItem(getSeverityCell($severity, $config, $unackTriggersNum, $data['count_unack'] == 0));
                    break;
                case EXTACK_OPTION_BOTH:
                    if ($data['count_unack'] != 0) {
                        $groupRow->addItem(getSeverityCell($severity, $config, [$unackTriggersNum, ' ' . _('of') . ' ', $allTriggersNum]));
                    } else {
                        $groupRow->addItem(getSeverityCell($severity, $config, $allTriggersNum, $data['count'] == 0));
                    }
                    break;
            }
        }
        $table->addRow($groupRow);
    }
    return $table;
}
$form_list->addRow(_('Host groups'), $hostGroupsComboBox);
if ($this->data['grpswitch']) {
    $form_list->addRow(_('Show selected groups'), (new CMultiSelect(['name' => 'groupids[]', 'objectName' => 'hostGroup', 'data' => $this->data['groups'], 'disabled' => !$this->data['isFilterEnable'], 'popup' => ['parameters' => 'srctbl=host_groups&dstfrm=' . $form->getName() . '&dstfld1=groupids_' . '&srcfld1=groupid&multiselect=1']]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH));
    $form_list->addRow(_('Hide selected groups'), (new CMultiSelect(['name' => 'hidegroupids[]', 'objectName' => 'hostGroup', 'data' => $this->data['hideGroups'], 'disabled' => !$this->data['isFilterEnable'], 'popup' => ['parameters' => 'srctbl=host_groups&dstfrm=' . $form->getName() . '&dstfld1=hidegroupids_' . '&srcfld1=groupid&multiselect=1']]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH));
}
// append host in maintenance checkbox to form list
$maintenanceCheckBox = (new CCheckBox('maintenance'))->setChecked($this->data['maintenance'] == 1);
if (!$this->data['isFilterEnable']) {
    $maintenanceCheckBox->setAttribute('disabled', 'disabled');
}
$form_list->addRow(_('Hosts'), new CLabel([$maintenanceCheckBox, _('Show hosts in maintenance')], 'maintenance'));
// append trigger severities to form list
$severities = [];
foreach ($this->data['severities'] as $severity) {
    $serverityCheckBox = (new CCheckBox('trgSeverity[' . $severity . ']'))->setChecked(isset($this->data['severity'][$severity]))->setEnabled($this->data['isFilterEnable']);
    $severities[] = new CLabel([$serverityCheckBox, getSeverityName($severity, $this->data['config'])], 'trgSeverity[' . $severity . ']');
    $severities[] = BR();
}
array_pop($severities);
$form_list->addRow(_('Triggers with severity'), $severities);
$form_list->addRow(_('Trigger name like'), (new CTextBox('trigger_name', $data['trigger_name']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)->setEnabled($data['isFilterEnable']));
if ($data['config']['event_ack_enable']) {
    // append problem display to form list
    $ext_ack_combobox = new CComboBox('extAck', $data['extAck'], null, [EXTACK_OPTION_ALL => _('All'), EXTACK_OPTION_BOTH => _('Separated'), EXTACK_OPTION_UNACK => _('Unacknowledged only')]);
    $ext_ack_combobox->setEnabled($data['isFilterEnable']);
    $form_list->addRow(_('Problem display'), $ext_ack_combobox);
}
// create tab
$tab = new CTabView();
$tab->addTab('dashconfTab', _('Filter'), $form_list);
$tab->setFooter(makeFormFooter(new CSubmit('update', _('Update')), [new CButtonCancel()]));
Beispiel #8
0
    foreach ($keys as $id => $val) {
        $row = new CRow([htmlspecialchars($val['value']), $val['type'], (new CCol((new CButton(null, _('Remove')))->addClass(ZBX_STYLE_BTN_LINK)->onClick('javascript: remove_keyword("keytr' . $id . '");')))->addClass(ZBX_STYLE_NOWRAP)]);
        $row->setId('keytr' . $id);
        $keyTable->addRow($row);
        $form->addVar('keys[' . $id . '][value]', $val['value']);
        $form->addVar('keys[' . $id . '][type]', $val['type']);
        $maxId = max($maxId, $id);
    }
    zbx_add_post_js('key_count=' . ($maxId + 1) . ';');
    $form_list->addRow(null, (new CDiv($keyTable))->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)->setAttribute('style', 'min-width: ' . ZBX_TEXTAREA_BIG_WIDTH . 'px;'));
    $form_list->addRow(null, (new CDiv($table))->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)->setAttribute('style', 'min-width: ' . ZBX_TEXTAREA_BIG_WIDTH . 'px;'));
    $sev_select = new CComboBox('priority', $priority);
    $config = select_config();
    $severityNames = [];
    for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
        $severityNames[] = getSeverityName($severity, $config);
    }
    $sev_select->addItems($severityNames);
    $form_list->addRow(_('Severity'), $sev_select);
    $form_list->addRow(_('Comments'), (new CTextArea('comments', $comments))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH));
    $form_list->addRow(_('URL'), (new CTextBox('url', $url))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH));
    $form_list->addRow(_('Disabled'), (new CCheckBox('status'))->setChecked($status == TRIGGER_STATUS_DISABLED));
    $tab = (new CTabView())->addTab('trigger_tab', null, $form_list);
    if (hasRequest('triggerid')) {
        $tab->setFooter(makeFormFooter(new CSubmit('update', _('Update')), [(new CButton('cancel', _('Cancel')))->onClick('javascript: self.close();')]));
    } else {
        $tab->setFooter(makeFormFooter(new CSubmit('add', _('Add')), [(new CButton('cancel', _('Cancel')))->onClick('javascript: self.close();')]));
    }
    $form->addItem($tab);
    $widget->addItem($form)->show();
}
Beispiel #9
0
         $scripts = API::Script()->getScriptsByHosts($hostids);
     }
     // actions
     $actions = makeEventsActions(zbx_objectValues($events, 'eventid'));
     // events
     foreach ($events as $event) {
         $trigger = $triggers[$event['objectid']];
         $host = reset($trigger['hosts']);
         $host = $hosts[$host['hostid']];
         $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, ['clock' => $event['clock'], 'ns' => $event['ns']]));
         // duration
         $event['duration'] = ($nextEvent = get_next_event($event, $events)) ? zbx_date2age($event['clock'], $nextEvent['clock']) : zbx_date2age($event['clock']);
         // action
         $action = isset($actions[$event['eventid']]) ? $actions[$event['eventid']] : '';
         if ($csvExport) {
             $csvRows[] = [zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), $pageFilter->hostid == 0 ? $host['name'] : null, $description, trigger_value2str($event['value']), getSeverityName($trigger['priority'], $config), $event['duration'], $config['event_ack_enable'] ? $event['acknowledges'] ? _('Yes') : _('No') : null, strip_tags((string) $action)];
         } else {
             $triggerDescription = (new CSpan($description))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getTrigger($trigger, null, $event['clock']));
             // add colors and blinking to span depending on configuration and trigger parameters
             $statusSpan = new CSpan(trigger_value2str($event['value']));
             addTriggerValueStyle($statusSpan, $event['value'], $event['clock'], $event['acknowledged']);
             // host JS menu link
             $hostName = null;
             if ($pageFilter->hostid == 0) {
                 $hostName = (new CSpan($host['name']))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$host['hostid']]));
             }
             $table->addRow([(new CLink(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid']))->addClass('action'), $hostName, $triggerDescription, $statusSpan, getSeverityCell($trigger['priority'], $config, null, !$event['value']), $event['duration'], $config['event_ack_enable'] ? getEventAckState($event, $page['file']) : null, (new CCol($action))->addClass(ZBX_STYLE_NOWRAP)]);
         }
     }
 } else {
     if (!$csvExport) {
Beispiel #10
0
/**
 * Converts numerical action condition values to their corresponding string values according to action condition type.
 *
 * For action condition types such as: hosts, host groups, templates, proxies, triggers, discovery rules
 * and discovery checks, action condition values contain IDs. All unique IDs are first collected and then queried.
 * For other action condition types values are returned as they are or converted using simple string convertion
 * functions according to action condition type.
 *
 * @param array $actions							array of actions
 * @param array $action['filter']					array containing arrays of action conditions and other data
 * @param array $action['filter']['conditions']		array of action conditions
 * @param array $config								array containing configuration parameters for getting trigger
 *													severity names
 *
 * @return array									returns an array of actions condition string values
 */
function actionConditionValueToString(array $actions, array $config)
{
    $result = [];
    $groupIds = [];
    $triggerIds = [];
    $hostIds = [];
    $templateIds = [];
    $proxyIds = [];
    $dRuleIds = [];
    $dCheckIds = [];
    foreach ($actions as $i => $action) {
        $result[$i] = [];
        foreach ($action['filter']['conditions'] as $j => $condition) {
            // unknown types and all of the default values for other types are 'Unknown'
            $result[$i][$j] = _('Unknown');
            switch ($condition['conditiontype']) {
                case CONDITION_TYPE_HOST_GROUP:
                    $groupIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_TRIGGER:
                    $triggerIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_HOST:
                    $hostIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_TEMPLATE:
                    $templateIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_PROXY:
                    $proxyIds[$condition['value']] = $condition['value'];
                    break;
                    // return values as is for following condition types
                // return values as is for following condition types
                case CONDITION_TYPE_TRIGGER_NAME:
                case CONDITION_TYPE_HOST_METADATA:
                case CONDITION_TYPE_HOST_NAME:
                case CONDITION_TYPE_TIME_PERIOD:
                case CONDITION_TYPE_DHOST_IP:
                case CONDITION_TYPE_DSERVICE_PORT:
                case CONDITION_TYPE_DUPTIME:
                case CONDITION_TYPE_DVALUE:
                case CONDITION_TYPE_APPLICATION:
                    $result[$i][$j] = $condition['value'];
                    break;
                case CONDITION_TYPE_EVENT_ACKNOWLEDGED:
                    $result[$i][$j] = $condition['value'] ? _('Ack') : _('Not Ack');
                    break;
                case CONDITION_TYPE_MAINTENANCE:
                    $result[$i][$j] = _('maintenance');
                    break;
                case CONDITION_TYPE_TRIGGER_VALUE:
                    $result[$i][$j] = trigger_value2str($condition['value']);
                    break;
                case CONDITION_TYPE_TRIGGER_SEVERITY:
                    $result[$i][$j] = getSeverityName($condition['value'], $config);
                    break;
                case CONDITION_TYPE_DRULE:
                    $dRuleIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_DCHECK:
                    $dCheckIds[$condition['value']] = $condition['value'];
                    break;
                case CONDITION_TYPE_DOBJECT:
                    $result[$i][$j] = discovery_object2str($condition['value']);
                    break;
                case CONDITION_TYPE_DSERVICE_TYPE:
                    $result[$i][$j] = discovery_check_type2str($condition['value']);
                    break;
                case CONDITION_TYPE_DSTATUS:
                    $result[$i][$j] = discovery_object_status2str($condition['value']);
                    break;
                case CONDITION_TYPE_EVENT_TYPE:
                    $result[$i][$j] = eventType($condition['value']);
                    break;
            }
        }
    }
    $groups = [];
    $triggers = [];
    $hosts = [];
    $templates = [];
    $proxies = [];
    $dRules = [];
    $dChecks = [];
    if ($groupIds) {
        $groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => $groupIds, 'preservekeys' => true]);
    }
    if ($triggerIds) {
        $triggers = API::Trigger()->get(['output' => ['description'], 'triggerids' => $triggerIds, 'expandDescription' => true, 'selectHosts' => ['name'], 'preservekeys' => true]);
    }
    if ($hostIds) {
        $hosts = API::Host()->get(['output' => ['name'], 'hostids' => $hostIds, 'preservekeys' => true]);
    }
    if ($templateIds) {
        $templates = API::Template()->get(['output' => ['name'], 'templateids' => $templateIds, 'preservekeys' => true]);
    }
    if ($proxyIds) {
        $proxies = API::Proxy()->get(['output' => ['host'], 'proxyids' => $proxyIds, 'preservekeys' => true]);
    }
    if ($dRuleIds) {
        $dRules = API::DRule()->get(['output' => ['name'], 'druleids' => $dRuleIds, 'preservekeys' => true]);
    }
    if ($dCheckIds) {
        $dChecks = API::DCheck()->get(['output' => ['type', 'key_', 'ports'], 'dcheckids' => $dCheckIds, 'selectDRules' => ['name'], 'preservekeys' => true]);
    }
    if ($groups || $triggers || $hosts || $templates || $proxies || $dRules || $dChecks) {
        foreach ($actions as $i => $action) {
            foreach ($action['filter']['conditions'] as $j => $condition) {
                $id = $condition['value'];
                switch ($condition['conditiontype']) {
                    case CONDITION_TYPE_HOST_GROUP:
                        if (isset($groups[$id])) {
                            $result[$i][$j] = $groups[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_TRIGGER:
                        if (isset($triggers[$id])) {
                            $host = reset($triggers[$id]['hosts']);
                            $result[$i][$j] = $host['name'] . NAME_DELIMITER . $triggers[$id]['description'];
                        }
                        break;
                    case CONDITION_TYPE_HOST:
                        if (isset($hosts[$id])) {
                            $result[$i][$j] = $hosts[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_TEMPLATE:
                        if (isset($templates[$id])) {
                            $result[$i][$j] = $templates[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_PROXY:
                        if (isset($proxies[$id])) {
                            $result[$i][$j] = $proxies[$id]['host'];
                        }
                        break;
                    case CONDITION_TYPE_DRULE:
                        if (isset($dRules[$id])) {
                            $result[$i][$j] = $dRules[$id]['name'];
                        }
                        break;
                    case CONDITION_TYPE_DCHECK:
                        if (isset($dChecks[$id])) {
                            $drule = reset($dChecks[$id]['drules']);
                            $type = $dChecks[$id]['type'];
                            $key_ = $dChecks[$id]['key_'];
                            $ports = $dChecks[$id]['ports'];
                            $dCheck = discovery_check2str($type, $key_, $ports);
                            $result[$i][$j] = $drule['name'] . NAME_DELIMITER . $dCheck;
                        }
                        break;
                }
            }
        }
    }
    return $result;
}
    $userMessagingFormList->addRow(_('Message timeout (seconds)'), (new CNumericBox('messages[timeout]', $this->data['messages']['timeout'], 5))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH), 'timeout_row');
    $repeatSound = new CComboBox('messages[sounds.repeat]', $this->data['messages']['sounds.repeat'], 'if (IE) { submit() }', [1 => _('Once'), 10 => '10 ' . _('Seconds'), -1 => _('Message timeout')]);
    $userMessagingFormList->addRow(_('Play sound'), $repeatSound, 'repeat_row');
    $soundList = new CComboBox('messages[sounds.recovery]', $this->data['messages']['sounds.recovery']);
    foreach ($zbxSounds as $filename => $file) {
        $soundList->addItem($file, $filename);
    }
    $triggersTable = (new CTable())->addRow([new CLabel([(new CCheckBox('messages[triggers.recovery]'))->setChecked($this->data['messages']['triggers.recovery'] == 1), _('Recovery')], 'messages[triggers.recovery]'), [$soundList, (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CButton('start', _('Play')))->addClass(ZBX_STYLE_BTN_GREY)->onClick("javascript: testUserSound('messages_sounds.recovery');"), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CButton('stop', _('Stop')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('javascript: AudioControl.stop();')]]);
    $msgVisibility = ['1' => ['messages[timeout]', 'messages[sounds.repeat]', 'messages[sounds.recovery]', 'messages[triggers.recovery]', 'timeout_row', 'repeat_row', 'triggers_row']];
    // trigger sounds
    for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
        $soundList = new CComboBox('messages[sounds.' . $severity . ']', $this->data['messages']['sounds.' . $severity]);
        foreach ($zbxSounds as $filename => $file) {
            $soundList->addItem($file, $filename);
        }
        $triggersTable->addRow([new CLabel([(new CCheckBox('messages[triggers.severities][' . $severity . ']'))->setChecked(isset($this->data['messages']['triggers.severities'][$severity])), getSeverityName($severity, $this->data['config'])], 'messages[triggers.severities][' . $severity . ']'), [$soundList, (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CButton('start', _('Play')))->addClass(ZBX_STYLE_BTN_GREY)->onClick("javascript: testUserSound('messages_sounds." . $severity . "');"), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CButton('stop', _('Stop')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('javascript: AudioControl.stop();')]]);
        zbx_subarray_push($msgVisibility, 1, 'messages[triggers.severities][' . $severity . ']');
        zbx_subarray_push($msgVisibility, 1, 'messages[sounds.' . $severity . ']');
    }
    $userMessagingFormList->addRow(_('Trigger severity'), $triggersTable, 'triggers_row');
}
// append form lists to tab
$userTab = new CTabView();
if (!$this->data['form_refresh']) {
    $userTab->setSelected(0);
}
$userTab->addTab('userTab', _('User'), $userFormList);
if (isset($userMediaFormList)) {
    $userTab->addTab('mediaTab', _('Media'), $userMediaFormList);
}
if (!$this->data['is_profile']) {
Beispiel #12
0
/**
 * Returns HTML representation of trigger severity cell containing severity name and color.
 *
 * @param int	 $severity			trigger severity
 * @param array  $config			array of configuration parameters to get trigger severity name
 * @param string $text				trigger severity name
 * @param bool	 $forceNormal		true to return 'normal' class, false to return corresponding severity class
 *
 * @return CCol
 */
function getSeverityCell($severity, $config, $text = null, $forceNormal = false)
{
    if ($text === null) {
        $text = CHtml::encode(getSeverityName($severity, $config));
    }
    return (new CCol($text))->addClass(getSeverityStyle($severity, !$forceNormal));
}
Beispiel #13
0
 /**
  * Initialize minimum trigger severities.
  *
  * @param string $severityMin			minimum trigger severity
  * @param array  $options				array of options
  * @param int    $options['default']	default severity
  * @param string $options['mapId']		ID of a map
  * @param array	 $config				array of configuration parameters for getting severity names
  *
  * @return void
  */
 private function _initSeveritiesMin($severityMin, array $options, array $config)
 {
     $default = isset($options['default']) ? $options['default'] : TRIGGER_SEVERITY_NOT_CLASSIFIED;
     $mapId = isset($options['mapId']) ? $options['mapId'] : 0;
     $severityMinProfile = isset($this->_profileIds['severityMin']) ? $this->_profileIds['severityMin'] : null;
     if ($severityMin === null && $severityMinProfile !== null) {
         $severityMin = $severityMinProfile;
     }
     if ($severityMin !== null) {
         if ($severityMin == $default) {
             CProfile::delete($this->_profileIdx['severityMin'], $mapId);
         } else {
             CProfile::update($this->_profileIdx['severityMin'], $severityMin, PROFILE_TYPE_INT, $mapId);
         }
     }
     $this->data['severitiesMin'] = [];
     for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
         $severityName = getSeverityName($severity, $config);
         if ($severity == $default) {
             $this->data['severitiesMin'][] = $severityName . SPACE . '(' . _('default') . ')';
         } else {
             $this->data['severitiesMin'][] = $severityName;
         }
     }
     $this->ids['severityMin'] = $severityMin === null ? $default : $severityMin;
 }
     $condition = (new CTextBox('new_condition[value]', ''))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH);
     break;
 case CONDITION_TYPE_TRIGGER_VALUE:
     $triggerValues = [];
     foreach ([TRIGGER_VALUE_FALSE, TRIGGER_VALUE_TRUE] as $triggerValue) {
         $triggerValues[$triggerValue] = trigger_value2str($triggerValue);
     }
     $condition = new CComboBox('new_condition[value]', null, null, $triggerValues);
     break;
 case CONDITION_TYPE_TIME_PERIOD:
     $condition = (new CTextBox('new_condition[value]', ZBX_DEFAULT_INTERVAL))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH);
     break;
 case CONDITION_TYPE_TRIGGER_SEVERITY:
     $severityNames = [];
     for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
         $severityNames[] = getSeverityName($severity, $this->data['config']);
     }
     $condition = new CComboBox('new_condition[value]', null, null, $severityNames);
     break;
 case CONDITION_TYPE_MAINTENANCE:
     $condition = _('maintenance');
     break;
 case CONDITION_TYPE_DRULE:
     $conditionFormList->addItem(new CVar('new_condition[value]', '0'));
     $condition = [(new CTextBox('drule', '', true))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CButton('btn1', _('Select')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('return PopUp("popup.php?srctbl=drules&srcfld1=druleid&srcfld2=name' . '&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value&dstfld2=drule");')];
     break;
 case CONDITION_TYPE_DCHECK:
     $conditionFormList->addItem(new CVar('new_condition[value]', '0'));
     $condition = [(new CTextBox('dcheck', '', true))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CButton('btn1', _('Select')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('return PopUp("popup.php?srctbl=dchecks&srcfld1=dcheckid&srcfld2=name' . '&dstfrm=' . $actionForm->getName() . '&dstfld1=new_condition_value&dstfld2=dcheck&writeonly=1");')];
     break;
 case CONDITION_TYPE_PROXY:
Beispiel #15
0
    $severities = [];
    for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
        if ($severityRequest & 1 << $severity) {
            $severities[$severity] = $severity;
        }
    }
} else {
    $severities = getRequest('severity', array_keys($severityNames));
}
$media = getRequest('media', -1);
$sendto = getRequest('sendto', '');
$mediatypeid = getRequest('mediatypeid', 0);
$active = getRequest('active', MEDIA_STATUS_ACTIVE);
$period = getRequest('period', ZBX_DEFAULT_INTERVAL);
$mediatypes = API::MediaType()->get(['output' => ['description'], 'preservekeys' => true]);
CArrayHelper::sort($mediatypes, ['description']);
foreach ($mediatypes as &$mediatype) {
    $mediatype = $mediatype['description'];
}
unset($mediatype);
$frm_row = [];
for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
    $frm_row[] = new CLabel([(new CCheckBox('severity[' . $severity . ']', $severity))->setChecked(str_in_array($severity, $severities)), getSeverityName($severity, $config)], 'severity[' . $severity . ']');
    $frm_row[] = BR();
}
array_pop($frm_row);
$frmMedia = (new CFormList(_('Media')))->addRow(_('Type'), new CComboBox('mediatypeid', $mediatypeid, null, $mediatypes))->addRow(_('Send to'), (new CTextBox('sendto', $sendto, false, 100))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH))->addRow(_('When active'), (new CTextBox('period', $period, false, 100))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH))->addRow(_('Use if severity'), $frm_row)->addRow(_('Enabled'), (new CCheckBox('active', MEDIA_STATUS_ACTIVE))->setChecked($active == MEDIA_STATUS_ACTIVE));
$mediaTab = (new CTabView())->addTab('mediaTab', _('Media'), $frmMedia)->setFooter(makeFormFooter(new CSubmit('add', $media > -1 ? _('Update') : _('Add')), [new CButtonCancel(null, 'window.close();')]));
$form = (new CForm())->addVar('media', $media)->addVar('dstfrm', $_REQUEST['dstfrm'])->addItem($mediaTab);
$widget = (new CWidget())->setTitle(_('Media'))->addItem($form)->show();
require_once dirname(__FILE__) . '/include/page_footer.php';