示例#1
0
function execute_script($scriptid, $hostid)
{
    $res = 1;
    $command = script_make_command($scriptid, $hostid);
    $nodeid = id2nodeid($hostid);
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if (!$socket) {
        $res = 0;
    }
    if ($res) {
        global $ZBX_SERVER, $ZBX_SERVER_PORT;
        $res = socket_connect($socket, $ZBX_SERVER, $ZBX_SERVER_PORT);
    }
    if ($res) {
        $send = "Command­{$nodeid}­{$hostid}­{$command}\n";
        socket_write($socket, $send);
    }
    if ($res) {
        $res = socket_read($socket, 65535);
    }
    if ($res) {
        list($flag, $msg) = split("­", $res);
        $message["flag"] = $flag;
        $message["message"] = $msg;
    } else {
        $message["flag"] = -1;
        $message["message"] = S_CONNECT_TO_SERVER_ERROR . ' [' . $ZBX_SERVER . ':' . $ZBX_SERVER_PORT . '] [' . socket_strerror(socket_last_error()) . ']';
    }
    if ($socket) {
        socket_close($socket);
    }
    return $message;
}
 public function __construct($groupid = 0, $style = STYLE_HORISONTAL)
 {
     $this->nodeid = id2nodeid($groupid);
     $this->groupid = $groupid;
     $this->style = null;
     parent::__construct(null, 'hosts_info');
     $this->setOrientation($style);
 }
示例#3
0
 public function __construct($groupid = 0, $style = STYLE_HORISONTAL)
 {
     $this->nodeid = id2nodeid($groupid);
     $this->groupid = $groupid;
     $this->style = null;
     parent::CTable(NULL, "hosts_info");
     $this->SetOrientation($style);
 }
示例#4
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;
}
示例#5
0
$dbGraph = API::Graph()->get(array('graphids' => $_REQUEST['graphid'], 'output' => API_OUTPUT_EXTEND, 'expandName' => 1));
//    _ex($dbGraph,0);
if (!$dbGraph) {
    access_deny();
} else {
    $dbGraph = reset($dbGraph);
}
$host = API::Host()->get(array('nodeids' => get_current_nodeid(true), 'graphids' => $_REQUEST['graphid'], 'output' => API_OUTPUT_EXTEND, 'templated_hosts' => true));
$host = reset($host);
/*
 * Display
 */
$timeline = CScreenBase::calculateTime(array('profileIdx' => get_request('profileIdx', 'web.screens'), 'profileIdx2' => get_request('profileIdx2'), 'updateProfile' => get_request('updateProfile', true), 'period' => get_request('period'), 'stime' => get_request('stime')));
CProfile::update('web.screens.graphid', $_REQUEST['graphid'], PROFILE_TYPE_ID);
$chartHeader = '';
if (id2nodeid($dbGraph['graphid']) != get_current_nodeid()) {
    $chartHeader = get_node_name_by_elid($dbGraph['graphid'], true, NAME_DELIMITER);
}
$chartHeader .= $host['name'] . NAME_DELIMITER . $dbGraph['name'];
$graph = new CLineGraphDraw_Zabbix($dbGraph['graphtype']);
$graph->setHeader($chartHeader);
$graph->setPeriod($timeline['period']);
$graph->setSTime($timeline['stime']);
if (isset($_REQUEST['border'])) {
    $graph->setBorder(0);
}
$width = get_request('width', 0);
if ($width <= 0) {
    $width = $dbGraph['width'];
}
$height = get_request('height', 0);
示例#6
0
文件: db.inc.php 项目: rennhak/zabbix
function in_node($id_var, $nodes = null)
{
    if (is_null($nodes)) {
        $nodes = get_current_nodeid();
    }
    if (empty($nodes)) {
        $nodes = 0;
    }
    if (zbx_numeric($nodes)) {
        $nodes = array($nodes);
    } else {
        if (is_string($nodes)) {
            if (!eregi('([0-9\\,]+)', $nodes)) {
                fatal_error('Incorrect "nodes" for "in_node". Passed [' . $nodes . ']');
            }
            $nodes = explode(',', $nodes);
        } else {
            if (!is_array($nodes)) {
                fatal_error('Incorrect type of "nodes" for "in_node". Passed [' . gettype($nodes) . ']');
            }
        }
    }
    return uint_in_array(id2nodeid($id_var), $nodes);
}
示例#7
0
function condition_value2str($conditiontype, $value)
{
    switch ($conditiontype) {
        case CONDITION_TYPE_HOST_GROUP:
            $group = get_hostgroup_by_groupid($value);
            $str_val = '';
            if (id2nodeid($value) != get_current_nodeid()) {
                $str_val = get_node_name_by_elid($value, true);
            }
            $str_val .= $group['name'];
            break;
        case CONDITION_TYPE_TRIGGER:
            $str_val = expand_trigger_description($value);
            break;
        case CONDITION_TYPE_HOST:
        case CONDITION_TYPE_HOST_TEMPLATE:
            $host = get_host_by_hostid($value);
            $str_val = '';
            if (id2nodeid($value) != get_current_nodeid()) {
                $str_val = get_node_name_by_elid($value, true);
            }
            $str_val .= $host['host'];
            break;
        case CONDITION_TYPE_TRIGGER_NAME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_TRIGGER_VALUE:
            $str_val = trigger_value2str($value);
            break;
        case CONDITION_TYPE_TRIGGER_SEVERITY:
            $str_val = get_severity_description($value);
            break;
        case CONDITION_TYPE_TIME_PERIOD:
            $str_val = $value;
            break;
        case CONDITION_TYPE_MAINTENANCE:
            $str_val = S_MAINTENANCE_SMALL;
            break;
        case CONDITION_TYPE_DHOST_IP:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSERVICE_TYPE:
            $str_val = discovery_check_type2str($value);
            break;
        case CONDITION_TYPE_DSERVICE_PORT:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSTATUS:
            $str_val = discovery_object_status2str($value);
            break;
        case CONDITION_TYPE_DUPTIME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DVALUE:
            $str_val = $value;
            break;
        case CONDITION_TYPE_EVENT_ACKNOWLEDGED:
            $str_val = $value ? S_ACK : S_NOT_ACK;
            break;
        case CONDITION_TYPE_APPLICATION:
            $str_val = $value;
            break;
        default:
            return S_UNKNOWN;
            break;
    }
    return '"' . $str_val . '"';
}
示例#8
0
function condition_value2str($conditiontype, $value)
{
    switch ($conditiontype) {
        case CONDITION_TYPE_HOST_GROUP:
            $groups = API::HostGroup()->get(array('groupids' => $value, 'output' => array('name'), 'nodeids' => get_current_nodeid(true), 'limit' => 1));
            if ($groups) {
                $group = reset($groups);
                $str_val = '';
                if (id2nodeid($value) != get_current_nodeid()) {
                    $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER);
                }
                $str_val .= $group['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_TRIGGER:
            $trigs = API::Trigger()->get(array('triggerids' => $value, 'expandDescription' => true, 'output' => array('description'), 'selectHosts' => array('name'), 'nodeids' => get_current_nodeid(true), 'limit' => 1));
            if ($trigs) {
                $trig = reset($trigs);
                $host = reset($trig['hosts']);
                $str_val = '';
                if (id2nodeid($value) != get_current_nodeid()) {
                    $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER);
                }
                $str_val .= $host['name'] . NAME_DELIMITER . $trig['description'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_HOST:
        case CONDITION_TYPE_TEMPLATE:
            if ($host = get_host_by_hostid($value)) {
                $str_val = '';
                if (id2nodeid($value) != get_current_nodeid()) {
                    $str_val = get_node_name_by_elid($value, true, NAME_DELIMITER);
                }
                $str_val .= $host['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_TRIGGER_NAME:
        case CONDITION_TYPE_HOST_METADATA:
        case CONDITION_TYPE_HOST_NAME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_TRIGGER_VALUE:
            $str_val = trigger_value2str($value);
            break;
        case CONDITION_TYPE_TRIGGER_SEVERITY:
            $str_val = getSeverityCaption($value);
            break;
        case CONDITION_TYPE_TIME_PERIOD:
            $str_val = $value;
            break;
        case CONDITION_TYPE_MAINTENANCE:
            $str_val = _('maintenance');
            break;
        case CONDITION_TYPE_NODE:
            if ($node = get_node_by_nodeid($value)) {
                $str_val = $node['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DRULE:
            if ($drule = get_discovery_rule_by_druleid($value)) {
                $str_val = $drule['name'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DCHECK:
            $row = DBfetch(DBselect('SELECT dr.name,c.dcheckid,c.type,c.key_,c.ports' . ' FROM drules dr,dchecks c' . ' WHERE dr.druleid=c.druleid' . ' AND c.dcheckid=' . zbx_dbstr($value)));
            if ($row) {
                $str_val = $row['name'] . NAME_DELIMITER . discovery_check2str($row['type'], $row['key_'], $row['ports']);
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DOBJECT:
            $str_val = discovery_object2str($value);
            break;
        case CONDITION_TYPE_PROXY:
            if ($host = get_host_by_hostid($value)) {
                $str_val = $host['host'];
            } else {
                return _('Unknown');
            }
            break;
        case CONDITION_TYPE_DHOST_IP:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSERVICE_TYPE:
            $str_val = discovery_check_type2str($value);
            break;
        case CONDITION_TYPE_DSERVICE_PORT:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSTATUS:
            $str_val = discovery_object_status2str($value);
            break;
        case CONDITION_TYPE_DUPTIME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DVALUE:
            $str_val = $value;
            break;
        case CONDITION_TYPE_EVENT_ACKNOWLEDGED:
            $str_val = $value ? _('Ack') : _('Not Ack');
            break;
        case CONDITION_TYPE_APPLICATION:
            $str_val = $value;
            break;
        case CONDITION_TYPE_EVENT_TYPE:
            $str_val = eventType($value);
            break;
        default:
            return _('Unknown');
    }
    return $str_val;
}
示例#9
0
 $params = array('nodeids' => get_current_nodeid(true), 'templateids' => $templateids, 'editable' => 1);
 $rw_templates = CTemplate::get($params);
 $rw_templates = zbx_toHash($rw_templates, 'templateid');
 $params = array('nodeids' => get_current_nodeid(true), 'search' => array('host' => $search), 'countOutput' => 1, 'editable' => 1);
 $overalCount = CTemplate::get($params);
 $viewCount = count($templates);
 $header = array(ZBX_DISTRIBUTED ? new CCol(S_NODE) : null, new CCol(S_TEMPLATES), new CCol(S_APPLICATIONS), new CCol(S_ITEMS), new CCol(S_TRIGGERS), new CCol(S_GRAPHS));
 $table = new CTableInfo();
 $table->setHeader($header);
 foreach ($templates as $tnum => $template) {
     $templateid = $template['hostid'];
     $group = reset($template['groups']);
     $link = 'groupid=' . $group['groupid'] . '&hostid=' . $templateid . '&switch_node=' . id2nodeid($templateid);
     $caption = make_decoration($template['host'], $search);
     if (isset($rw_templates[$templateid])) {
         $template_link = new CLink($caption, 'templates.php?form=update&' . '&templateid=' . $templateid . '&switch_node=' . id2nodeid($templateid));
         $applications_link = array(new CLink(S_APPLICATIONS, 'applications.php?' . $link), ' (' . $template['applications'] . ')');
         $items_link = array(new CLink(S_ITEMS, 'items.php?' . $link), ' (' . $template['items'] . ')');
         $triggers_link = array(new CLink(S_TRIGGERS, 'triggers.php?' . $link), ' (' . $template['triggers'] . ')');
         $graphs_link = array(new CLink(S_GRAPHS, 'graphs.php?' . $link), ' (' . $template['graphs'] . ')');
     } else {
         $template_link = new CSpan($caption);
         $applications_link = array(new CSpan(S_APPLICATIONS, 'unknown'), ' (' . $template['applications'] . ')');
         $items_link = array(new CSpan(S_ITEMS, 'unknown'), ' (' . $template['items'] . ')');
         $triggers_link = array(new CSpan(S_TRIGGERS, 'unknown'), ' (' . $template['triggers'] . ')');
         $graphs_link = array(new CSpan(S_GRAPHS, 'unknown'), ' (' . $template['graphs'] . ')');
     }
     $table->addRow(array(get_node_name_by_elid($templateid, true), $template_link, $applications_link, $items_link, $triggers_link, $graphs_link));
 }
 $table->setFooter(new CCol(S_DISPLAYING . SPACE . $viewCount . SPACE . S_OF_SMALL . SPACE . $overalCount . SPACE . S_FOUND_SMALL));
 $wdgt_templates = new CWidget('search_templates', $table);
示例#10
0
function get_node_name_by_elid($objectId, $forceWithAllNodes = null, $delimiter = '')
{
    global $ZBX_NODES, $ZBX_VIEWED_NODES;
    if ($forceWithAllNodes === false || is_null($forceWithAllNodes) && $ZBX_VIEWED_NODES['selected'] != 0) {
        return null;
    }
    $nodeId = id2nodeid($objectId);
    if (!isset($ZBX_NODES[$nodeId])) {
        return null;
    }
    return $ZBX_NODES[$nodeId]['name'] . $delimiter;
}
示例#11
0
function in_node($id_var, $nodes = null)
{
    if (is_null($nodes)) {
        $nodes = get_current_nodeid();
    }
    if (empty($nodes)) {
        $nodes = 0;
    }
    if (zbx_ctype_digit($nodes)) {
        $nodes = array($nodes);
    } elseif (is_string($nodes)) {
        if (!preg_match('/^([0-9,]+)$/', $nodes)) {
            fatal_error('Incorrect "nodes" for "in_node". Passed [' . $nodes . ']');
        }
        $nodes = explode(',', $nodes);
    } elseif (!is_array($nodes)) {
        fatal_error('Incorrect type of "nodes" for "in_node". Passed [' . gettype($nodes) . ']');
    }
    return uint_in_array(id2nodeid($id_var), $nodes);
}
示例#12
0
function make_latest_issues($filter = array())
{
    global $page;
    $config = select_config();
    $limit = isset($filter['limit']) ? $filter['limit'] : 20;
    $options = array('groupids' => $filter['groupids'], 'monitored' => 1, 'maintenance' => $filter['maintenance'], 'skipDependent' => 1, 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE), 'select_groups' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND, 'sortfield' => 'lastchange', 'sortorder' => ZBX_SORT_DOWN, 'limit' => $limit);
    if (isset($filter['hostids'])) {
        $options['hostids'] = $filter['hostids'];
    }
    $triggers = CTrigger::get($options);
    // GATHER HOSTS FOR SELECTED TRIGGERS {{{
    $triggers_hosts = array();
    foreach ($triggers as $tnum => $trigger) {
        // if trigger is lost(broken expression) we skip it
        if (empty($trigger['hosts'])) {
            unset($triggers[$tnum]);
            continue;
        }
        $triggers_hosts = array_merge($triggers_hosts, $trigger['hosts']);
    }
    $triggers_hosts = zbx_toHash($triggers_hosts, 'hostid');
    $triggers_hostids = array_keys($triggers_hosts);
    // }}} GATHER HOSTS FOR SELECTED TRIGGERS
    $scripts_by_hosts = CScript::getScriptsByHosts($triggers_hostids);
    $table = new CTableInfo();
    $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST, S_ISSUE, S_LAST_CHANGE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS));
    $thosts_cache = array();
    foreach ($triggers as $tnum => $trigger) {
        // Check for dependencies
        $group = reset($trigger['groups']);
        $host = reset($trigger['hosts']);
        $trigger['hostid'] = $host['hostid'];
        $trigger['host'] = $host['host'];
        $host = null;
        $menus = '';
        $host_nodeid = id2nodeid($trigger['hostid']);
        foreach ($scripts_by_hosts[$trigger['hostid']] as $id => $script) {
            $script_nodeid = id2nodeid($script['scriptid']);
            if (bccomp($host_nodeid, $script_nodeid) == 0) {
                $menus .= "[" . zbx_jsvalue($script['name']) . ",\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $trigger['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']}],";
            }
        }
        if (!empty($scripts_by_hosts)) {
            $menus = "['" . S_TOOLS . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus;
        }
        if (isset($thosts_cache[$trigger['hostid']])) {
            $hprofile = $thosts_cache[$trigger['hostid']];
        } else {
            $hprofile = CHost::get(array('hostids' => $trigger['hostid'], 'output' => API_OUTPUT_SHORTEN, 'select_profile' => API_OUTPUT_EXTEND));
            $hprofile = reset($hprofile);
            $thosts_cache[$hprofile['hostid']] = $hprofile;
        }
        $menus .= "['" . S_LINKS . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],";
        $menus .= "['" . S_LATEST_DATA . "',\"javascript: redirect('latest.php?groupid=" . $group['groupid'] . '&hostid=' . $trigger['hostid'] . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
        if (!empty($hprofile['profile'])) {
            $menus .= "['" . S_PROFILE . "',\"javascript: redirect('hostprofiles.php?hostid=" . $trigger['hostid'] . "&prof_type=0')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
        }
        if (!empty($hprofile['profile_ext'])) {
            $menus .= "['" . S_EXTENDED_PROFILE . "',\"javascript: redirect('hostprofiles.php?hostid=" . $trigger['hostid'] . "&prof_type=1')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
        }
        $menus = rtrim($menus, ',');
        $menus = 'show_popup_menu(event,[' . $menus . '],180);';
        $host = new CSpan($trigger['host'], 'link_menu pointer');
        $host->setAttribute('onclick', 'javascript: ' . $menus);
        //$host = new CSpan($trigger['host'],'link_menu pointer');
        //$host->setAttribute('onclick','javascript: '.$menus);
        // Maintenance {{{
        $trigger_host = $triggers_hosts[$trigger['hostid']];
        $text = null;
        $style = 'link_menu';
        if ($trigger_host['maintenance_status']) {
            $style .= ' orange';
            $options = array('maintenanceids' => $trigger_host['maintenanceid'], 'output' => API_OUTPUT_EXTEND);
            $maintenances = CMaintenance::get($options);
            $maintenance = reset($maintenances);
            $text = $maintenance['name'];
            $text .= ' [' . ($trigger_host['maintenance_type'] ? S_NO_DATA_MAINTENANCE : S_NORMAL_MAINTENANCE) . ']';
        }
        $host = new CSpan($trigger['host'], $style . ' pointer');
        $host->setAttribute('onclick', 'javascript: ' . $menus);
        if (!is_null($text)) {
            $host->setHint($text, '', '', false);
        }
        // }}} Maintenance
        $event_sql = 'SELECT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged' . ' FROM events e' . ' WHERE e.object=' . EVENT_OBJECT_TRIGGER . ' AND e.objectid=' . $trigger['triggerid'] . ' 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'] . '&backurl=' . $page['file'], 'off');
                    $ack->setHint($ack_info, '', '', false);
                } else {
                    $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row_event['eventid'] . '&backurl=' . $page['file'], 'on');
                }
            }
            //			$description = expand_trigger_description($row['triggerid']);
            $description = expand_trigger_description_by_data(zbx_array_merge($trigger, array('clock' => $row_event['clock'])), ZBX_FLAG_EVENT);
            //actions
            $actions = get_event_actions_stat_hints($row_event['eventid']);
            $clock = new CLink(zbx_date2str(S_BLOCKS_LATEST_ISSUES_DATE_FORMAT, $row_event['clock']), 'events.php?triggerid=' . $trigger['triggerid'] . '&source=0&show_unknown=1&nav_time=' . $row_event['clock']);
            if ($trigger['url']) {
                $description = new CLink($description, $trigger['url'], null, null, true);
            } else {
                $description = new CSpan($description, 'pointer');
            }
            $description = new CCol($description, get_severity_style($trigger['priority']));
            $description->setHint(make_popup_eventlist($row_event['eventid'], $trigger['type'], $trigger['triggerid']), '', '', false);
            $table->addRow(array(get_node_name_by_elid($trigger['triggerid']), $host, $description, $clock, zbx_date2age($row_event['clock']), $ack, $actions));
        }
        unset($trigger, $description, $actions);
    }
    $table->setFooter(new CCol(S_UPDATED . ': ' . zbx_date2str(S_BLOCKS_LATEST_ISSUES_TIME_FORMAT)));
    return $table;
}
示例#13
0
 protected function checkInput(&$users, $method)
 {
     $create = $method === 'create';
     $update = $method === 'update';
     if ($update) {
         $userDBfields = array('userid' => null);
         $dbUsers = $this->get(array('output' => array('userid', 'alias', 'autologin', 'autologout'), 'userids' => zbx_objectValues($users, 'userid'), 'editable' => true, 'preservekeys' => true));
     } else {
         $userDBfields = array('alias' => null, 'passwd' => null, 'usrgrps' => null, 'user_medias' => array());
     }
     $themes = array_keys(Z::getThemes());
     $themes[] = THEME_DEFAULT;
     $themeValidator = new CSetValidator(array('values' => $themes));
     $alias = array();
     foreach ($users as &$user) {
         if (!check_db_fields($userDBfields, $user)) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Wrong fields for user "%s".', $user['alias']));
         }
         // permissions
         if ($create) {
             if (self::$userData['type'] != USER_TYPE_SUPER_ADMIN) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('You do not have permissions to create users.'));
             }
             $dbUser = $user;
         } elseif ($update) {
             if (!isset($dbUsers[$user['userid']])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('You do not have permissions to update user or user does not exist.'));
             }
             if (bccomp(self::$userData['userid'], $user['userid']) != 0 && self::$userData['type'] != USER_TYPE_SUPER_ADMIN) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('You do not have permissions to update other users.'));
             }
             $dbUser = $dbUsers[$user['userid']];
         }
         // check if user alias
         if (isset($user['alias'])) {
             // check if we change guest user
             if ($dbUser['alias'] === ZBX_GUEST_USER && $user['alias'] !== ZBX_GUEST_USER) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot rename guest user.'));
             }
             if (!isset($alias[$user['alias']])) {
                 $alias[$user['alias']] = $update ? $user['userid'] : 1;
             } else {
                 if ($create || bccomp($user['userid'], $alias[$user['alias']]) != 0) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Duplicate user alias "%s".', $user['alias']));
                 }
             }
             if (zbx_strlen($user['alias']) > 64) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _n('Maximum alias length is %1$d characters, "%2$s" is %3$d character.', 'Maximum alias length is %1$d characters, "%2$s" is %3$d characters.', 64, $user['alias'], zbx_strlen($user['alias'])));
             }
         }
         if (isset($user['usrgrps'])) {
             if (empty($user['usrgrps'])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('User "%s" cannot be without user group.', $dbUser['alias']));
             }
             // checking if user tries to disable himself (not allowed). No need to check this on creating a user.
             if (!$create && bccomp(self::$userData['userid'], $user['userid']) == 0) {
                 $usrgrps = API::UserGroup()->get(array('usrgrpids' => zbx_objectValues($user['usrgrps'], 'usrgrpid'), 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'nopermissions' => true));
                 foreach ($usrgrps as $groupid => $group) {
                     if ($group['gui_access'] == GROUP_GUI_ACCESS_DISABLED) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _s('User may not modify GUI access for himself by becoming a member of user group "%s".', $group['name']));
                     }
                     if ($group['users_status'] == GROUP_STATUS_DISABLED) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _s('User may not modify system status for himself by becoming a member of user group "%s".', $group['name']));
                     }
                 }
             }
         }
         if (isset($user['theme'])) {
             $themeValidator->messageInvalid = _s('Incorrect theme for user "%1$s".', $dbUser['alias']);
             $this->checkValidator($user['theme'], $themeValidator);
         }
         if (isset($user['type']) && USER_TYPE_SUPER_ADMIN != self::$userData['type']) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('You are not allowed to alter privileges for user "%s".', $dbUser['alias']));
         }
         if (isset($user['autologin']) && $user['autologin'] == 1 && $dbUser['autologout'] != 0) {
             $user['autologout'] = 0;
         }
         if (isset($user['autologout']) && $user['autologout'] > 0 && $dbUser['autologin'] != 0) {
             $user['autologin'] = 0;
         }
         if (array_key_exists('passwd', $user)) {
             if (is_null($user['passwd'])) {
                 unset($user['passwd']);
             } else {
                 if ($dbUser['alias'] == ZBX_GUEST_USER && !zbx_empty($user['passwd'])) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('Not allowed to set password for user "guest".'));
                 }
                 $user['passwd'] = md5($user['passwd']);
             }
         }
         if (isset($user['alias'])) {
             $nodeids = $update ? id2nodeid($user['userid']) : get_current_nodeid(false);
             $userExist = $this->get(array('nodeids' => $nodeids, 'filter' => array('alias' => $user['alias']), 'nopermissions' => true));
             if ($exUser = reset($userExist)) {
                 if ($create || bccomp($exUser['userid'], $user['userid']) != 0) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('User with alias "%s" already exists.', $user['alias']));
                 }
             }
         }
     }
     unset($user);
 }
示例#14
0
function condition_value2str($conditiontype, $value)
{
    switch ($conditiontype) {
        case CONDITION_TYPE_HOST_GROUP:
            $group = get_hostgroup_by_groupid($value);
            $str_val = '';
            if (id2nodeid($value) != get_current_nodeid()) {
                $str_val = get_node_name_by_elid($value, true, ': ');
            }
            $str_val .= $group['name'];
            break;
        case CONDITION_TYPE_TRIGGER:
            $trig = CTrigger::get(array('triggerids' => $value, 'expandTriggerDescriptions' => true, 'output' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_EXTEND, 'nodeids' => get_current_nodeid(true)));
            $trig = reset($trig);
            $host = reset($trig['hosts']);
            $str_val = '';
            if (id2nodeid($value) != get_current_nodeid()) {
                $str_val = get_node_name_by_elid($value, true, ': ');
            }
            $str_val .= $host['host'] . ':' . $trig['description'];
            break;
        case CONDITION_TYPE_HOST:
        case CONDITION_TYPE_HOST_TEMPLATE:
            $host = get_host_by_hostid($value);
            $str_val = '';
            if (id2nodeid($value) != get_current_nodeid()) {
                $str_val = get_node_name_by_elid($value, true, ': ');
            }
            $str_val .= $host['host'];
            break;
        case CONDITION_TYPE_TRIGGER_NAME:
        case CONDITION_TYPE_HOST_NAME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_TRIGGER_VALUE:
            $str_val = trigger_value2str($value);
            break;
        case CONDITION_TYPE_TRIGGER_SEVERITY:
            $str_val = get_severity_description($value);
            break;
        case CONDITION_TYPE_TIME_PERIOD:
            $str_val = $value;
            break;
        case CONDITION_TYPE_MAINTENANCE:
            $str_val = S_MAINTENANCE_SMALL;
            break;
        case CONDITION_TYPE_NODE:
            $node = get_node_by_nodeid($value);
            $str_val = $node['name'];
            break;
        case CONDITION_TYPE_DRULE:
            $drule = get_discovery_rule_by_druleid($value);
            $str_val = $drule['name'];
            break;
        case CONDITION_TYPE_DCHECK:
            $row = DBfetch(DBselect('SELECT DISTINCT r.name,c.dcheckid,c.type,c.key_,c.snmp_community,c.ports' . ' FROM drules r,dchecks c WHERE r.druleid=c.druleid AND c.dcheckid=' . $value));
            $str_val = $row['name'] . ':' . discovery_check2str($row['type'], $row['snmp_community'], $row['key_'], $row['ports']);
            break;
        case CONDITION_TYPE_DOBJECT:
            $str_val = discovery_object2str($value);
            break;
        case CONDITION_TYPE_PROXY:
            $host = get_host_by_hostid($value);
            $str_val = $host['host'];
            break;
        case CONDITION_TYPE_DHOST_IP:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSERVICE_TYPE:
            $str_val = discovery_check_type2str($value);
            break;
        case CONDITION_TYPE_DSERVICE_PORT:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DSTATUS:
            $str_val = discovery_object_status2str($value);
            break;
        case CONDITION_TYPE_DUPTIME:
            $str_val = $value;
            break;
        case CONDITION_TYPE_DVALUE:
            $str_val = $value;
            break;
        case CONDITION_TYPE_EVENT_ACKNOWLEDGED:
            $str_val = $value ? S_ACK : S_NOT_ACK;
            break;
        case CONDITION_TYPE_APPLICATION:
            $str_val = $value;
            break;
        default:
            return S_UNKNOWN;
            break;
    }
    return '"' . $str_val . '"';
}
示例#15
0
function explode_exp($expressionCompressed, $html = false, $resolveMacro = false, $sourceHost = null, $destinationHost = null)
{
    $expressionExpanded = $html ? array() : '';
    $trigger = array();
    for ($i = 0, $state = '', $max = zbx_strlen($expressionCompressed); $i < $max; $i++) {
        if ($expressionCompressed[$i] == '{') {
            if ($expressionCompressed[$i + 1] == '$') {
                $state = 'USERMACRO';
                $userMacro = '';
            } elseif ($expressionCompressed[$i + 1] == '#') {
                $state = 'LLDMACRO';
                $lldMacro = '';
            } else {
                $state = 'FUNCTIONID';
                $functionId = '';
                continue;
            }
        } elseif ($expressionCompressed[$i] == '}') {
            if ($state == 'USERMACRO') {
                $state = '';
                $userMacro .= '}';
                if ($resolveMacro) {
                    $functionData['expression'] = $userMacro;
                    $userMacro = CMacrosResolverHelper::resolveTriggerExpressionUserMacro($functionData);
                }
                if ($html) {
                    $expressionExpanded[] = $userMacro;
                } else {
                    $expressionExpanded .= $userMacro;
                }
                continue;
            } elseif ($state == 'LLDMACRO') {
                $state = '';
                $lldMacro .= '}';
                if ($html) {
                    $expressionExpanded[] = $lldMacro;
                } else {
                    $expressionExpanded .= $lldMacro;
                }
                continue;
            } elseif ($functionId == 'TRIGGER.VALUE') {
                $state = '';
                if ($html) {
                    $expressionExpanded[] = '{' . $functionId . '}';
                } else {
                    $expressionExpanded .= '{' . $functionId . '}';
                }
                continue;
            }
            $state = '';
            $error = true;
            if (is_numeric($functionId)) {
                $functionData = DBfetch(DBselect('SELECT h.host,h.hostid,i.itemid,i.key_,f.function,f.triggerid,f.parameter,i.itemid,i.status,i.type,i.flags' . ' FROM items i,functions f,hosts h' . ' WHERE f.functionid=' . zbx_dbstr($functionId) . ' AND i.itemid=f.itemid' . ' AND h.hostid=i.hostid'));
                if ($functionData) {
                    $error = false;
                    if ($resolveMacro) {
                        $trigger = $functionData;
                        // expand macros in item key
                        $items = CMacrosResolverHelper::resolveItemKeys(array($functionData));
                        $item = reset($items);
                        $functionData['key_'] = $item['key_expanded'];
                        // expand macros in function parameter
                        $functionParameters = CMacrosResolverHelper::resolveFunctionParameters(array($functionData));
                        $functionParameter = reset($functionParameters);
                        $functionData['parameter'] = $functionParameter['parameter_expanded'];
                    }
                    if ($sourceHost !== null && $destinationHost !== null && $sourceHost === $functionData['host']) {
                        $functionData['host'] = $destinationHost;
                    }
                    if ($html) {
                        if ($functionData['status'] == ITEM_STATUS_DISABLED) {
                            $style = 'disabled';
                        } elseif ($functionData['status'] == ITEM_STATUS_ACTIVE) {
                            $style = 'enabled';
                        } else {
                            $style = 'unknown';
                        }
                        if ($functionData['flags'] == ZBX_FLAG_DISCOVERY_CREATED || $functionData['type'] == ITEM_TYPE_HTTPTEST) {
                            $link = new CSpan($functionData['host'] . ':' . $functionData['key_'], $style);
                        } elseif ($functionData['flags'] == ZBX_FLAG_DISCOVERY_PROTOTYPE) {
                            $link = new CLink($functionData['host'] . ':' . $functionData['key_'], 'disc_prototypes.php?form=update&itemid=' . $functionData['itemid'] . '&parent_discoveryid=' . $trigger['discoveryRuleid'] . '&switch_node=' . id2nodeid($functionData['itemid']), $style);
                        } else {
                            $link = new CLink($functionData['host'] . ':' . $functionData['key_'], 'items.php?form=update&itemid=' . $functionData['itemid'] . '&switch_node=' . id2nodeid($functionData['itemid']), $style);
                        }
                        $expressionExpanded[] = array('{', $link, '.', bold($functionData['function'] . '('), $functionData['parameter'], bold(')'), '}');
                    } else {
                        $expressionExpanded .= '{' . $functionData['host'] . ':' . $functionData['key_'] . '.' . $functionData['function'] . '(' . $functionData['parameter'] . ')}';
                    }
                }
            }
            if ($error) {
                if ($html) {
                    $expressionExpanded[] = new CSpan('*ERROR*', 'on');
                } else {
                    $expressionExpanded .= '*ERROR*';
                }
            }
            continue;
        }
        switch ($state) {
            case 'FUNCTIONID':
                $functionId .= $expressionCompressed[$i];
                break;
            case 'USERMACRO':
                $userMacro .= $expressionCompressed[$i];
                break;
            case 'LLDMACRO':
                $lldMacro .= $expressionCompressed[$i];
                break;
            default:
                if ($html) {
                    $expressionExpanded[] = $expressionCompressed[$i];
                } else {
                    $expressionExpanded .= $expressionCompressed[$i];
                }
        }
    }
    return $expressionExpanded;
}
示例#16
0
 /**
  * Executes a script on the given host and returns the result.
  *
  * @param $scriptId
  * @param $hostId
  *
  * @return bool|array
  */
 public function executeScript($scriptId, $hostId)
 {
     return $this->request(array('request' => 'command', 'nodeid' => id2nodeid($hostId), 'scriptid' => $scriptId, 'hostid' => $hostId));
 }
示例#17
0
function getUserFormData($userid, $isProfile = false)
{
    $config = select_config();
    $data = array('is_profile' => $isProfile);
    if (isset($userid)) {
        $options = array('userids' => $userid, 'output' => API_OUTPUT_EXTEND);
        if ($data['is_profile']) {
            $options['nodeids'] = id2nodeid($userid);
        }
        $users = API::User()->get($options);
        $user = reset($users);
    }
    if (isset($userid) && (!isset($_REQUEST['form_refresh']) || isset($_REQUEST['register']))) {
        $data['alias'] = $user['alias'];
        $data['name'] = $user['name'];
        $data['surname'] = $user['surname'];
        $data['password1'] = null;
        $data['password2'] = null;
        $data['url'] = $user['url'];
        $data['autologin'] = $user['autologin'];
        $data['autologout'] = $user['autologout'];
        $data['lang'] = $user['lang'];
        $data['theme'] = $user['theme'];
        $data['refresh'] = $user['refresh'];
        $data['rows_per_page'] = $user['rows_per_page'];
        $data['user_type'] = $user['type'];
        $data['messages'] = getMessageSettings();
        $userGroups = API::UserGroup()->get(array('userids' => $userid, 'output' => 'usrgrpid'));
        $userGroup = zbx_objectValues($userGroups, 'usrgrpid');
        $data['user_groups'] = zbx_toHash($userGroup);
        $data['user_medias'] = array();
        $dbMedia = DBselect('SELECT m.mediaid,m.mediatypeid,m.period,m.sendto,m.severity,m.active' . ' FROM media m' . ' WHERE m.userid=' . zbx_dbstr($userid));
        while ($dbMedium = DBfetch($dbMedia)) {
            $data['user_medias'][] = $dbMedium;
        }
        if ($data['autologout'] > 0) {
            $_REQUEST['autologout'] = $data['autologout'];
        }
    } else {
        $data['alias'] = get_request('alias', '');
        $data['name'] = get_request('name', '');
        $data['surname'] = get_request('surname', '');
        $data['password1'] = get_request('password1', '');
        $data['password2'] = get_request('password2', '');
        $data['url'] = get_request('url', '');
        $data['autologin'] = get_request('autologin', 0);
        $data['autologout'] = get_request('autologout', 900);
        $data['lang'] = get_request('lang', 'en_gb');
        $data['theme'] = get_request('theme', THEME_DEFAULT);
        $data['refresh'] = get_request('refresh', 30);
        $data['rows_per_page'] = get_request('rows_per_page', 50);
        $data['user_type'] = get_request('user_type', USER_TYPE_ZABBIX_USER);
        $data['user_groups'] = get_request('user_groups', array());
        $data['change_password'] = get_request('change_password', null);
        $data['user_medias'] = get_request('user_medias', array());
        // set messages
        $data['messages'] = get_request('messages', array());
        if (!isset($data['messages']['enabled'])) {
            $data['messages']['enabled'] = 0;
        }
        if (!isset($data['messages']['sounds.recovery'])) {
            $data['messages']['sounds.recovery'] = 'alarm_ok.wav';
        }
        if (!isset($data['messages']['triggers.recovery'])) {
            $data['messages']['triggers.recovery'] = 0;
        }
        if (!isset($data['messages']['triggers.severities'])) {
            $data['messages']['triggers.severities'] = array();
        }
        $data['messages'] = array_merge(getMessageSettings(), $data['messages']);
    }
    // authentication type
    if ($data['user_groups']) {
        $data['auth_type'] = getGroupAuthenticationType($data['user_groups'], GROUP_GUI_ACCESS_INTERNAL);
    } else {
        $data['auth_type'] = $userid === null ? $config['authentication_type'] : getUserAuthenticationType($userid, GROUP_GUI_ACCESS_INTERNAL);
    }
    // set autologout
    if ($data['autologin'] || !isset($data['autologout'])) {
        $data['autologout'] = 0;
    }
    // set media types
    if (!empty($data['user_medias'])) {
        $mediaTypeDescriptions = array();
        $dbMediaTypes = DBselect('SELECT mt.mediatypeid,mt.description FROM media_type mt WHERE ' . dbConditionInt('mt.mediatypeid', zbx_objectValues($data['user_medias'], 'mediatypeid')));
        while ($dbMediaType = DBfetch($dbMediaTypes)) {
            $mediaTypeDescriptions[$dbMediaType['mediatypeid']] = $dbMediaType['description'];
        }
        foreach ($data['user_medias'] as &$media) {
            $media['description'] = $mediaTypeDescriptions[$media['mediatypeid']];
        }
        unset($media);
        CArrayHelper::sort($data['user_medias'], array('description', 'sendto'));
    }
    // set user rights
    if (!$data['is_profile']) {
        $data['groups'] = API::UserGroup()->get(array('usrgrpids' => $data['user_groups'], 'output' => array('usrgrpid', 'name')));
        order_result($data['groups'], 'name');
        $group_ids = array_values($data['user_groups']);
        if (count($group_ids) == 0) {
            $group_ids = array(-1);
        }
        $db_rights = DBselect('SELECT r.* FROM rights r WHERE ' . dbConditionInt('r.groupid', $group_ids));
        // deny beat all, read-write beat read
        $tmp_permitions = array();
        while ($db_right = DBfetch($db_rights)) {
            if (isset($tmp_permitions[$db_right['id']]) && $tmp_permitions[$db_right['id']] != PERM_DENY) {
                $tmp_permitions[$db_right['id']] = $db_right['permission'] == PERM_DENY ? PERM_DENY : max($tmp_permitions[$db_right['id']], $db_right['permission']);
            } else {
                $tmp_permitions[$db_right['id']] = $db_right['permission'];
            }
        }
        $data['user_rights'] = array();
        foreach ($tmp_permitions as $id => $permition) {
            array_push($data['user_rights'], array('id' => $id, 'permission' => $permition));
        }
    }
    return $data;
}
示例#18
0
function get_screen_item_form()
{
    global $USER_DETAILS;
    $form = new CFormTable(S_SCREEN_CELL_CONFIGURATION, 'screenedit.php?screenid=' . $_REQUEST['screenid']);
    $form->SetHelp('web.screenedit.cell.php');
    if (isset($_REQUEST['screenitemid'])) {
        $sql = 'SELECT * ' . ' FROM screens_items' . ' WHERE screenid=' . $_REQUEST['screenid'] . ' AND screenitemid=' . $_REQUEST['screenitemid'];
        $iresult = DBSelect($sql);
        $form->addVar('screenitemid', $_REQUEST['screenitemid']);
    } else {
        $form->addVar('x', $_REQUEST['x']);
        $form->addVar('y', $_REQUEST['y']);
    }
    if (isset($_REQUEST['screenitemid']) && !isset($_REQUEST['form_refresh'])) {
        $irow = DBfetch($iresult);
        $resourcetype = $irow['resourcetype'];
        $resourceid = $irow['resourceid'];
        $width = $irow['width'];
        $height = $irow['height'];
        $colspan = $irow['colspan'];
        $rowspan = $irow['rowspan'];
        $elements = $irow['elements'];
        $valign = $irow['valign'];
        $halign = $irow['halign'];
        $style = $irow['style'];
        $url = $irow['url'];
        $dynamic = $irow['dynamic'];
    } else {
        $resourcetype = get_request('resourcetype', 0);
        $resourceid = get_request('resourceid', 0);
        $width = get_request('width', 500);
        $height = get_request('height', 100);
        $colspan = get_request('colspan', 0);
        $rowspan = get_request('rowspan', 0);
        $elements = get_request('elements', 25);
        $valign = get_request('valign', VALIGN_DEFAULT);
        $halign = get_request('halign', HALIGN_DEFAULT);
        $style = get_request('style', 0);
        $url = get_request('url', '');
        $dynamic = get_request('dynamic', SCREEN_SIMPLE_ITEM);
    }
    $form->addVar('screenid', $_REQUEST['screenid']);
    // a-z order!!!
    $cmbRes = new CCombobox('resourcetype', $resourcetype, 'submit()');
    $cmbRes->addItem(SCREEN_RESOURCE_CLOCK, S_CLOCK);
    $cmbRes->addItem(SCREEN_RESOURCE_DATA_OVERVIEW, S_DATA_OVERVIEW);
    $cmbRes->addItem(SCREEN_RESOURCE_GRAPH, S_GRAPH);
    $cmbRes->addItem(SCREEN_RESOURCE_ACTIONS, S_HISTORY_OF_ACTIONS);
    $cmbRes->addItem(SCREEN_RESOURCE_EVENTS, S_HISTORY_OF_EVENTS);
    $cmbRes->addItem(SCREEN_RESOURCE_HOSTS_INFO, S_HOSTS_INFO);
    $cmbRes->addItem(SCREEN_RESOURCE_MAP, S_MAP);
    $cmbRes->addItem(SCREEN_RESOURCE_PLAIN_TEXT, S_PLAIN_TEXT);
    $cmbRes->addItem(SCREEN_RESOURCE_SCREEN, S_SCREEN);
    $cmbRes->addItem(SCREEN_RESOURCE_SERVER_INFO, S_SERVER_INFO);
    $cmbRes->addItem(SCREEN_RESOURCE_SIMPLE_GRAPH, S_SIMPLE_GRAPH);
    $cmbRes->addItem(SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, S_STATUS_OF_HOSTGROUP_TRIGGERS);
    $cmbRes->addItem(SCREEN_RESOURCE_HOST_TRIGGERS, S_STATUS_OF_HOST_TRIGGERS);
    $cmbRes->addItem(SCREEN_RESOURCE_SYSTEM_STATUS, S_SYSTEM_STATUS);
    $cmbRes->addItem(SCREEN_RESOURCE_TRIGGERS_INFO, S_TRIGGERS_INFO);
    $cmbRes->addItem(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, S_TRIGGERS_OVERVIEW);
    $cmbRes->addItem(SCREEN_RESOURCE_URL, S_URL);
    $form->addRow(S_RESOURCE, $cmbRes);
    if ($resourcetype == SCREEN_RESOURCE_GRAPH) {
        // User-defined graph
        $options = array('graphids' => $resourceid, 'select_hosts' => array('hostid', 'host'), 'output' => API_OUTPUT_EXTEND);
        $graphs = CGraph::get($options);
        $caption = '';
        $id = 0;
        if (!empty($graphs)) {
            $id = $resourceid;
            $graph = reset($graphs);
            order_result($graph['hosts'], 'host');
            $graph['host'] = reset($graph['hosts']);
            $caption = $graph['host']['host'] . ':' . $graph['name'];
            $nodeName = get_node_name_by_elid($graph['host']['hostid']);
            if (!zbx_empty($nodeName)) {
                $caption = '(' . $nodeName . ') ' . $caption;
            }
        }
        $form->addVar('resourceid', $id);
        $textfield = new CTextbox('caption', $caption, 75, 'yes');
        $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&real_hosts=1&dstfld1=resourceid&dstfld2=caption&srctbl=graphs&srcfld1=graphid&srcfld2=name',800,450);");
        $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
        $form->addRow(S_GRAPH_NAME, array($textfield, SPACE, $selectbtn));
    } else {
        if ($resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH) {
            // Simple graph
            $options = array('itemids' => $resourceid, 'select_hosts' => array('hostid', 'host'), 'output' => API_OUTPUT_EXTEND);
            $items = CItem::get($options);
            $caption = '';
            $id = 0;
            if (!empty($items)) {
                $id = $resourceid;
                $item = reset($items);
                $item['host'] = reset($item['hosts']);
                $caption = item_description($item);
                $nodeName = get_node_name_by_elid($item['itemid']);
                if (!zbx_empty($nodeName)) {
                    $caption = '(' . $nodeName . ') ' . $caption;
                }
            }
            $form->addVar('resourceid', $id);
            $textfield = new Ctextbox('caption', $caption, 75, 'yes');
            $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&real_hosts=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=simple_graph&srcfld1=itemid&srcfld2=description',800,450);");
            $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
            $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn));
        } else {
            if ($resourcetype == SCREEN_RESOURCE_MAP) {
                // Map
                $options = array('sysmapids' => $resourceid, 'output' => API_OUTPUT_EXTEND);
                $maps = CMap::get($options);
                $caption = '';
                $id = 0;
                if (!empty($maps)) {
                    $id = $resourceid;
                    $map = reset($maps);
                    $caption = $map['name'];
                    $nodeName = get_node_name_by_elid($map['sysmapid']);
                    if (!zbx_empty($nodeName)) {
                        $caption = '(' . $nodeName . ') ' . $caption;
                    }
                }
                $form->addVar('resourceid', $id);
                $textfield = new Ctextbox('caption', $caption, 60, 'yes');
                $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=sysmaps&srcfld1=sysmapid&srcfld2=name',400,450);");
                $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn));
            } else {
                if ($resourcetype == SCREEN_RESOURCE_PLAIN_TEXT) {
                    // Plain text
                    $options = array('itemids' => $resourceid, 'select_hosts' => array('hostid', 'host'), 'output' => API_OUTPUT_EXTEND);
                    $items = CItem::get($options);
                    $caption = '';
                    $id = 0;
                    if (!empty($items)) {
                        $id = $resourceid;
                        $item = reset($items);
                        $item['host'] = reset($item['hosts']);
                        $caption = item_description($item);
                        $nodeName = get_node_name_by_elid($item['itemid']);
                        if (!zbx_empty($nodeName)) {
                            $caption = '(' . $nodeName . ') ' . $caption;
                        }
                    }
                    $form->addVar('resourceid', $id);
                    $textfield = new CTextbox('caption', $caption, 75, 'yes');
                    $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=plain_text&srcfld1=itemid&srcfld2=description',800,450);");
                    $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                    $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn));
                    $form->addRow(S_SHOW_LINES, new CNumericBox('elements', $elements, 2));
                    $form->addRow(S_SHOW_TEXT_AS_HTML, new CCheckBox('style', $style, null, 1));
                } else {
                    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, SCREEN_RESOURCE_HOST_TRIGGERS))) {
                        // Status of triggers
                        $caption = '';
                        $id = 0;
                        if (SCREEN_RESOURCE_HOSTGROUP_TRIGGERS == $resourcetype) {
                            if ($resourceid > 0) {
                                $options = array('groupids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                                $groups = CHostgroup::get($options);
                                foreach ($groups as $gnum => $group) {
                                    $caption = get_node_name_by_elid($group['groupid'], true, ':') . $group['name'];
                                    $id = $resourceid;
                                }
                            }
                            $form->addVar('resourceid', $id);
                            $textfield = new CTextbox('caption', $caption, 60, 'yes');
                            $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=host_group&srcfld1=groupid&srcfld2=name',800,450);");
                            $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                            $form->addRow(S_GROUP, array($textfield, SPACE, $selectbtn));
                        } else {
                            if ($resourceid > 0) {
                                $options = array('hostids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                                $hosts = CHost::get($options);
                                foreach ($hosts as $hnum => $host) {
                                    $caption = get_node_name_by_elid($host['hostid'], true, ':') . $host['host'];
                                    $id = $resourceid;
                                }
                            }
                            $form->addVar('resourceid', $id);
                            $textfield = new CTextbox('caption', $caption, 60, 'yes');
                            $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=hosts&srcfld1=hostid&srcfld2=host',800,450);");
                            $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                            $form->addRow(S_HOST, array($textfield, SPACE, $selectbtn));
                        }
                        $form->addRow(S_SHOW_LINES, new CNumericBox('elements', $elements, 2));
                    } else {
                        if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_EVENTS, SCREEN_RESOURCE_ACTIONS))) {
                            // History of actions
                            // History of events
                            $form->addRow(S_SHOW_LINES, new CNumericBox('elements', $elements, 2));
                            $form->addVar('resourceid', 0);
                        } else {
                            if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW))) {
                                // Overviews
                                $caption = '';
                                $id = 0;
                                if ($resourceid > 0) {
                                    $options = array('groupids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                                    $groups = CHostgroup::get($options);
                                    foreach ($groups as $gnum => $group) {
                                        $caption = get_node_name_by_elid($group['groupid'], true, ':') . $group['name'];
                                        $id = $resourceid;
                                    }
                                }
                                $form->addVar('resourceid', $id);
                                $textfield = new CTextbox('caption', $caption, 75, 'yes');
                                $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=overview&srcfld1=groupid&srcfld2=name',800,450);");
                                $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                                $form->addRow(S_GROUP, array($textfield, SPACE, $selectbtn));
                            } else {
                                if ($resourcetype == SCREEN_RESOURCE_SCREEN) {
                                    // Screens
                                    $caption = '';
                                    $id = 0;
                                    if ($resourceid > 0) {
                                        $result = DBselect('SELECT DISTINCT n.name as node_name,s.screenid,s.name ' . ' FROM screens s ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('s.screenid') . ' WHERE s.screenid=' . $resourceid);
                                        while ($row = DBfetch($result)) {
                                            $r = CScreen::get(array('screenids' => $row['screenid'], 'output' => API_OUTPUT_SHORTEN));
                                            if (empty($r)) {
                                                continue;
                                            }
                                            if (check_screen_recursion($_REQUEST['screenid'], $row['screenid'])) {
                                                continue;
                                            }
                                            $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : '';
                                            $caption = $row['node_name'] . $row['name'];
                                            $id = $resourceid;
                                        }
                                    }
                                    $form->addVar('resourceid', $id);
                                    $textfield = new Ctextbox('caption', $caption, 60, 'yes');
                                    $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=screens2&srcfld1=screenid&srcfld2=name&screenid=" . $_REQUEST['screenid'] . "',800,450);");
                                    $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                                    $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn));
                                } else {
                                    if ($resourcetype == SCREEN_RESOURCE_HOSTS_INFO || $resourcetype == SCREEN_RESOURCE_TRIGGERS_INFO) {
                                        // HOSTS info
                                        $caption = '';
                                        $id = 0;
                                        $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY);
                                        if (remove_nodes_from_id($resourceid) > 0) {
                                            $result = DBselect('SELECT DISTINCT n.name as node_name,g.groupid,g.name ' . ' FROM hosts_groups hg, groups g ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('g.groupid') . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' AND g.groupid=' . $resourceid);
                                            while ($row = DBfetch($result)) {
                                                $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : '';
                                                $caption = $row['node_name'] . $row['name'];
                                                $id = $resourceid;
                                            }
                                        } else {
                                            if (remove_nodes_from_id($resourceid) == 0) {
                                                $result = DBselect('SELECT DISTINCT n.name as node_name ' . ' FROM nodes n ' . ' WHERE n.nodeid=' . id2nodeid($resourceid));
                                                while ($row = DBfetch($result)) {
                                                    $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : '';
                                                    $caption = $row['node_name'] . S_MINUS_ALL_GROUPS_MINUS;
                                                    $id = $resourceid;
                                                }
                                            }
                                        }
                                        $form->addVar('resourceid', $id);
                                        $textfield = new CTextbox('caption', $caption, 60, 'yes');
                                        $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=host_group_scr&srcfld1=groupid&srcfld2=name',480,450);");
                                        $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                                        $form->addRow(S_GROUP, array($textfield, SPACE, $selectbtn));
                                    } else {
                                        // SCREEN_RESOURCE_CLOCK
                                        $form->addVar('resourceid', 0);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO))) {
        $cmbStyle = new CComboBox("style", $style);
        $cmbStyle->addItem(STYLE_HORISONTAL, S_HORIZONTAL);
        $cmbStyle->addItem(STYLE_VERTICAL, S_VERTICAL);
        $form->addRow(S_STYLE, $cmbStyle);
    } else {
        if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW))) {
            $cmbStyle = new CComboBox('style', $style);
            $cmbStyle->addItem(STYLE_LEFT, S_LEFT);
            $cmbStyle->addItem(STYLE_TOP, S_TOP);
            $form->addRow(S_HOSTS_LOCATION, $cmbStyle);
        } else {
            if ($resourcetype == SCREEN_RESOURCE_CLOCK) {
                $cmbStyle = new CComboBox('style', $style);
                $cmbStyle->addItem(TIME_TYPE_LOCAL, S_LOCAL_TIME);
                $cmbStyle->addItem(TIME_TYPE_SERVER, S_SERVER_TIME);
                $form->addRow(S_TIME_TYPE, $cmbStyle);
            } else {
                $form->addVar('style', 0);
            }
        }
    }
    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_URL))) {
        $form->addRow(S_URL, new CTextBox('url', $url, 60));
    } else {
        $form->addVar('url', '');
    }
    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_CLOCK, SCREEN_RESOURCE_URL))) {
        $form->addRow(S_WIDTH, new CNumericBox('width', $width, 5));
        $form->addRow(S_HEIGHT, new CNumericBox('height', $height, 5));
    } else {
        $form->addVar('width', 500);
        $form->addVar('height', 100);
    }
    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_MAP, SCREEN_RESOURCE_CLOCK, SCREEN_RESOURCE_URL))) {
        $cmbHalign = new CComboBox('halign', $halign);
        $cmbHalign->addItem(HALIGN_CENTER, S_CENTRE);
        $cmbHalign->addItem(HALIGN_LEFT, S_LEFT);
        $cmbHalign->addItem(HALIGN_RIGHT, S_RIGHT);
        $form->addRow(S_HORIZONTAL_ALIGN, $cmbHalign);
    } else {
        $form->addVar('halign', 0);
    }
    $cmbValign = new CComboBox('valign', $valign);
    $cmbValign->addItem(VALIGN_MIDDLE, S_MIDDLE);
    $cmbValign->addItem(VALIGN_TOP, S_TOP);
    $cmbValign->addItem(VALIGN_BOTTOM, S_BOTTOM);
    $form->addRow(S_VERTICAL_ALIGN, $cmbValign);
    $form->addRow(S_COLUMN_SPAN, new CNumericBox('colspan', $colspan, 2));
    $form->addRow(S_ROW_SPAN, new CNumericBox('rowspan', $rowspan, 2));
    // dynamic AddOn
    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT))) {
        $form->addRow(S_DYNAMIC_ITEM, new CCheckBox('dynamic', $dynamic, null, 1));
    }
    $form->addItemToBottomRow(new CButton('save', S_SAVE));
    if (isset($_REQUEST['screenitemid'])) {
        $form->addItemToBottomRow(SPACE);
        $form->addItemToBottomRow(new CButtonDelete(null, url_param('form') . url_param('screenid') . url_param('screenitemid')));
    }
    $form->addItemToBottomRow(SPACE);
    $form->addItemToBottomRow(new CButtonCancel(url_param('screenid')));
    return $form;
}
示例#19
0
文件: chart3.php 项目: rennhak/zabbix
$fields = array('period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'from' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'stime' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'border' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'name' => array(T_ZBX_STR, O_OPT, NULL, null, null), 'width' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), null), 'height' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), null), 'ymin_type' => array(T_ZBX_INT, O_OPT, NULL, IN('0,1,2'), null), 'ymax_type' => array(T_ZBX_INT, O_OPT, NULL, IN('0,1,2'), null), 'ymin_itemid' => array(T_ZBX_INT, O_OPT, NULL, DB_ID, null), 'ymax_itemid' => array(T_ZBX_INT, O_OPT, NULL, DB_ID, null), 'graphtype' => array(T_ZBX_INT, O_OPT, NULL, IN('0,1'), null), 'yaxismin' => array(T_ZBX_DBL, O_OPT, NULL, BETWEEN(-65535, 65535), null), 'yaxismax' => array(T_ZBX_DBL, O_OPT, NULL, null, null), 'percent_left' => array(T_ZBX_DBL, O_OPT, NULL, BETWEEN(0, 100), null), 'percent_right' => array(T_ZBX_DBL, O_OPT, NULL, BETWEEN(0, 100), null), 'items' => array(T_ZBX_STR, O_OPT, NULL, null, null));
check_fields($fields);
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY, get_current_nodeid(true));
$items = get_request('items', array());
asort_by_key($items, 'sortorder');
foreach ($items as $id => $gitem) {
    if (!($host = DBfetch(DBselect('select h.* from hosts h,items i where h.hostid=i.hostid and i.itemid=' . $gitem['itemid'])))) {
        fatal_error(S_NO_ITEM_DEFINED);
    }
    if (!isset($available_hosts[$host['hostid']])) {
        access_deny();
    }
}
$graph = new CChart(get_request('graphtype', GRAPH_TYPE_NORMAL));
$chart_header = '';
if (id2nodeid($host['hostid']) != get_current_nodeid()) {
    $chart_header = get_node_name_by_elid($host['hostid'], true);
}
$chart_header .= $host['host'] . ':' . get_request('name', '');
$graph->setHeader($chart_header);
unset($host);
if (isset($_REQUEST['period'])) {
    $graph->setPeriod($_REQUEST['period']);
}
if (isset($_REQUEST['from'])) {
    $graph->setFrom($_REQUEST['from']);
}
if (isset($_REQUEST['stime'])) {
    $graph->setSTime($_REQUEST['stime']);
}
if (isset($_REQUEST['border'])) {
示例#20
0
    $_REQUEST['hostid'] = $onlyHostid;
    unset($_REQUEST['groupid'], $_REQUEST['nodeid']);
}
// value types
$value_types = null;
if (get_request('value_types')) {
    $value_types = get_request('value_types');
} elseif (get_request('numeric')) {
    $value_types = array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64);
}
// choose nodes
// if an LLD rule is selected, use its node
if (hasRequest('parent_discoveryid')) {
    $nodeId = id2nodeid(getRequest('parent_discoveryid'));
} elseif (hasRequest('only_hostid')) {
    $nodeId = id2nodeid(getRequest('only_hostid'));
} else {
    $nodeId = getRequest('nodeid', get_current_nodeid(false));
}
clearCookies(true);
function get_window_opener($frame, $field, $value)
{
    if (empty($field)) {
        return '';
    }
    return '
		try {' . "window.opener.document.getElementById('" . addslashes($field) . "').value='" . addslashes($value) . "'; " . '} catch(e) {' . 'throw("Error: Target not found")' . '}' . "\n";
}
/*
 * Page filter
 */
function get_node_name_by_elid($id_val, $force_with_all_nodes = null, $delimiter = '')
{
    global $ZBX_NODES, $ZBX_VIEWED_NODES;
    if ($force_with_all_nodes === false || is_null($force_with_all_nodes) && $ZBX_VIEWED_NODES['selected'] != 0) {
        return null;
    }
    $nodeid = id2nodeid($id_val);
    if (!isset($ZBX_NODES[$nodeid])) {
        return null;
    }
    return $ZBX_NODES[$nodeid]['name'] . $delimiter;
}
示例#22
0
function get_node_name_by_elid($id_val, $forse_with_subnodes = null)
{
    global $ZBX_NODES;
    if (!is_show_subnodes($forse_with_subnodes)) {
        return null;
    }
    $nodeid = id2nodeid($id_val);
    if (!isset($ZBX_NODES[$nodeid])) {
        return null;
    }
    return '[' . $ZBX_NODES[$nodeid]['name'] . '] ';
}
示例#23
0
/**
 * Prepare data for trigger menu popup.
 *
 * @param array  $trigger						trigger data
 * @param string $trigger['triggerid']			trigger id
 * @param int    $trigger['flags']				trigger flags (TRIGGER_FLAG_DISCOVERY*)
 * @param array  $trigger['hosts']				hosts, used by trigger expression
 * @param string $trigger['hosts'][]['hostid']	host id
 * @param string $trigger['url']				url
 * @param array  $items							trigger items (optional)
 * @param string $items[]['name']				item name
 * @param array  $items[]['params']				item url parameters ("name" => "value")
 * @param array  $acknowledge					acknowledge link parameters (optional)
 * @param string $acknowledge['eventid']		event id
 * @param string $acknowledge['screenid']		screen id (optional)
 * @param string $acknowledge['backurl']		return url (optional)
 * @param string $eventTime						event navigation time parameter (optional)
 *
 * @return array
 */
function getMenuPopupTrigger(array $trigger, array $items = null, array $acknowledge = null, $eventTime = null)
{
    if ($items) {
        CArrayHelper::sort($items, array('name'));
    }
    $data = array('type' => 'trigger', 'triggerid' => $trigger['triggerid'], 'items' => $items, 'acknowledge' => $acknowledge, 'eventTime' => $eventTime, 'configuration' => null, 'url' => resolveTriggerUrl($trigger));
    if ((CWebUser::$data['type'] == USER_TYPE_ZABBIX_ADMIN || CWebUser::$data['type'] == USER_TYPE_SUPER_ADMIN) && $trigger['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
        $host = reset($trigger['hosts']);
        $data['configuration'] = array('hostid' => $host['hostid'], 'switchNode' => id2nodeid($trigger['triggerid']));
    }
    return $data;
}
示例#24
0
function get_accessible_nodes_by_rights(&$rights, $user_type, $perm, $perm_res = null)
{
    global $ZBX_LOCALNODEID;
    $nodeid = get_current_nodeid(true);
    if (is_null($perm_res)) {
        $perm_res = PERM_RES_STRING_LINE;
    }
    if (is_null($user_type)) {
        $user_type = USER_TYPE_ZABBIX_USER;
    }
    $node_data = array();
    $result = array();
    //COpt::counter_up('perm_nodes['.$userid.','.$perm.','.$perm_mode.','.$perm_res.','.$nodeid.']');
    //COpt::counter_up('perm');
    //SDI(get_accessible_groups_by_rights($rights,$user_type,$perm,PERM_RES_DATA_ARRAY,$nodeid));
    $available_groups = get_accessible_groups_by_rights($rights, $user_type, $perm, PERM_RES_DATA_ARRAY, $nodeid);
    foreach ($available_groups as $id => $group) {
        $nodeid = id2nodeid($group['groupid']);
        $permission = $group['permission'];
        if (isset($node_data[$nodeid]) && $permission < $node_data[$nodeid]['permission']) {
            $permission = $node_data[$nodeid]['permission'];
        }
        $node_data[$nodeid]['nodeid'] = $nodeid;
        $node_data[$nodeid]['permission'] = $permission;
    }
    $available_hosts = get_accessible_hosts_by_rights($rights, $user_type, $perm, PERM_RES_DATA_ARRAY, $nodeid);
    foreach ($available_hosts as $id => $host) {
        $nodeid = id2nodeid($host['hostid']);
        $permission = $host['permission'];
        if (isset($node_data[$nodeid]) && $permission < $node_data[$nodeid]['permission']) {
            $permission = $node_data[$nodeid]['permission'];
        }
        $node_data[$nodeid]['nodeid'] = $nodeid;
        $node_data[$nodeid]['permission'] = $permission;
    }
    foreach ($node_data as $nodeid => $node) {
        switch ($perm_res) {
            case PERM_RES_DATA_ARRAY:
                $db_node = DBfetch(DBselect('SELECT * FROM nodes WHERE nodeid=' . $nodeid));
                if (!ZBX_DISTRIBUTED) {
                    if (!$node) {
                        $db_node = array('nodeid' => $ZBX_LOCALNODEID, 'name' => 'local', 'permission' => PERM_READ_WRITE, 'userid' => null);
                    } else {
                        continue;
                    }
                }
                $result[$nodeid] = array_merge($db_node, $node);
                break;
            default:
                $result[$nodeid] = $nodeid;
                break;
        }
    }
    if ($perm_res == PERM_RES_STRING_LINE) {
        if (count($result) == 0) {
            $result = '-1';
        } else {
            $result = implode(',', $result);
        }
    }
    return $result;
}
示例#25
0
function explode_exp($expression, $html = false, $resolve_macro = false, $src_host = null, $dst_host = null)
{
    $exp = !$html ? '' : array();
    $trigger = array();
    for ($i = 0, $state = '', $max = zbx_strlen($expression); $i < $max; $i++) {
        if ($expression[$i] == '{') {
            if ($expression[$i + 1] == '$') {
                $usermacro = '';
                $state = 'USERMACRO';
            } elseif ($expression[$i + 1] == '#') {
                $lldmacro = '';
                $state = 'LLDMACRO';
            } else {
                $functionid = '';
                $state = 'FUNCTIONID';
                continue;
            }
        } elseif ($expression[$i] == '}') {
            if ($state == 'USERMACRO') {
                $usermacro .= '}';
                if ($resolve_macro) {
                    $function_data['expression'] = $usermacro;
                    $function_data = API::UserMacro()->resolveTrigger($function_data);
                    $usermacro = $function_data['expression'];
                }
                if ($html) {
                    array_push($exp, $usermacro);
                } else {
                    $exp .= $usermacro;
                }
                $state = '';
                continue;
            } elseif ($state == 'LLDMACRO') {
                $lldmacro .= '}';
                if ($html) {
                    array_push($exp, $lldmacro);
                } else {
                    $exp .= $lldmacro;
                }
                $state = '';
                continue;
            } elseif ($functionid == 'TRIGGER.VALUE') {
                if ($html) {
                    array_push($exp, '{' . $functionid . '}');
                } else {
                    $exp .= '{' . $functionid . '}';
                }
                $state = '';
                continue;
            }
            $sql = 'SELECT h.host,i.itemid,i.key_,f.function,f.triggerid,f.parameter,i.itemid,i.status,i.type,i.flags' . ' FROM items i,functions f,hosts h' . ' WHERE f.functionid=' . $functionid . ' AND i.itemid=f.itemid' . ' AND h.hostid=i.hostid';
            if (is_numeric($functionid) && ($function_data = DBfetch(DBselect($sql)))) {
                if ($resolve_macro) {
                    $trigger = $function_data;
                    $function_data = API::UserMacro()->resolveItem($function_data);
                    $function_data['expression'] = $function_data['parameter'];
                    $function_data = API::UserMacro()->resolveTrigger($function_data);
                    $function_data['parameter'] = $function_data['expression'];
                }
                if (!is_null($src_host) && !is_null($dst_host) && strcmp($src_host, $function_data['host']) == 0) {
                    $function_data['host'] = $dst_host;
                }
                if ($html) {
                    $style = $function_data['status'] == ITEM_STATUS_DISABLED ? 'disabled' : 'unknown';
                    if ($function_data['status'] == ITEM_STATUS_ACTIVE) {
                        $style = 'enabled';
                    }
                    if ($function_data['flags'] == ZBX_FLAG_DISCOVERY_CREATED || $function_data['type'] == ITEM_TYPE_HTTPTEST) {
                        $link = new CSpan($function_data['host'] . ':' . $function_data['key_'], $style);
                    } elseif ($function_data['flags'] == ZBX_FLAG_DISCOVERY_PROTOTYPE) {
                        $link = new CLink($function_data['host'] . ':' . $function_data['key_'], 'disc_prototypes.php?form=update&itemid=' . $function_data['itemid'] . '&parent_discoveryid=' . $trigger['discoveryRuleid'] . '&switch_node=' . id2nodeid($function_data['itemid']), $style);
                    } else {
                        $link = new CLink($function_data['host'] . ':' . $function_data['key_'], 'items.php?form=update&itemid=' . $function_data['itemid'] . '&switch_node=' . id2nodeid($function_data['itemid']), $style);
                    }
                    array_push($exp, array('{', $link, '.', bold($function_data['function'] . '('), $function_data['parameter'], bold(')'), '}'));
                } else {
                    $exp .= '{' . $function_data['host'] . ':' . $function_data['key_'] . '.' . $function_data['function'] . '(' . $function_data['parameter'] . ')}';
                }
            } else {
                if ($html) {
                    array_push($exp, new CSpan('*ERROR*', 'on'));
                } else {
                    $exp .= '*ERROR*';
                }
            }
            $state = '';
            continue;
        }
        switch ($state) {
            case 'FUNCTIONID':
                $functionid .= $expression[$i];
                break;
            case 'USERMACRO':
                $usermacro .= $expression[$i];
                break;
            case 'LLDMACRO':
                $lldmacro .= $expression[$i];
                break;
            default:
                if ($html) {
                    array_push($exp, $expression[$i]);
                } else {
                    $exp .= $expression[$i];
                }
        }
    }
    return $exp;
}
示例#26
0
 /**
  * Update Users
  *
  * {@source}
  * @access public
  * @static
  * @since 1.8
  * @version 1
  *
  * @param _array $users multidimensional array with Users data
  * @param string $users['userid']
  * @param string $users['name']
  * @param string $users['surname']
  * @param array $users['alias']
  * @param string $users['passwd']
  * @param string $users['url']
  * @param int $users['autologin']
  * @param int $users['autologout']
  * @param string $users['lang']
  * @param string $users['theme']
  * @param int $users['refresh']
  * @param int $users['rows_per_page']
  * @param int $users['type']
  * @param array $users['user_medias']
  * @param string $users['user_medias']['mediatypeid']
  * @param string $users['user_medias']['address']
  * @param int $users['user_medias']['severity']
  * @param int $users['user_medias']['active']
  * @param string $users['user_medias']['period']
  * @return boolean
  */
 public static function updateProfile($user)
 {
     global $USER_DETAILS;
     $errors = array();
     $result = true;
     $options = array('nodeids' => id2nodeid($USER_DETAILS['userid']), 'userids' => $USER_DETAILS['userid'], 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1);
     $upd_users = self::get($options);
     $upd_user = reset($upd_users);
     //add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_USER, 'User ['.$user['alias'].']');
     self::BeginTransaction(__METHOD__);
     $user_db_fields = $upd_user;
     // unset if not changed passwd
     if (isset($user['passwd']) && !is_null($user['passwd'])) {
         $user['passwd'] = md5($user['passwd']);
     } else {
         unset($user['passwd']);
     }
     //---------
     if (!check_db_fields($user_db_fields, $user)) {
         $errors[] = array('errno' => ZBX_API_ERROR_PARAMETERS, 'error' => S_CUSER_ERROR_WRONG_FIELD_FOR_USER);
         $result = false;
         break;
     }
     // copy from frontend {
     $sql = 'UPDATE users SET ' . ' passwd=' . zbx_dbstr($user['passwd']) . ', ' . ' url=' . zbx_dbstr($user['url']) . ', ' . ' autologin='******'autologin'] . ', ' . ' autologout=' . $user['autologout'] . ', ' . ' lang=' . zbx_dbstr($user['lang']) . ', ' . ' theme=' . zbx_dbstr($user['theme']) . ', ' . ' refresh=' . $user['refresh'] . ', ' . ' rows_per_page=' . $user['rows_per_page'] . ' WHERE userid=' . $user['userid'];
     $result = DBexecute($sql);
     $result = self::EndTransaction($result, __METHOD__);
     if ($result) {
         $options = array('nodeids' => id2nodeid($USER_DETAILS['userid']), 'userids' => $USER_DETAILS['userid'], 'extendoutput' => 1);
         $upd_users = self::get($options);
         return $upd_users;
     } else {
         self::setMethodErrors(__METHOD__, $errors);
         return false;
     }
 }
示例#27
0
     $img = new Cimg('images/general/up_icon.png', 'DEP_UP');
     $img->setAttribute('style', 'vertical-align: middle; border: 0px;');
     $img->setHint($dep_table);
     $description = array($img, SPACE, $description);
 }
 unset($img, $dep_table, $dependency);
 // }}} DEPENDENCIES
 $tr_desc = new CSpan($description);
 // host JS menu {{{
 $hosts_list = array();
 foreach ($trigger['hosts'] as $num => $trigger_host) {
     $menus = '';
     $host_nodeid = id2nodeid($trigger_host['hostid']);
     if (isset($scripts_by_hosts[$trigger_host['hostid']])) {
         foreach ($scripts_by_hosts[$trigger_host['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=" . $trigger_host['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']}],";
             }
         }
     }
     if (!empty($scripts_by_hosts)) {
         $menus = "[" . zbx_jsvalue(S_TOOLS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus;
     }
     $menus .= "[" . zbx_jsvalue(S_LINKS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],";
     $menus .= "['" . S_LATEST_DATA . "',\"javascript: redirect('latest.php?hostid=" . $trigger_host['hostid'] . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
     $menus = rtrim($menus, ',');
     $menus = 'show_popup_menu(event,[' . $menus . '],180);';
     $maint_span = null;
     if ($trigger_host['maintenance_status']) {
         $text = $trigger_host['maintenance_type'] ? S_NO_DATA_MAINTENANCE : S_NORMAL_MAINTENANCE;
示例#28
0
    show_error_message(S_NO_GRAPH_DEFINED);
}
$options = array('nodeids' => get_current_nodeid(true), 'graphids' => $_REQUEST['graphid'], 'output' => API_OUTPUT_EXTEND);
$db_data = CGraph::get($options);
if (empty($db_data)) {
    access_deny();
} else {
    $db_data = reset($db_data);
}
$options = array('nodeids' => get_current_nodeid(true), 'graphids' => $_REQUEST['graphid'], 'output' => API_OUTPUT_EXTEND);
$host = CHost::get($options);
$host = reset($host);
$effectiveperiod = navigation_bar_calc();
CProfile::update('web.charts.graphid', $_REQUEST['graphid'], PROFILE_TYPE_ID);
$chart_header = '';
if (id2nodeid($db_data['graphid']) != get_current_nodeid()) {
    $chart_header = get_node_name_by_elid($db_data['graphid'], true, ': ');
}
$chart_header .= $host['host'] . ': ' . $db_data['name'];
$graph = new CChart($db_data['graphtype']);
$graph->setHeader($chart_header);
if (isset($_REQUEST['period'])) {
    $graph->setPeriod($_REQUEST['period']);
}
if (isset($_REQUEST['stime'])) {
    $graph->setSTime($_REQUEST['stime']);
}
if (isset($_REQUEST['border'])) {
    $graph->setBorder(0);
}
$width = get_request('width', 0);
示例#29
0
function update_user($userid, $user)
{
    $result = true;
    $sql = 'SELECT DISTINCT * ' . ' FROM users ' . ' WHERE ( alias=' . zbx_dbstr($user['alias']) . ' OR userid=' . $userid . ' ) ' . ' AND ' . DBin_node('userid', id2nodeid($userid));
    $db_users = DBselect($sql);
    while ($db_user = DBfetch($db_users)) {
        if ($db_user['userid'] != $userid) {
            error('User ' . $user['alias'] . ' already exists');
            return false;
        }
        $user_db_fields = $db_user;
    }
    if (!isset($user_db_fields)) {
        return false;
    }
    if (isset($user['passwd'])) {
        $user['passwd'] = md5($user['passwd']);
    }
    if (!check_db_fields($user_db_fields, $user)) {
        error('Incorrect arguments pasted to function [update_user]');
        return false;
    }
    $sql = 'UPDATE users SET ' . ' name=' . zbx_dbstr($user['name']) . ' ,surname=' . zbx_dbstr($user['surname']) . ' ,alias=' . zbx_dbstr($user['alias']) . ' ,passwd=' . zbx_dbstr($user['passwd']) . ' ,url=' . zbx_dbstr($user['url']) . ' ,autologin='******'autologin'] . ' ,autologout=' . $user['autologout'] . ' ,lang=' . zbx_dbstr($user['lang']) . ' ,theme=' . zbx_dbstr($user['theme']) . ' ,refresh=' . $user['refresh'] . ' ,rows_per_page=' . $user['rows_per_page'] . ' ,type=' . $user['type'] . ' WHERE userid=' . $userid;
    $result = DBexecute($sql);
    if ($result && !is_null($user['user_groups'])) {
        $result = DBexecute('DELETE FROM users_groups WHERE userid=' . $userid);
        foreach ($user['user_groups'] as $groupid => $group_name) {
            if (!$result) {
                break;
            }
            $users_groups_id = get_dbid('users_groups', 'id');
            $result = DBexecute('INSERT INTO users_groups (id, usrgrpid, userid)' . 'values(' . $users_groups_id . ',' . $groupid . ',' . $userid . ')');
        }
    }
    if ($result && !is_null($user['user_medias'])) {
        $result = DBexecute('DELETE FROM media WHERE userid=' . $userid);
        foreach ($user['user_medias'] as $mediaid => $media_data) {
            if (!$result) {
                break;
            }
            $mediaid = get_dbid('media', 'mediaid');
            $result = DBexecute('INSERT INTO media (mediaid, userid, mediatypeid, sendto, active, severity, period)' . ' values (' . $mediaid . ',' . $userid . ',' . $media_data['mediatypeid'] . ',' . zbx_dbstr($media_data['sendto']) . ',' . $media_data['active'] . ',' . $media_data['severity'] . ',' . zbx_dbstr($media_data['period']) . ')');
        }
    }
    return $result;
}
示例#30
0
function get_node_name_by_elid($id_val, $forse_with_all_nodes = null)
{
    global $ZBX_NODES, $ZBX_VIEWED_NODES;
    if ($forse_with_all_nodes === false || is_null($forse_with_all_nodes) && $ZBX_VIEWED_NODES['selected'] != 0) {
        return null;
    }
    $nodeid = id2nodeid($id_val);
    //SDI($nodeid.' - '.$ZBX_NODES[$nodeid]['name']);
    if (!isset($ZBX_NODES[$nodeid])) {
        return null;
    }
    return '[' . $ZBX_NODES[$nodeid]['name'] . '] ';
}