Beispiel #1
0
 protected function calcTriggers()
 {
     $this->triggers = array();
     if ($this->m_showTriggers != 1) {
         return;
     }
     $max = 3;
     $cnt = 0;
     foreach ($this->items as $inum => $item) {
         $db_triggers = DBselect('SELECT DISTINCT h.host,tr.description,tr.triggerid,tr.expression,tr.priority,tr.value' . ' FROM triggers tr,functions f,items i,hosts h' . ' WHERE tr.triggerid=f.triggerid' . " AND f.function IN ('last','min','avg','max')" . ' AND tr.status=' . TRIGGER_STATUS_ENABLED . ' AND i.itemid=f.itemid' . ' AND h.hostid=i.hostid' . ' AND f.itemid=' . $item['itemid'] . ' ORDER BY tr.priority');
         while (($trigger = DBfetch($db_triggers)) && $cnt < $max) {
             $db_fnc_cnt = DBselect('SELECT COUNT(*) AS cnt FROM functions f WHERE f.triggerid=' . $trigger['triggerid']);
             $fnc_cnt = DBfetch($db_fnc_cnt);
             if ($fnc_cnt['cnt'] != 1) {
                 continue;
             }
             $trigger = API::UserMacro()->resolveTrigger($trigger);
             if (!preg_match('/^\\{([0-9]+)\\}\\s*?([\\<\\>\\=]{1})\\s*?([\\-0-9\\.]+)([TGMKsmhdw]?)$/', $trigger['expression'], $arr)) {
                 continue;
             }
             $val = convert($arr[3] . $arr[4]);
             $minY = $this->m_minY[$this->items[$inum]['axisside']];
             $maxY = $this->m_maxY[$this->items[$inum]['axisside']];
             $this->triggers[] = array('skipdraw' => $val <= $minY || $val >= $maxY, 'y' => $this->sizeY - ($val - $minY) / ($maxY - $minY) * $this->sizeY + $this->shiftY, 'color' => getSeverityColor($trigger['priority']), 'description' => _('Trigger') . ': ' . CTriggerHelper::expandDescription($trigger), 'constant' => '[' . $arr[2] . ' ' . $arr[3] . $arr[4] . ']');
             ++$cnt;
         }
     }
 }
require_once dirname(__FILE__) . '/include/views/js/general.script.confirm.js.php';
// get triggers
$options = array('triggerids' => $_REQUEST['triggerid'], 'expandData' => 1, 'selectHosts' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND);
$triggers = API::Trigger()->get($options);
if (empty($triggers)) {
    access_deny();
}
$trigger = reset($triggers);
// get events
$options = array('eventids' => $_REQUEST['eventid'], 'triggerids' => $_REQUEST['triggerid'], 'select_alerts' => API_OUTPUT_EXTEND, 'select_acknowledges' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND, 'selectHosts' => API_OUTPUT_EXTEND);
$events = API::Event()->get($options);
$event = reset($events);
$tr_event_wdgt = new CWidget();
$tr_event_wdgt->setClass('header');
// Main widget header
$text = array(_('EVENTS') . ': "' . CTriggerHelper::expandDescription($trigger) . '"');
$fs_icon = get_icon('fullscreen', array('fullscreen' => $_REQUEST['fullscreen']));
$tr_event_wdgt->addHeader($text, $fs_icon);
$left_col = array();
// tr details
$triggerDetails = new CUIWidget('hat_triggerdetails', make_trigger_details($trigger));
$triggerDetails->setHeader(_('Event source details'));
$left_col[] = $triggerDetails;
// event details
$eventDetails = new CUIWidget('hat_eventdetails', make_event_details($event, $trigger));
$eventDetails->setHeader(_('Event details'));
$left_col[] = $eventDetails;
$right_col = array();
// if acknowledges are not disabled in configuration, let's show them
if ($config['event_ack_enable']) {
    $event_ack = new CUIWidget('hat_eventack', makeAckTab($event), CProfile::get('web.tr_events.hats.hat_eventack.state', 1));
function make_trigger_details($trigger)
{
    $table = new CTableInfo();
    if (is_show_all_nodes()) {
        $table->addRow(array(_('Node'), get_node_name_by_elid($trigger['triggerid'])));
    }
    $expression = explode_exp($trigger['expression'], true, true);
    $host = API::Host()->get(array('output' => array('name', 'hostid'), 'hostids' => $trigger['hosts'][0]['hostid'], 'selectScreens' => API_OUTPUT_COUNT, 'selectInventory' => array('hostid'), 'preservekeys' => true));
    $host = reset($host);
    $hostScripts = API::Script()->getScriptsByHosts($host['hostid']);
    // host js link
    $hostSpan = new CSpan($host['name'], 'link_menu menu-host');
    $scripts = $hostScripts[$host['hostid']];
    $hostSpan->attr('data-menu', hostMenuData($host, $scripts));
    // get visible name of the first host
    $table->addRow(array(_('Host'), $hostSpan));
    $table->addRow(array(_('Trigger'), CTriggerHelper::expandDescription($trigger)));
    $table->addRow(array(_('Severity'), getSeverityCell($trigger['priority'])));
    $table->addRow(array(_('Expression'), $expression));
    $table->addRow(array(_('Event generation'), _('Normal') . (TRIGGER_MULT_EVENT_ENABLED == $trigger['type'] ? SPACE . '+' . SPACE . _('Multiple PROBLEM events') : '')));
    $table->addRow(array(_('Disabled'), TRIGGER_STATUS_ENABLED == $trigger['status'] ? new CCol(_('No'), 'off') : new CCol(_('Yes'), 'on')));
    return $table;
}
 $description = new CSpan($trigger['description'], 'link');
 $trigger['description'] = $trigger['hostname'] . ': ' . $trigger['description'];
 if ($multiselect) {
     $js_action = 'addValue(' . zbx_jsvalue($reference) . ', ' . zbx_jsvalue($trigger['triggerid']) . ');';
 } else {
     $values = array($dstfld1 => $trigger[$srcfld1], $dstfld2 => $trigger[$srcfld2]);
     if (isset($srcfld3)) {
         $values[$dstfld3] = $trigger[$srcfld3];
     }
     $js_action = 'addValues(' . zbx_jsvalue($dstfrm) . ', ' . zbx_jsvalue($values) . '); return false;';
 }
 $description->setAttribute('onclick', $js_action . ' jQuery(this).removeAttr("onclick");');
 if (count($trigger['dependencies']) > 0) {
     $description = array($description, BR(), bold(_('Depends on')), BR());
     foreach ($trigger['dependencies'] as $val) {
         $description[] = array(CTriggerHelper::expandDescription($val), BR());
     }
 }
 switch ($trigger['status']) {
     case TRIGGER_STATUS_DISABLED:
         $status = new CSpan(_('Disabled'), 'disabled');
         break;
     case TRIGGER_STATUS_ENABLED:
         $status = new CSpan(_('Enabled'), 'enabled');
         break;
 }
 $table->addRow(array($multiselect ? new CCheckBox('triggers[' . zbx_jsValue($trigger[$srcfld1]) . ']', null, null, $trigger['triggerid']) : null, $description, getSeverityCell($trigger['priority']), $status));
 // made to save memmory usage
 if ($multiselect) {
     $jsTriggers[$trigger['triggerid']] = array('triggerid' => $trigger['triggerid'], 'description' => $trigger['description'], 'expression' => $trigger['expression'], 'priority' => $trigger['priority'], 'status' => $trigger['status'], 'host' => $trigger['hostname']);
 }
function getSelementsInfo($sysmap)
{
    $config = select_config();
    $show_unack = $config['event_ack_enable'] ? $sysmap['show_unack'] : EXTACK_OPTION_ALL;
    $triggers_map = array();
    $triggers_map_submaps = array();
    $hostgroups_map = array();
    $hosts_map = array();
    if ($sysmap['sysmapid']) {
        $iconMap = API::IconMap()->get(array('sysmapids' => $sysmap['sysmapid'], 'selectMappings' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND));
        $iconMap = reset($iconMap);
        $hostsToGetInventories = array();
    }
    $selements = zbx_toHash($sysmap['selements'], 'selementid');
    foreach ($selements as $selementid => $selement) {
        $selements[$selementid]['hosts'] = array();
        $selements[$selementid]['triggers'] = array();
        switch ($selement['elementtype']) {
            case SYSMAP_ELEMENT_TYPE_MAP:
                $mapids = array($selement['elementid']);
                while (!empty($mapids)) {
                    $maps = API::Map()->get(array('sysmapids' => $mapids, 'output' => API_OUTPUT_REFER, 'selectSelements' => API_OUTPUT_EXTEND, 'nopermissions' => true, 'nodeids' => get_current_nodeid(true)));
                    $mapids = array();
                    foreach ($maps as $map) {
                        foreach ($map['selements'] as $sel) {
                            switch ($sel['elementtype']) {
                                case SYSMAP_ELEMENT_TYPE_MAP:
                                    $mapids[] = $sel['elementid'];
                                    break;
                                case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                                    $hostgroups_map[$sel['elementid']][$selementid] = $selementid;
                                    break;
                                case SYSMAP_ELEMENT_TYPE_HOST:
                                    $hosts_map[$sel['elementid']][$selementid] = $selementid;
                                    break;
                                case SYSMAP_ELEMENT_TYPE_TRIGGER:
                                    $triggers_map_submaps[$sel['elementid']][$selementid] = $selementid;
                                    break;
                            }
                        }
                    }
                }
                break;
            case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                $hostgroups_map[$selement['elementid']][$selement['selementid']] = $selement['selementid'];
                break;
            case SYSMAP_ELEMENT_TYPE_HOST:
                $hosts_map[$selement['elementid']][$selement['selementid']] = $selement['selementid'];
                // if we have icon map applied, we need to get inventories for all hosts,
                // where automatic icon selection is enabled.
                if ($sysmap['iconmapid'] && $selement['use_iconmap']) {
                    $hostsToGetInventories[] = $selement['elementid'];
                }
                break;
            case SYSMAP_ELEMENT_TYPE_TRIGGER:
                $triggers_map[$selement['elementid']][$selement['selementid']] = $selement['selementid'];
                break;
        }
    }
    // get host inventories
    if ($sysmap['iconmapid']) {
        $hostInventories = API::Host()->get(array('hostids' => $hostsToGetInventories, 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => true, 'preservekeys' => true, 'selectInventory' => API_OUTPUT_EXTEND));
    }
    $all_hosts = array();
    if (!empty($hosts_map)) {
        $hosts = API::Host()->get(array('hostids' => array_keys($hosts_map), 'output' => array('name', 'status', 'maintenance_status', 'maintenanceid'), 'nopermissions' => true, 'nodeids' => get_current_nodeid(true)));
        $all_hosts = array_merge($all_hosts, $hosts);
        foreach ($hosts as $host) {
            foreach ($hosts_map[$host['hostid']] as $belongs_to_sel) {
                $selements[$belongs_to_sel]['hosts'][$host['hostid']] = $host['hostid'];
            }
        }
    }
    if (!empty($hostgroups_map)) {
        $hosts = API::Host()->get(array('groupids' => array_keys($hostgroups_map), 'output' => array('name', 'status', 'maintenance_status', 'maintenanceid'), 'nopermissions' => true, 'nodeids' => get_current_nodeid(true)));
        $all_hosts = array_merge($all_hosts, $hosts);
        foreach ($hosts as $host) {
            foreach ($host['groups'] as $group) {
                if (isset($hostgroups_map[$group['groupid']])) {
                    foreach ($hostgroups_map[$group['groupid']] as $belongs_to_sel) {
                        $selements[$belongs_to_sel]['hosts'][$host['hostid']] = $host['hostid'];
                        // add hosts to hosts_map for trigger selection;
                        if (!isset($hosts_map[$host['hostid']])) {
                            $hosts_map[$host['hostid']] = array();
                        }
                        $hosts_map[$host['hostid']][$belongs_to_sel] = $belongs_to_sel;
                    }
                }
            }
        }
    }
    $all_hosts = zbx_toHash($all_hosts, 'hostid');
    $monitored_hostids = array();
    foreach ($all_hosts as $hostid => $host) {
        if ($host['status'] == HOST_STATUS_MONITORED) {
            $monitored_hostids[$hostid] = $hostid;
        }
    }
    // get triggers data, triggers from current map, select all
    $all_triggers = array();
    if (!empty($triggers_map)) {
        $triggers = API::Trigger()->get(array('nodeids' => get_current_nodeid(true), 'triggerids' => array_keys($triggers_map), 'filter' => array('value_flags' => null), 'output' => API_OUTPUT_EXTEND, 'nopermissions' => true));
        $all_triggers = array_merge($all_triggers, $triggers);
        foreach ($triggers as $trigger) {
            foreach ($triggers_map[$trigger['triggerid']] as $belongs_to_sel) {
                $selements[$belongs_to_sel]['triggers'][$trigger['triggerid']] = $trigger['triggerid'];
            }
        }
    }
    // triggers from submaps, skip dependent
    if (!empty($triggers_map_submaps)) {
        $triggers = API::Trigger()->get(array('nodeids' => get_current_nodeid(true), 'triggerids' => array_keys($triggers_map_submaps), 'filter' => array('value_flags' => null), 'skipDependent' => true, 'output' => API_OUTPUT_EXTEND, 'nopermissions' => true));
        $all_triggers = array_merge($all_triggers, $triggers);
        foreach ($triggers as $trigger) {
            foreach ($triggers_map_submaps[$trigger['triggerid']] as $belongs_to_sel) {
                $selements[$belongs_to_sel]['triggers'][$trigger['triggerid']] = $trigger['triggerid'];
            }
        }
    }
    // triggers from all hosts/hostgroups, skip dependent
    if (!empty($monitored_hostids)) {
        $triggers = API::Trigger()->get(array('hostids' => $monitored_hostids, 'output' => array('status', 'value', 'priority', 'lastchange', 'description', 'expression'), 'nopermissions' => true, 'filter' => array('value_flags' => null), 'nodeids' => get_current_nodeid(true), 'monitored' => true, 'skipDependent' => true));
        $all_triggers = array_merge($all_triggers, $triggers);
        foreach ($triggers as $trigger) {
            foreach ($trigger['hosts'] as $host) {
                if (isset($hosts_map[$host['hostid']])) {
                    foreach ($hosts_map[$host['hostid']] as $belongs_to_sel) {
                        $selements[$belongs_to_sel]['triggers'][$trigger['triggerid']] = $trigger['triggerid'];
                    }
                }
            }
        }
    }
    $all_triggers = zbx_toHash($all_triggers, 'triggerid');
    $unack_triggerids = API::Trigger()->get(array('triggerids' => array_keys($all_triggers), 'withLastEventUnacknowledged' => true, 'output' => API_OUTPUT_SHORTEN, 'nodeids' => get_current_nodeid(true), 'nopermissions' => true, 'monitored' => true, 'filter' => array('value' => TRIGGER_VALUE_TRUE, 'value_flags' => null)));
    $unack_triggerids = zbx_toHash($unack_triggerids, 'triggerid');
    $info = array();
    foreach ($selements as $selementid => $selement) {
        $i = array('disabled' => 0, 'maintenance' => 0, 'problem' => 0, 'problem_unack' => 0, 'unknown' => 0, 'priority' => 0, 'trigger_disabled' => 0, 'latelyChanged' => false, 'ack' => true);
        foreach ($selement['hosts'] as $hostid) {
            $host = $all_hosts[$hostid];
            $last_hostid = $hostid;
            if ($host['status'] == HOST_STATUS_NOT_MONITORED) {
                $i['disabled']++;
            } elseif ($host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) {
                $i['maintenance']++;
            }
        }
        foreach ($selement['triggers'] as $triggerid) {
            $trigger = $all_triggers[$triggerid];
            if ($trigger['status'] == TRIGGER_STATUS_DISABLED) {
                $i['trigger_disabled']++;
            } else {
                if ($trigger['value'] == TRIGGER_VALUE_TRUE) {
                    $i['problem']++;
                    $last_problemid = $triggerid;
                    if ($i['priority'] < $trigger['priority']) {
                        $i['priority'] = $trigger['priority'];
                    }
                }
                if (isset($unack_triggerids[$triggerid])) {
                    $i['problem_unack']++;
                }
                $config = select_config();
                $i['latelyChanged'] |= time() - $trigger['lastchange'] < $config['blink_period'];
            }
        }
        $i['ack'] = (bool) (!$i['problem_unack']);
        if ($sysmap['expandproblem'] && $i['problem'] == 1) {
            $i['problem_title'] = CTriggerHelper::expandDescription($all_triggers[$last_problemid]);
        }
        if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST && $i['maintenance'] == 1) {
            $mnt = get_maintenance_by_maintenanceid($all_hosts[$last_hostid]['maintenanceid']);
            $i['maintenance_title'] = $mnt['name'];
        }
        // replace default icons
        if (!$selement['iconid_on']) {
            $selement['iconid_on'] = $selement['iconid_off'];
        }
        if (!$selement['iconid_maintenance']) {
            $selement['iconid_maintenance'] = $selement['iconid_off'];
        }
        if (!$selement['iconid_disabled']) {
            $selement['iconid_disabled'] = $selement['iconid_off'];
        }
        switch ($selement['elementtype']) {
            case SYSMAP_ELEMENT_TYPE_MAP:
                $info[$selementid] = getMapsInfo($selement, $i, $show_unack);
                break;
            case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                $info[$selementid] = getHostGroupsInfo($selement, $i, $show_unack);
                break;
            case SYSMAP_ELEMENT_TYPE_HOST:
                $info[$selementid] = getHostsInfo($selement, $i, $show_unack);
                if ($sysmap['iconmapid'] && $selement['use_iconmap']) {
                    $info[$selementid]['iconid'] = getIconByMapping($iconMap, $hostInventories[$selement['elementid']]);
                }
                break;
            case SYSMAP_ELEMENT_TYPE_TRIGGER:
                $info[$selementid] = getTriggersInfo($selement, $i, $show_unack);
                break;
            case SYSMAP_ELEMENT_TYPE_IMAGE:
                $info[$selementid] = getImagesInfo($selement);
                break;
        }
    }
    if ($sysmap['label_format'] == SYSMAP_LABEL_ADVANCED_OFF) {
        $hlabel = $hglabel = $tlabel = $mlabel = $sysmap['label_type'] == MAP_LABEL_TYPE_NAME;
    } else {
        $hlabel = $sysmap['label_type_host'] == MAP_LABEL_TYPE_NAME;
        $hglabel = $sysmap['label_type_hostgroup'] == MAP_LABEL_TYPE_NAME;
        $tlabel = $sysmap['label_type_trigger'] == MAP_LABEL_TYPE_NAME;
        $mlabel = $sysmap['label_type_map'] == MAP_LABEL_TYPE_NAME;
    }
    // get names if needed
    $elems = separateMapElements($sysmap);
    if (!empty($elems['sysmaps']) && $mlabel) {
        $maps = API::Map()->get(array('sysmapids' => zbx_objectValues($elems['sysmaps'], 'elementid'), 'nopermissions' => true, 'output' => array('name')));
        $maps = zbx_toHash($maps, 'sysmapid');
        foreach ($elems['sysmaps'] as $elem) {
            $info[$elem['selementid']]['name'] = $maps[$elem['elementid']]['name'];
        }
    }
    if (!empty($elems['hostgroups']) && $hglabel) {
        $hostgroups = API::HostGroup()->get(array('groupids' => zbx_objectValues($elems['hostgroups'], 'elementid'), 'nopermissions' => true, 'output' => array('name')));
        $hostgroups = zbx_toHash($hostgroups, 'groupid');
        foreach ($elems['hostgroups'] as $elem) {
            $info[$elem['selementid']]['name'] = $hostgroups[$elem['elementid']]['name'];
        }
    }
    if (!empty($elems['triggers']) && $tlabel) {
        foreach ($elems['triggers'] as $elem) {
            $info[$elem['selementid']]['name'] = CTriggerHelper::expandDescription($all_triggers[$elem['elementid']]);
        }
    }
    if (!empty($elems['hosts']) && $hlabel) {
        foreach ($elems['hosts'] as $elem) {
            $info[$elem['selementid']]['name'] = $all_hosts[$elem['elementid']]['name'];
        }
    }
    return $info;
}
    }
    if (isset($_REQUEST['saveandreturn'])) {
        ob_end_clean();
        if ($_REQUEST['backurl'] == 'tr_events.php') {
            redirect($_REQUEST['backurl'] . '?eventid=' . $_REQUEST['eventid'] . '&triggerid=' . $_REQUEST['triggerid']);
        } elseif ($_REQUEST['backurl'] == 'screenedit.php') {
            redirect($_REQUEST['backurl'] . '?screenid=' . $_REQUEST['screenid']);
        } elseif ($_REQUEST['backurl'] == 'screens.php') {
            redirect($_REQUEST['backurl'] . '?elementid=' . $_REQUEST['screenid']);
        } else {
            redirect($_REQUEST['backurl']);
        }
    }
}
ob_end_flush();
$msg = $bulk ? ' BULK ACKNOWLEDGE ' : CTriggerHelper::expandDescription($event_trigger);
show_table_header(array(_('ALARM ACKNOWLEDGES') . ': ', $msg));
echo SBR;
if ($bulk) {
    $title = _('Acknowledge alarm by');
    $btn_txt2 = _('Acknowledge and return');
} else {
    $db_acks = get_acknowledges_by_eventid($_REQUEST['eventid']);
    if ($db_acks) {
        $table = new CTable(null, 'ack_msgs');
        $table->setAlign('center');
        while ($db_ack = DBfetch($db_acks)) {
            $table->addRow(array(new CCol($db_ack['alias'], 'user'), new CCol(zbx_date2str(_('d M Y H:i:s'), $db_ack['clock']), 'time')), 'title');
            $msgCol = new CCol(zbx_nl2br($db_ack['message']));
            $msgCol->setColspan(2);
            $table->addRow($msgCol, 'msg');