Esempio n. 1
0
/**
 * Creates and returns a trigger status cell for the trigger overview table.
 *
 * @see getTriggersOverview()
 *
 * @param array  $trigger
 * @param string $pageFile		the page where the element is displayed
 * @param string $screenid
 *
 * @return CCol
 */
function getTriggerOverviewCells($trigger, $pageFile, $screenid = null)
{
    $ack = null;
    $css = null;
    $desc = [];
    $acknowledge = [];
    // for how long triggers should blink on status change (set by user in administration->general)
    $config = select_config();
    if ($trigger) {
        $css = getSeverityStyle($trigger['priority'], $trigger['value'] == TRIGGER_VALUE_TRUE);
        // problem trigger
        if ($trigger['value'] == TRIGGER_VALUE_TRUE) {
            $ack = null;
            if ($config['event_ack_enable']) {
                if ($event = get_last_event_by_triggerid($trigger['triggerid'])) {
                    if ($screenid !== null) {
                        $acknowledge = ['eventid' => $event['eventid'], 'backurl' => $pageFile . '?screenid=' . $screenid];
                    } else {
                        $acknowledge = ['eventid' => $event['eventid'], 'backurl' => $pageFile];
                    }
                    if ($event['acknowledged'] == 1) {
                        $ack = (new CSpan())->addClass(ZBX_STYLE_ICON_ACKN);
                    }
                }
            }
        }
        // dependency: triggers on which depends this
        $triggerId = empty($trigger['triggerid']) ? 0 : $trigger['triggerid'];
        // trigger dependency DOWN
        $dependencyTable = (new CTableInfo())->setAttribute('style', 'width: 200px;')->addRow(bold(_('Depends on') . ':'));
        $isDependencyFound = false;
        $dbDependencies = DBselect('SELECT td.* FROM trigger_depends td WHERE td.triggerid_down=' . zbx_dbstr($triggerId));
        while ($dbDependency = DBfetch($dbDependencies)) {
            $dependencyTable->addRow(SPACE . '-' . SPACE . CMacrosResolverHelper::resolveTriggerNameById($dbDependency['triggerid_up']));
            $isDependencyFound = true;
        }
        if ($isDependencyFound) {
            $desc[] = (new CSpan())->addClass(ZBX_STYLE_ICON_DEPEND_DOWN)->setHint($dependencyTable, '', false);
        }
        // trigger dependency UP
        $dependencyTable = (new CTableInfo())->setAttribute('style', 'width: 200px;')->addRow(bold(_('Dependent') . ':'));
        $isDependencyFound = false;
        $dbDependencies = DBselect('SELECT td.* FROM trigger_depends td WHERE td.triggerid_up=' . zbx_dbstr($triggerId));
        while ($dbDependency = DBfetch($dbDependencies)) {
            $dependencyTable->addRow(SPACE . '-' . SPACE . CMacrosResolverHelper::resolveTriggerNameById($dbDependency['triggerid_down']));
            $isDependencyFound = true;
        }
        if ($isDependencyFound) {
            $desc[] = (new CSpan())->addClass(ZBX_STYLE_ICON_DEPEND_UP)->setHint($dependencyTable, '', false);
        }
    }
    $column = new CCol([$desc, $ack]);
    if ($css !== null) {
        $column->addClass($css)->addClass(ZBX_STYLE_CURSOR_POINTER);
    }
    if ($trigger && $config['blink_period'] > 0 && time() - $trigger['lastchange'] < $config['blink_period']) {
        $column->addClass('blink');
        $column->setAttribute('data-toggle-class', $css);
    }
    if ($trigger) {
        $column->setMenuPopup(CMenuPopupHelper::getTrigger($trigger, $acknowledge));
    }
    return $column;
}