Example #1
0
function make_latest_issues($params = array())
{
    global $USER_DETAILS;
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY);
    $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array());
    $scripts_by_hosts = get_accessible_scripts_by_hosts($available_hosts);
    $config = select_config();
    $sql_select = '';
    $sql_from = '';
    $sql_where = '';
    $limit = 20;
    if (!empty($params)) {
        if (isset($params['limit'])) {
            $limit = $params['limit'];
        }
        if (isset($params['groupid']) && $params['groupid'] > 0) {
            $sql_select .= ',g.name ';
            $sql_from .= ',groups g ';
            $sql_where .= ' AND g.groupid=hg.groupid ' . ' AND hg.groupid=' . $params['groupid'];
        }
        if (isset($params['hostid']) && $params['hostid'] > 0) {
            $sql_where .= ' AND h.hostid=' . $params['hostid'];
        }
    }
    $table = new CTableInfo();
    $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, isset($params['groupid']) && $params['groupid'] > 0 ? S_GROUP : null, S_HOST, S_ISSUE, S_LAST_CHANGE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS));
    $sql = 'SELECT DISTINCT t.triggerid,t.status,t.description,t.expression,t.priority,t.lastchange,t.value,h.host,h.hostid ' . $sql_select . ' FROM triggers t,hosts h,items i,functions f,hosts_groups hg ' . $sql_from . ' WHERE f.itemid=i.itemid ' . ' AND h.hostid=i.hostid ' . ' AND hg.hostid=h.hostid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND t.value=' . TRIGGER_VALUE_TRUE . $sql_where . ' ORDER BY t.lastchange DESC';
    $result = DBselect($sql, $limit);
    while ($row = DBfetch($result)) {
        // Check for dependencies
        if (trigger_dependent($row["triggerid"])) {
            continue;
        }
        $host = null;
        $menus = '';
        $host_nodeid = id2nodeid($row['hostid']);
        foreach ($scripts_by_hosts[$row['hostid']] as $id => $script) {
            $script_nodeid = id2nodeid($script['scriptid']);
            if (bccomp($host_nodeid, $script_nodeid) == 0) {
                $menus .= "['" . $script['name'] . "',\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $row['hostid'] . "&scriptid=" . $script['scriptid'] . "','" . S_TOOLS . "',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
            }
        }
        $menus .= "[" . zbx_jsvalue(S_LINKS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],";
        $menus .= "['" . S_LATEST_DATA . "',\"javascript: redirect('latest.php?groupid=0&hostid=" . $row['hostid'] . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
        $menus = rtrim($menus, ',');
        $menus = "show_popup_menu(event,[[" . zbx_jsvalue(S_TOOLS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus . "],180);";
        $host = new CSpan($row['host'], 'link');
        $host->setAttribute('onclick', 'javascript: ' . $menus);
        $host->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
        $event_sql = 'SELECT DISTINCT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged, t.type, t.url ' . ' FROM events e, triggers t ' . ' WHERE e.object=' . EVENT_SOURCE_TRIGGERS . ' AND e.objectid=' . $row['triggerid'] . ' AND t.triggerid=e.objectid ' . ' AND e.value=' . TRIGGER_VALUE_TRUE . ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC';
        $res_events = DBSelect($event_sql, 1);
        while ($row_event = DBfetch($res_events)) {
            $ack = NULL;
            if ($config['event_ack_enable']) {
                if ($row_event['acknowledged'] == 1) {
                    $ack_info = make_acktab_by_eventid($row_event['eventid']);
                    $ack_info->setAttribute('style', 'width: auto;');
                    $ack = new CLink(S_YES, 'acknow.php?eventid=' . $row_event['eventid'], 'action');
                    $ack->setHint($ack_info);
                } else {
                    $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row_event['eventid'], 'on');
                }
            }
            //			$description = expand_trigger_description($row['triggerid']);
            $description = expand_trigger_description_by_data(array_merge($row, array('clock' => $row_event['clock'])), ZBX_FLAG_EVENT);
            //actions
            $actions = get_event_actions_stat_hints($row_event['eventid']);
            $clock = new CLink(zbx_date2str(S_DATE_FORMAT_YMDHMS, $row_event['clock']), 'events.php?triggerid=' . $row['triggerid'] . '&source=0&show_unknown=1&nav_time=' . $row_event['clock'], 'action');
            if ($row_event['url']) {
                $description = new CLink($description, $row_event['url'], 'action', null, true);
            } else {
                $description = new CSpan($description, 'pointer');
            }
            $description = new CCol($description, get_severity_style($row["priority"]));
            $description->setHint(make_popup_eventlist($row_event['eventid'], $row['type']));
            $table->addRow(array(get_node_name_by_elid($row['triggerid']), $host, $description, $clock, zbx_date2age($row_event['clock']), $ack, $actions));
        }
        unset($row, $description, $actions, $alerts, $hint);
    }
    $table->setFooter(new CCol(S_UPDATED . ': ' . date("H:i:s", time())));
    return $table;
}
Example #2
0
        break;
    case EVENTS_OPTION_NOFALSEFORB:
        $event_cond .= ' AND e.acknowledged=0 ' . ' AND ((e.value=' . TRIGGER_VALUE_TRUE . ') OR ((e.value=' . TRIGGER_VALUE_FALSE . ') AND t.type=' . TRIGGER_MULT_EVENT_DISABLED . '))';
        break;
    case EVENTS_OPTION_NOEVENT:
    default:
        $event_cond .= ' AND 1=2 ';
        break;
}
$triggers = array();
$triggerids = array();
$sql = 'SELECT DISTINCT t.triggerid,t.status,t.description, t.expression,t.priority, ' . ' t.lastchange,t.comments,t.url,t.value,h.host,h.hostid,t.type ' . ' FROM triggers t,hosts h,items i,functions f ' . ' WHERE ' . DBcondition('t.triggerid', $available_triggers) . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND f.triggerid=t.triggerid ' . ' AND i.itemid=f.itemid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND h.hostid=i.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . $cond . order_by('h.host,h.hostid,t.description,t.priority,t.lastchange');
$result = DBselect($sql);
while ($row = DBfetch($result)) {
    // Check for dependencies
    if (trigger_dependent($row['triggerid'])) {
        continue;
    }
    if ($show_triggers == TRIGGERS_OPTION_NOFALSEFORB) {
        $event_sql = 'SELECT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged, t.type ' . ' FROM events e, triggers t ' . ' WHERE e.object=0 ' . ' AND e.objectid=' . $row['triggerid'] . ' AND t.triggerid=e.objectid ' . $event_cond . ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC';
        if (!($row = get_row_for_nofalseforb($row, $event_sql))) {
            continue;
        }
    }
    $triggers_num++;
    $row['events'] = array();
    $row['items'] = array();
    $triggers[$row['triggerid']] = $row;
    $triggerids[$row['triggerid']] = $row['triggerid'];
}
$sql = 'SELECT f.triggerid, i.* ' . ' FROM functions f, items i ' . ' WHERE ' . DBcondition('f.triggerid', $triggerids) . ' AND i.itemid=f.itemid';
Example #3
0
function get_triggers_overview($hostids, $view_style = null)
{
    $available_triggers = get_accessible_triggers(PERM_READ_ONLY, $hostids);
    if (is_null($view_style)) {
        $view_style = get_profile('web.overview.view.style', STYLE_TOP);
    }
    $table = new CTableInfo(S_NO_TRIGGERS_DEFINED);
    $result = DBselect('SELECT DISTINCT t.triggerid,t.description,t.expression,t.value,t.priority,t.lastchange,h.hostid,h.host' . ' FROM hosts h,items i,triggers t, functions f ' . ' WHERE h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid ' . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid' . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' ORDER BY t.description');
    unset($triggers);
    unset($hosts);
    $triggers = array();
    while ($row = DBfetch($result)) {
        if (trigger_dependent($row['triggerid'])) {
            continue;
        }
        $row['host'] = get_node_name_by_elid($row['hostid']) . $row['host'];
        $row['description'] = expand_trigger_description_constants($row['description'], $row);
        $hosts[strtolower($row['host'])] = $row['host'];
        // A little tricky check for attempt to overwrite active trigger (value=1) with
        // inactive or active trigger with lower priority.
        if (!isset($triggers[$row['description']][$row['host']]) || ($triggers[$row['description']][$row['host']]['value'] == TRIGGER_VALUE_FALSE && $row['value'] == TRIGGER_VALUE_TRUE || ($triggers[$row['description']][$row['host']]['value'] == TRIGGER_VALUE_FALSE || $row['value'] == TRIGGER_VALUE_TRUE) && $row['priority'] > $triggers[$row['description']][$row['host']]['priority'])) {
            $triggers[$row['description']][$row['host']] = array('hostid' => $row['hostid'], 'triggerid' => $row['triggerid'], 'value' => $row['value'], 'lastchange' => $row['lastchange'], 'priority' => $row['priority']);
        }
    }
    if (!isset($hosts)) {
        return $table;
    }
    ksort($hosts);
    if ($view_style == STYLE_TOP) {
        $header = array(new CCol(S_TRIGGERS, 'center'));
        foreach ($hosts as $hostname) {
            $header = array_merge($header, array(new CImg('vtext.php?text=' . $hostname)));
        }
        $table->setHeader($header, 'vertical_header');
        foreach ($triggers as $descr => $trhosts) {
            $table_row = array(nbsp($descr));
            foreach ($hosts as $hostname) {
                $table_row = get_trigger_overview_cells($table_row, $trhosts, $hostname);
            }
            $table->AddRow($table_row);
        }
    } else {
        $header = array(new CCol(S_HOSTS, 'center'));
        foreach ($triggers as $descr => $trhosts) {
            $descr = array(new CImg('vtext.php?text=' . $descr));
            array_push($header, $descr);
        }
        $table->SetHeader($header, 'vertical_header');
        foreach ($hosts as $hostname) {
            $table_row = array(nbsp($hostname));
            foreach ($triggers as $descr => $trhosts) {
                $table_row = get_trigger_overview_cells($table_row, $trhosts, $hostname);
            }
            $table->AddRow($table_row);
        }
    }
    return $table;
}
Example #4
0
 public function bodyToString()
 {
     $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array(), PERM_RES_IDS_ARRAY, get_current_nodeid(true));
     foreach ($available_triggers as $id => $triggerid) {
         if (trigger_dependent($triggerid)) {
             unset($available_triggers[$id]);
         }
     }
     $this->cleanItems();
     $ok = $uncn = $info = $warn = $avg = $high = $dis = 0;
     $sql_from = '';
     $sql_where = '';
     if ($this->groupid > 0) {
         $sql_from = ', hosts_groups hg ';
         $sql_where = ' AND hg.groupid=' . $this->groupid . ' AND h.hostid=hg.hostid ';
     }
     $db_priority = DBselect('SELECT t.priority,t.value,count(DISTINCT t.triggerid) as cnt ' . ' FROM triggers t,hosts h,items i,functions f ' . $sql_from . ' WHERE t.status=' . TRIGGER_STATUS_ENABLED . ' AND f.itemid=i.itemid ' . ' AND h.hostid=i.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND t.triggerid=f.triggerid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('t.triggerid', $available_triggers) . $sql_where . ' GROUP BY t.priority,t.value');
     while ($row = DBfetch($db_priority)) {
         switch ($row["value"]) {
             case TRIGGER_VALUE_TRUE:
                 switch ($row["priority"]) {
                     case TRIGGER_SEVERITY_INFORMATION:
                         $info += $row["cnt"];
                         break;
                     case TRIGGER_SEVERITY_WARNING:
                         $warn += $row["cnt"];
                         break;
                     case TRIGGER_SEVERITY_AVERAGE:
                         $avg += $row["cnt"];
                         break;
                     case TRIGGER_SEVERITY_HIGH:
                         $high += $row["cnt"];
                         break;
                     case TRIGGER_SEVERITY_DISASTER:
                         $dis += $row["cnt"];
                         break;
                     default:
                         $uncn += $row["cnt"];
                         break;
                 }
                 break;
             case TRIGGER_VALUE_FALSE:
                 $ok += $row["cnt"];
                 break;
             default:
                 $uncn += $row["cnt"];
                 break;
         }
     }
     if ($this->show_header) {
         $header = new CCol(S_TRIGGERS_INFO, "header");
         if ($this->style == STYLE_HORISONTAL) {
             $header->SetColspan(7);
         }
         $this->addRow($header);
     }
     $trok = new CCol($ok . SPACE . S_OK, get_severity_style('ok', false));
     $uncn = new CCol($uncn . SPACE . S_NOT_CLASSIFIED, get_severity_style(TRIGGER_SEVERITY_NOT_CLASSIFIED, $uncn));
     $info = new CCol($info . SPACE . S_INFORMATION, get_severity_style(TRIGGER_SEVERITY_INFORMATION, $info));
     $warn = new CCol($warn . SPACE . S_WARNING, get_severity_style(TRIGGER_SEVERITY_WARNING, $warn));
     $avg = new CCol($avg . SPACE . S_AVERAGE, get_severity_style(TRIGGER_SEVERITY_AVERAGE, $avg));
     $high = new CCol($high . SPACE . S_HIGH, get_severity_style(TRIGGER_SEVERITY_HIGH, $high));
     $dis = new CCol($dis . SPACE . S_DISASTER, get_severity_style(TRIGGER_SEVERITY_DISASTER, $dis));
     if (STYLE_HORISONTAL == $this->style) {
         $this->addRow(array($trok, $uncn, $info, $warn, $avg, $high, $dis));
     } else {
         $this->addRow($trok);
         $this->addRow($uncn);
         $this->addRow($info);
         $this->addRow($warn);
         $this->addRow($avg);
         $this->addRow($high);
         $this->addRow($dis);
     }
     return parent::BodyToString();
 }