コード例 #1
0
ファイル: blocks.inc.php プロジェクト: phedders/zabbix
function make_system_summary($args = array())
{
    global $USER_DETAILS;
    $config = select_config();
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
    $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
    $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array(), PERM_RES_IDS_ARRAY);
    if (isset($args['hosts']) && !empty($args['hosts'])) {
        $available_hosts = zbx_uint_array_intersect($args['hosts'], $available_hosts);
    }
    if (isset($args['groups']) && !empty($args['groups'])) {
        $available_groups = zbx_uint_array_intersect($args['groups'], $available_groups);
    }
    $sql_where = '';
    if (isset($args['severity']) && ctype_digit($args['severity'])) {
        $sql_where = ' AND t.priority>=' . $args['severity'];
    }
    $table = new CTableInfo();
    $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST_GROUP, S_DISASTER, S_HIGH, S_AVERAGE, S_WARNING, S_INFORMATION, S_NOT_CLASSIFIED));
    $sql = 'SELECT DISTINCT g.groupid,g.name ' . ' FROM groups g, hosts_groups hg, hosts h, items i, functions f, triggers t ' . ' WHERE ' . DBcondition('h.hostid', $available_hosts) . ' AND ' . DBcondition('g.groupid', $available_groups) . ' AND hg.groupid=g.groupid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid ' . ' AND hg.hostid=h.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' ORDER BY g.name';
    $gr_result = DBselect($sql);
    while ($group = DBFetch($gr_result)) {
        $group_row = new CRow();
        if (is_show_all_nodes()) {
            $group_row->addItem(get_node_name_by_elid($group['groupid']));
        }
        $name = new CLink($group['name'], 'tr_status.php?groupid=' . $group['groupid'] . '&show_triggers=' . TRIGGERS_OPTION_ONLYTRUE);
        $name->setTarget('blank');
        $group_row->addItem($name);
        $tab_priority[TRIGGER_SEVERITY_DISASTER] = 0;
        $tab_priority[TRIGGER_SEVERITY_HIGH] = 0;
        $tab_priority[TRIGGER_SEVERITY_AVERAGE] = 0;
        $tab_priority[TRIGGER_SEVERITY_WARNING] = 0;
        $tab_priority[TRIGGER_SEVERITY_INFORMATION] = 0;
        $tab_priority[TRIGGER_SEVERITY_NOT_CLASSIFIED] = 0;
        $sql = 'SELECT count(DISTINCT t.triggerid) as tr_cnt,t.priority ' . ' FROM hosts h,items i,hosts_groups hg, functions f, triggers t ' . ' WHERE h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid ' . ' AND hg.groupid=' . $group['groupid'] . ' AND hg.hostid=h.hostid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.value=' . TRIGGER_VALUE_TRUE . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' GROUP BY t.priority';
        //SDI($sql);
        $tr_result = DBSelect($sql);
        while ($group_stat = DBFetch($tr_result)) {
            $tab_priority[$group_stat['priority']] = $group_stat['tr_cnt'];
        }
        foreach ($tab_priority as $key => $value) {
            $tr_count = 0;
            if ($value) {
                //* trigger list
                $table_inf = new CTableInfo();
                $table_inf->setAttribute('style', 'width: 400px;');
                $table_inf->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST, S_ISSUE, 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 ' . ' FROM triggers t,hosts h,items i,functions f, hosts_groups hg ' . ' WHERE f.itemid=i.itemid ' . ' AND hg.groupid=' . $group['groupid'] . ' 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 . ' AND t.priority=' . $key . ' ORDER BY t.lastchange DESC';
                $result = DBselect($sql);
                while ($row_inf = DBfetch($result)) {
                    // Check for dependencies
                    if (trigger_dependent($row_inf["triggerid"])) {
                        continue;
                    }
                    $tr_count++;
                    if ($tr_count > 30) {
                        continue;
                    }
                    $host = new CSpan($row_inf['host']);
                    $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=' . EVENT_SOURCE_TRIGGERS . ' AND e.objectid=' . $row_inf['triggerid'] . ' AND t.triggerid=e.objectid ' . ' AND e.value=' . TRIGGER_VALUE_TRUE . ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC';
                    if ($row_inf_event = DBfetch(DBselect($event_sql, 1))) {
                        if ($config['event_ack_enable']) {
                            if ($row_inf_event['acknowledged'] == 1) {
                                $ack = new CLink(S_YES, 'acknow.php?eventid=' . $row_inf_event['eventid'], 'action');
                            } else {
                                $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row_inf_event['eventid'], 'on');
                            }
                        }
                        $description = expand_trigger_description_by_data(array_merge($row_inf, array('clock' => $row_inf_event['clock'])), ZBX_FLAG_EVENT);
                        //actions
                        $actions = get_event_actions_status($row_inf_event['eventid']);
                        //--------
                    } else {
                        $description = expand_trigger_description_by_data($row_inf, ZBX_FLAG_EVENT);
                        $ack = '-';
                        $actions = S_NO_DATA_SMALL;
                        $row_inf_event['clock'] = $row_inf['clock'];
                    }
                    $table_inf->addRow(array(get_node_name_by_elid($row_inf['triggerid']), $host, new CCol($description, get_severity_style($row_inf['priority'])), zbx_date2age($row_inf_event['clock']), $config['event_ack_enable'] ? new CCol($ack, 'center') : NULL, $actions));
                    unset($row_inf, $description, $actions);
                }
                $value = new CSpan($tr_count, 'pointer');
                $value->setHint($table_inf);
                //-------------*/
            }
            $group_row->AddItem(new CCol($value, get_severity_style($key, $tr_count)));
            unset($table_inf);
        }
        $table->addRow($group_row);
    }
    $table->setFooter(new CCol(S_UPDATED . ': ' . date("H:i:s", time())));
    return $table;
}
コード例 #2
0
ファイル: scripts.inc.php プロジェクト: rennhak/zabbix
function get_accessible_scripts_by_hosts($hosts)
{
    global $USER_DETAILS;
    if (!is_array($hosts)) {
        $hosts = array('0' => hosts);
    }
    // Selecting usrgroups by user
    $sql = 'SELECT ug.usrgrpid ' . ' FROM users_groups ug ' . ' WHERE ug.userid=' . $USER_DETAILS['userid'];
    $user_groups = DBfetch(DBselect($sql));
    $user_groups[] = 0;
    // to ALL user groups
    // --
    // Selecting groups by Hosts
    $sql = 'SELECT hg.hostid,hg.groupid ' . ' FROM hosts_groups hg ' . ' WHERE ' . DBcondition('hg.hostid', $hosts);
    $hg_res = DBselect($sql);
    while ($hg_rows = DBfetch($hg_res)) {
        $hosts_groups[$hg_rows['groupid']][$hg_rows['hostid']] = $hg_rows['hostid'];
        $hg_groups[$hg_rows['groupid']] = $hg_rows['groupid'];
    }
    $hg_groups[] = 0;
    // to ALL host groups
    // --
    $hosts_read_only = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY);
    $hosts_read_write = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE);
    $hosts_read_only = zbx_uint_array_intersect($hosts, $hosts_read_only);
    $hosts_read_write = zbx_uint_array_intersect($hosts, $hosts_read_write);
    $scripts_by_host = array();
    // initialize array
    foreach ($hosts as $id => $hostid) {
        $scripts_by_host[$hostid] = array();
    }
    //-----
    $sql = 'SELECT s.* ' . ' FROM scripts s ' . ' WHERE ' . DBin_node('s.scriptid') . ' AND ' . DBcondition('s.groupid', $hg_groups) . ' AND ' . DBcondition('s.usrgrpid', $user_groups) . ' ORDER BY scriptid ASC';
    $res = DBselect($sql);
    while ($script = DBfetch($res)) {
        $add_to_hosts = array();
        if (PERM_READ_WRITE == $script['host_access']) {
            if ($script['groupid'] > 0) {
                $add_to_hosts = zbx_uint_array_intersect($hosts_read_write, $hosts_groups[$script['groupid']]);
            } else {
                $add_to_hosts = $hosts_read_write;
            }
        } else {
            if (PERM_READ_ONLY == $script['host_access']) {
                if ($script['groupid'] > 0) {
                    $add_to_hosts = zbx_uint_array_intersect($hosts_read_only, $hosts_groups[$script['groupid']]);
                } else {
                    $add_to_hosts = $hosts_read_only;
                }
            }
        }
        foreach ($add_to_hosts as $id => $hostid) {
            $scripts_by_host[$hostid][] = $script;
        }
    }
    //SDI($scripts_by_host);
    return $scripts_by_host;
}
コード例 #3
0
ファイル: graphs.php プロジェクト: rennhak/zabbix
     $graph = get_graph_by_graphid($_REQUEST['graphid']);
     if (!isset($available_graphs[$_REQUEST['graphid']])) {
         access_deny();
     }
     DBstart();
     $result = delete_graph($_REQUEST['graphid']);
     $result = DBend($result);
     if ($result) {
         add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_GRAPH, 'Graph [' . $graph['name'] . ']');
         unset($_REQUEST['form']);
     }
     show_messages($result, S_GRAPH_DELETED, S_CANNOT_DELETE_GRAPH);
 } else {
     if (isset($_REQUEST['delete']) && isset($_REQUEST['group_graphid'])) {
         $group_graphid = $_REQUEST['group_graphid'];
         $group_graphid = zbx_uint_array_intersect($group_graphid, $available_graphs);
         $result = false;
         DBstart();
         foreach ($group_graphid as $id => $graphid) {
             $graph = get_graph_by_graphid($graphid);
             if ($graph['templateid'] != 0) {
                 continue;
             }
             add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_GRAPH, 'Graph [' . $graph['name'] . ']');
         }
         if (!empty($group_graphid)) {
             $result = delete_graph($group_graphid);
         }
         $result = DBend($result);
         show_messages($result, S_GRAPHS_DELETED, S_CANNOT_DELETE_GRAPHS);
     } else {
コード例 #4
0
ファイル: triggers.php プロジェクト: phedders/zabbix
}
//----
$showdisabled = get_request('showdisabled', 0);
update_profile('web.triggers.showdisabled', $showdisabled, PROFILE_TYPE_INT);
/* FORM ACTIONS */
if (isset($_REQUEST['clone']) && isset($_REQUEST['triggerid'])) {
    unset($_REQUEST['triggerid']);
    $_REQUEST['form'] = 'clone';
} else {
    if (isset($_REQUEST['mass_save']) && isset($_REQUEST['g_triggerid'])) {
        show_messages();
        $result = false;
        $visible = get_request('visible', array());
        $_REQUEST['dependencies'] = get_request('dependencies', array());
        $triggers = $_REQUEST['g_triggerid'];
        $triggers = zbx_uint_array_intersect($triggers, $available_triggers);
        DBstart();
        foreach ($triggers as $id => $triggerid) {
            $db_trig = get_trigger_by_triggerid($triggerid);
            $db_trig['dependencies'] = get_trigger_dependencies_by_triggerid($triggerid);
            foreach ($db_trig as $key => $value) {
                if (isset($visible[$key])) {
                    $db_trig[$key] = $_REQUEST[$key];
                }
            }
            $result2 = update_trigger($db_trig['triggerid'], null, null, null, $db_trig['priority'], null, null, null, $db_trig['dependencies'], null);
            $result |= $result2;
        }
        $result = DBend($result);
        show_messages($result, S_TRIGGER_UPDATED, S_CANNOT_UPDATE_TRIGGER);
        if ($result) {
コード例 #5
0
 public static function getScriptsByHosts($hostids)
 {
     zbx_value2array($hostids);
     $obj_params = array('hostids' => $hostids, 'preservekeys' => 1);
     $hosts_read_only = CHost::get($obj_params);
     $hosts_read_only = zbx_objectValues($hosts_read_only, 'hostid');
     $obj_params = array('editable' => 1, 'hostids' => $hostids, 'preservekeys' => 1);
     $hosts_read_write = CHost::get($obj_params);
     $hosts_read_write = zbx_objectValues($hosts_read_write, 'hostid');
     // initialize array
     $scripts_by_host = array();
     foreach ($hostids as $id => $hostid) {
         $scripts_by_host[$hostid] = array();
     }
     //-----
     $options = array('hostids' => $hostids, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1);
     $groups = CHostGroup::get($options);
     $obj_params = array('groupids' => zbx_objectValues($groups, 'groupid'), 'sortfield' => 'name', 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1);
     $scripts = CScript::get($obj_params);
     foreach ($scripts as $num => $script) {
         $add_to_hosts = array();
         $hostids = zbx_objectValues($groups[$script['groupid']]['hosts'], 'hostid');
         if (PERM_READ_WRITE == $script['host_access']) {
             if ($script['groupid'] > 0) {
                 $add_to_hosts = zbx_uint_array_intersect($hosts_read_write, $hostids);
             } else {
                 $add_to_hosts = $hosts_read_write;
             }
         } else {
             if (PERM_READ_ONLY == $script['host_access']) {
                 if ($script['groupid'] > 0) {
                     $add_to_hosts = zbx_uint_array_intersect($hosts_read_only, $hostids);
                 } else {
                     $add_to_hosts = $hosts_read_only;
                 }
             }
         }
         foreach ($add_to_hosts as $id => $hostid) {
             $scripts_by_host[$hostid][] = $script;
         }
     }
     //SDII(count($scripts_by_host));
     return $scripts_by_host;
 }