public function bodyToString() { $this->cleanItems(); $total = 0; // fetch accessible host ids $hosts = API::Host()->get(array('nodeids' => get_current_nodeid(true), 'output' => array('hostid'), 'preservekeys' => true)); $hostIds = array_keys($hosts); if (remove_nodes_from_id($this->groupid) > 0) { $cond_from = ',hosts_groups hg'; $cond_where = ' AND hg.hostid=h.hostid AND hg.groupid=' . zbx_dbstr($this->groupid); } else { $cond_from = ''; $cond_where = andDbNode('h.hostid', $this->nodeid); } $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $avail = $host_cnt['cnt']; $total += $host_cnt['cnt']; $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $notav = $host_cnt['cnt']; $total += $host_cnt['cnt']; $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $uncn = $host_cnt['cnt']; $total += $host_cnt['cnt']; $node = get_node_by_nodeid($this->nodeid); $header_str = _('Hosts info') . SPACE; if ($node > 0) { $header_str .= '(' . $node['name'] . ')' . SPACE; } if (remove_nodes_from_id($this->groupid) > 0) { $group = get_hostgroup_by_groupid($this->groupid); $header_str .= _('Group') . SPACE . '"' . $group['name'] . '"'; } else { $header_str .= _('All groups'); } $header = new CCol($header_str, 'header'); if ($this->style == STYLE_HORISONTAL) { $header->setColspan(4); } $this->addRow($header); $avail = new CCol($avail . ' ' . _('Available'), 'avail'); $notav = new CCol($notav . ' ' . _('Not available'), 'notav'); $uncn = new CCol($uncn . ' ' . _('Unknown'), 'uncn'); $total = new CCol($total . ' ' . _('Total'), 'total'); if ($this->style == STYLE_HORISONTAL) { $this->addRow(array($avail, $notav, $uncn, $total)); } else { $this->addRow($avail); $this->addRow($notav); $this->addRow($uncn); $this->addRow($total); } return parent::bodyToString(); }
function updateRegexp(array $regexp, array $expressions) { try { $regexpId = $regexp['regexpid']; unset($regexp['regexpid']); // check existence if (!getRegexp($regexpId)) { throw new Exception(_('Regular expression does not exist.')); } // check required fields $dbFields = array('name' => null); if (!check_db_fields($dbFields, $regexp)) { throw new Exception(_('Incorrect arguments passed to function') . ' [updateRegexp]'); } // check duplicate name $dbRegexp = DBfetch(DBselect('SELECT re.regexpid' . ' FROM regexps re' . ' WHERE re.name=' . zbx_dbstr($regexp['name']) . andDbNode('re.regexpid'))); if ($dbRegexp && bccomp($regexpId, $dbRegexp['regexpid']) != 0) { throw new Exception(_s('Regular expression "%s" already exists.', $regexp['name'])); } rewriteRegexpExpressions($regexpId, $expressions); DB::update('regexps', array('values' => $regexp, 'where' => array('regexpid' => $regexpId))); } catch (Exception $e) { error($e->getMessage()); return false; } return true; }
/** * Check input. * * @param array $triggers * @param string $method */ public function checkInput(array &$triggers, $method) { $create = $method == 'create'; $update = $method == 'update'; // permissions if ($update) { $triggerDbFields = array('triggerid' => null); $dbTriggers = $this->get(array('triggerids' => zbx_objectValues($triggers, 'triggerid'), 'output' => API_OUTPUT_EXTEND, 'editable' => true, 'preservekeys' => true, 'selectDependencies' => API_OUTPUT_REFER)); $updateDiscoveredValidator = new CUpdateDiscoveredValidator(array('allowed' => array('triggerid', 'status'), 'messageAllowedField' => _('Cannot update "%1$s" for a discovered trigger.'))); foreach ($triggers as $trigger) { // check permissions if (!isset($dbTriggers[$trigger['triggerid']])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!')); } // discovered fields, except status, cannot be updated $this->checkPartialValidator($trigger, $updateDiscoveredValidator, $dbTriggers[$trigger['triggerid']]); } $triggers = $this->extendObjects($this->tableName(), $triggers, array('description')); } else { $triggerDbFields = array('description' => null, 'expression' => null, 'value' => TRIGGER_VALUE_FALSE); } foreach ($triggers as $tnum => &$trigger) { $currentTrigger = $triggers[$tnum]; $this->checkNoParameters($trigger, array('templateid', 'state', 'value', 'value_flag'), $update ? _('Cannot update "%1$s" for trigger "%2$s".') : _('Cannot set "%1$s" for trigger "%2$s".'), $trigger['description']); if (!check_db_fields($triggerDbFields, $trigger)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect fields for trigger.')); } $expressionChanged = true; if ($update) { $dbTrigger = $dbTriggers[$trigger['triggerid']]; if (isset($trigger['expression'])) { $expressionFull = explode_exp($dbTrigger['expression']); if (strcmp($trigger['expression'], $expressionFull) == 0) { $expressionChanged = false; } } if (isset($trigger['description']) && strcmp($trigger['description'], $dbTrigger['description']) == 0) { unset($trigger['description']); } } // if some of the properties are unchanged, no need to update them in DB // validating trigger expression if (isset($trigger['expression']) && $expressionChanged) { // expression permissions $expressionData = new CTriggerExpression(array('lldmacros' => false)); if (!$expressionData->parse($trigger['expression'])) { self::exception(ZBX_API_ERROR_PARAMETERS, $expressionData->error); } if (!isset($expressionData->expressions[0])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Trigger expression must contain at least one host:key reference.')); } $expressionHosts = $expressionData->getHosts(); $hosts = API::Host()->get(array('filter' => array('host' => $expressionHosts), 'editable' => true, 'output' => array('hostid', 'host', 'status'), 'templated_hosts' => true, 'preservekeys' => true)); $hosts = zbx_toHash($hosts, 'host'); $hostsStatusFlags = 0x0; foreach ($expressionHosts as $host) { if (!isset($hosts[$host])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect trigger expression. Host "%s" does not exist or you have no access to this host.', $host)); } // find out if both templates and hosts are referenced in expression $hostsStatusFlags |= $hosts[$host]['status'] == HOST_STATUS_TEMPLATE ? 0x1 : 0x2; if ($hostsStatusFlags == 0x3) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect trigger expression. Trigger expression elements should not belong to a template and a host simultaneously.')); } } foreach ($expressionData->expressions as $exprPart) { $sql = 'SELECT i.itemid,i.value_type' . ' FROM items i,hosts h' . ' WHERE i.key_=' . zbx_dbstr($exprPart['item']) . ' AND ' . dbConditionInt('i.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . ' AND h.host=' . zbx_dbstr($exprPart['host']) . ' AND h.hostid=i.hostid' . andDbNode('i.itemid'); if (!DBfetch(DBselect($sql))) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect item key "%1$s" provided for trigger expression on "%2$s".', $exprPart['item'], $exprPart['host'])); } } } // check existing $this->checkIfExistsOnHost($currentTrigger); } unset($trigger); }
if ($goResult) { $host = get_host_by_hostid($dbApplication['hostid']); add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_APPLICATION, 'Application [' . $dbApplication['name'] . '] from host [' . $host['host'] . ']'); } } $goResult = DBend($goResult); show_messages($goResult, _('Application deleted'), _('Cannot delete application')); clearCookies($goResult, $_REQUEST['hostid']); } elseif (str_in_array(getRequest('go'), array('activate', 'disable'))) { $result = true; $hostId = getRequest('hostid'); $enable = getRequest('go') == 'activate'; $updated = 0; DBstart(); foreach (getRequest('applications') as $id => $appid) { $dbItems = DBselect('SELECT ia.itemid,i.hostid,i.key_' . ' FROM items_applications ia' . ' LEFT JOIN items i ON ia.itemid=i.itemid' . ' WHERE ia.applicationid=' . zbx_dbstr($appid) . ' AND i.hostid=' . zbx_dbstr($hostId) . ' AND i.type<>' . ITEM_TYPE_HTTPTEST . andDbNode('ia.applicationid')); while ($item = DBfetch($dbItems)) { $result &= $enable ? activate_item($item['itemid']) : disable_item($item['itemid']); $updated++; } } $result = DBend($result); $messageSuccess = $enable ? _n('Item enabled', 'Items enabled', $updated) : _n('Item disabled', 'Items disabled', $updated); $messageFailed = $enable ? _n('Cannot enable item', 'Cannot enable items', $updated) : _n('Cannot disable item', 'Cannot disable items', $updated); show_messages($result, $messageSuccess, $messageFailed); clearCookies($result, $hostId); } /* * Display */ if (isset($_REQUEST['form'])) {
/** * Get items from expression. * * @param CTriggerExpression $triggerExpression * * @return array */ function getExpressionItems(CTriggerExpression $triggerExpression) { $items = array(); $processedFunctions = array(); $processedItems = array(); foreach ($triggerExpression->expressions as $expression) { if (isset($processedFunctions[$expression['expression']])) { continue; } if (!isset($processedItems[$expression['host']][$expression['item']])) { $dbItems = DBselect('SELECT i.itemid,i.flags' . ' FROM items i,hosts h' . ' WHERE i.key_=' . zbx_dbstr($expression['item']) . ' AND ' . dbConditionInt('i.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED, ZBX_FLAG_DISCOVERY_PROTOTYPE)) . ' AND h.host=' . zbx_dbstr($expression['host']) . ' AND h.hostid=i.hostid' . andDbNode('i.itemid')); if ($dbItem = DBfetch($dbItems)) { $items[] = $dbItem; $processedItems[$expression['host']][$expression['item']] = true; } } $processedFunctions[$expression['expression']] = true; } return $items; }
function get_status() { global $ZBX_SERVER, $ZBX_SERVER_PORT; $status = array('triggers_count' => 0, 'triggers_count_enabled' => 0, 'triggers_count_disabled' => 0, 'triggers_count_off' => 0, 'triggers_count_on' => 0, 'items_count' => 0, 'items_count_monitored' => 0, 'items_count_disabled' => 0, 'items_count_not_supported' => 0, 'hosts_count' => 0, 'hosts_count_monitored' => 0, 'hosts_count_not_monitored' => 0, 'hosts_count_template' => 0, 'users_online' => 0, 'qps_total' => 0); // server $zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, 0); $status['zabbix_server'] = $zabbixServer->isRunning() ? _('Yes') : _('No'); // triggers $dbTriggers = DBselect('SELECT COUNT(DISTINCT t.triggerid) AS cnt,t.status,t.value' . ' FROM triggers t' . ' INNER JOIN functions f ON t.triggerid=f.triggerid' . ' INNER JOIN items i ON f.itemid=i.itemid' . ' INNER JOIN hosts h ON i.hostid=h.hostid' . ' WHERE i.status=' . ITEM_STATUS_ACTIVE . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND t.flags IN (' . ZBX_FLAG_DISCOVERY_NORMAL . ',' . ZBX_FLAG_DISCOVERY_CREATED . ')' . ' GROUP BY t.status,t.value'); while ($dbTrigger = DBfetch($dbTriggers)) { switch ($dbTrigger['status']) { case TRIGGER_STATUS_ENABLED: switch ($dbTrigger['value']) { case TRIGGER_VALUE_FALSE: $status['triggers_count_off'] = $dbTrigger['cnt']; break; case TRIGGER_VALUE_TRUE: $status['triggers_count_on'] = $dbTrigger['cnt']; break; } break; case TRIGGER_STATUS_DISABLED: $status['triggers_count_disabled'] += $dbTrigger['cnt']; break; } } $status['triggers_count_enabled'] = $status['triggers_count_off'] + $status['triggers_count_on']; $status['triggers_count'] = $status['triggers_count_enabled'] + $status['triggers_count_disabled']; // items $dbItems = DBselect('SELECT COUNT(i.itemid) AS cnt,i.status,i.state' . ' FROM items i' . ' INNER JOIN hosts h ON i.hostid=h.hostid' . ' WHERE h.status=' . HOST_STATUS_MONITORED . ' AND i.flags IN (' . ZBX_FLAG_DISCOVERY_NORMAL . ',' . ZBX_FLAG_DISCOVERY_CREATED . ')' . ' AND i.type<>' . ITEM_TYPE_HTTPTEST . ' GROUP BY i.status,i.state'); while ($dbItem = DBfetch($dbItems)) { if ($dbItem['status'] == ITEM_STATUS_ACTIVE) { if ($dbItem['state'] == ITEM_STATE_NORMAL) { $status['items_count_monitored'] = $dbItem['cnt']; } else { $status['items_count_not_supported'] = $dbItem['cnt']; } } elseif ($dbItem['status'] == ITEM_STATUS_DISABLED) { $status['items_count_disabled'] += $dbItem['cnt']; } } $status['items_count'] = $status['items_count_monitored'] + $status['items_count_disabled'] + $status['items_count_not_supported']; // hosts $dbHosts = DBselect('SELECT COUNT(*) AS cnt,h.status' . ' FROM hosts h' . ' WHERE ' . dbConditionInt('h.status', array(HOST_STATUS_MONITORED, HOST_STATUS_NOT_MONITORED, HOST_STATUS_TEMPLATE)) . ' AND ' . dbConditionInt('h.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . ' GROUP BY h.status'); while ($dbHost = DBfetch($dbHosts)) { switch ($dbHost['status']) { case HOST_STATUS_MONITORED: $status['hosts_count_monitored'] = $dbHost['cnt']; break; case HOST_STATUS_NOT_MONITORED: $status['hosts_count_not_monitored'] = $dbHost['cnt']; break; case HOST_STATUS_TEMPLATE: $status['hosts_count_template'] = $dbHost['cnt']; break; } } $status['hosts_count'] = $status['hosts_count_monitored'] + $status['hosts_count_not_monitored'] + $status['hosts_count_template']; // users $row = DBfetch(DBselect('SELECT COUNT(*) AS usr_cnt' . ' FROM users u' . whereDbNode('u.userid'))); $status['users_count'] = $row['usr_cnt']; $status['users_online'] = 0; $db_sessions = DBselect('SELECT s.userid,s.status,MAX(s.lastaccess) AS lastaccess' . ' FROM sessions s' . ' WHERE s.status=' . ZBX_SESSION_ACTIVE . andDbNode('s.userid') . ' GROUP BY s.userid,s.status'); while ($session = DBfetch($db_sessions)) { if ($session['lastaccess'] + ZBX_USER_ONLINE_TIME >= time()) { $status['users_online']++; } } // comments: !!! Don't forget sync code with C !!! $row = DBfetch(DBselect('SELECT SUM(1.0/i.delay) AS qps' . ' FROM items i,hosts h' . ' WHERE i.status=' . ITEM_STATUS_ACTIVE . ' AND i.hostid=h.hostid' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.delay<>0')); $status['qps_total'] = round($row['qps'], 2); return $status; }
function get_actions_hint_by_eventid($eventid, $status = null) { $tab_hint = new CTableInfo(_('No actions found.')); $tab_hint->setAttribute('style', 'width: 300px;'); $tab_hint->setHeader(array(is_show_all_nodes() ? _('Nodes') : null, _('User'), _('Details'), _('Status'))); $sql = 'SELECT a.alertid,mt.description,u.alias,u.name,u.surname,a.subject,a.message,a.sendto,a.status,a.retries,a.alerttype' . ' FROM events e,alerts a' . ' LEFT JOIN users u ON u.userid=a.userid' . ' LEFT JOIN media_type mt ON mt.mediatypeid=a.mediatypeid' . ' WHERE a.eventid=' . zbx_dbstr($eventid) . (is_null($status) ? '' : ' AND a.status=' . $status) . ' AND e.eventid=a.eventid' . ' AND a.alerttype IN (' . ALERT_TYPE_MESSAGE . ',' . ALERT_TYPE_COMMAND . ')' . andDbNode('a.alertid') . ' ORDER BY a.alertid'; $result = DBselect($sql, 30); while ($row = DBfetch($result)) { if ($row['status'] == ALERT_STATUS_SENT) { $status = new CSpan(_('Sent'), 'green'); } elseif ($row['status'] == ALERT_STATUS_NOT_SENT) { $status = new CSpan(_('In progress'), 'orange'); } else { $status = new CSpan(_('not sent'), 'red'); } switch ($row['alerttype']) { case ALERT_TYPE_MESSAGE: $message = empty($row['description']) ? '-' : $row['description']; break; case ALERT_TYPE_COMMAND: $message = array(bold(_('Command') . NAME_DELIMITER)); $msg = explode("\n", $row['message']); foreach ($msg as $m) { array_push($message, BR(), $m); } break; default: $message = '-'; } if (!$row['alias']) { $row['alias'] = ' - '; } else { $fullname = ''; if ($row['name']) { $fullname = $row['name']; } if ($row['surname']) { $fullname .= $fullname ? ' ' . $row['surname'] : $row['surname']; } if ($fullname) { $row['alias'] .= ' (' . $fullname . ')'; } } $tab_hint->addRow(array(get_node_name_by_elid($row['alertid']), $row['alias'], $message, $status)); } return $tab_hint; }
$columns[$col][] = $lastiss; } // web monitoring $refresh_menu = get_icon('menu', array('menu' => 'hat_webovr')); $web_mon = new CUIWidget('hat_webovr', new CSpan(_('Loading...'), 'textcolorstyles'), CProfile::get('web.dashboard.widget.webovr.state', 1)); $web_mon->setHeader(_('Web monitoring'), array($refresh_menu)); $web_mon->setFooter(new CDiv(SPACE, 'textwhite', 'hat_webovr_footer')); $col = CProfile::get('web.dashboard.widget.webovr.col', '1'); $row = CProfile::get('web.dashboard.widget.webovr.row', '4'); if (!isset($columns[$col][$row])) { $columns[$col][$row] = $web_mon; } else { $columns[$col][] = $web_mon; } // discovery info $drules = DBfetch(DBselect('SELECT COUNT(d.druleid) AS cnt' . ' FROM drules d' . ' WHERE d.status=' . DRULE_STATUS_ACTIVE . andDbNode('d.druleid'))); if ($drules['cnt'] > 0 && check_right_on_discovery()) { $refresh_tab[] = array('id' => 'hat_dscvry', 'frequency' => CProfile::get('web.dashboard.widget.dscvry.rf_rate', 60)); $refresh_menu = get_icon('menu', array('menu' => 'hat_dscvry')); $dcvr_mon = new CUIWidget('hat_dscvry', new CSpan(_('Loading...'), 'textcolorstyles'), CProfile::get('web.dashboard.widget.dscvry.state', 1)); $dcvr_mon->setHeader(_('Discovery status'), array($refresh_menu)); $dcvr_mon->setFooter(new CDiv(SPACE, 'textwhite', 'hat_dscvry_footer')); $col = CProfile::get('web.dashboard.widget.dscvry.col', '1'); $row = CProfile::get('web.dashboard.widget.dscvry.row', '5'); if (!isset($columns[$col][$row])) { $columns[$col][$row] = $dcvr_mon; } else { $columns[$col][] = $dcvr_mon; } } add_doll_objects($refresh_tab);
private static function updateDB($idx, $value, $type, $idx2) { $sql_cond = ''; if ($idx != 'web.nodes.switch_node') { $sql_cond .= andDbNode('profileid', false); } if ($idx2 > 0) { $sql_cond .= ' AND idx2=' . $idx2 . andDbNode('idx2', false); } $value_type = self::getFieldByType($type); return DBexecute('UPDATE profiles SET ' . $value_type . '=' . zbx_dbstr($value) . ',' . ' type=' . $type . ' WHERE userid=' . self::$userDetails['userid'] . ' AND idx=' . zbx_dbstr($idx) . $sql_cond); }
/** * Check if session id is authenticated. * * @param string $sessionid session id * * @return array an array of user data */ public function checkAuthentication($sessionid) { global $ZBX_LOCALNODEID; // access DB only once per page load if (!is_null(self::$userData)) { return self::$userData; } $time = time(); $userInfo = DBfetch(DBselect('SELECT u.userid,u.autologout,s.lastaccess' . ' FROM sessions s,users u' . ' WHERE s.sessionid=' . zbx_dbstr($sessionid) . ' AND s.status=' . ZBX_SESSION_ACTIVE . ' AND s.userid=u.userid' . ' AND (s.lastaccess+u.autologout>' . $time . ' OR u.autologout=0)' . andDbNode('u.userid', $ZBX_LOCALNODEID))); if (!$userInfo) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Session terminated, re-login, please.')); } // don't check permissions on the same second if ($time != $userInfo['lastaccess']) { if (!check_perm2system($userInfo['userid'])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions for system access.')); } if ($userInfo['autologout'] > 0) { DBexecute('DELETE FROM sessions WHERE userid=' . $userInfo['userid'] . ' AND lastaccess<' . (time() - $userInfo['autologout'])); } DBexecute('UPDATE sessions SET lastaccess=' . time() . ' WHERE userid=' . $userInfo['userid'] . ' AND sessionid=' . zbx_dbstr($sessionid)); } $dbAccess = DBfetch(DBselect('SELECT MAX(g.gui_access) AS gui_access' . ' FROM usrgrp g,users_groups ug' . ' WHERE ug.userid=' . $userInfo['userid'] . ' AND g.usrgrpid=ug.usrgrpid')); if (!zbx_empty($dbAccess['gui_access'])) { $guiAccess = $dbAccess['gui_access']; } else { $guiAccess = GROUP_GUI_ACCESS_SYSTEM; } $userData = $this->_getUserData($userInfo['userid']); $userData['sessionid'] = $sessionid; $userData['gui_access'] = $guiAccess; CWebUser::$data = self::$userData = $userData; return $userData; }
$regExpWidget->addPageHeader(_('CONFIGURATION OF REGULAR EXPRESSIONS'), $regExpForm); if (isset($_REQUEST['form'])) { $data = array('form_refresh' => get_request('form_refresh'), 'regexpid' => get_request('regexpid')); if (isset($_REQUEST['regexpid']) && !isset($_REQUEST['form_refresh'])) { $regExp = DBfetch(DBSelect('SELECT re.name,re.test_string' . ' FROM regexps re' . ' WHERE re.regexpid=' . zbx_dbstr($_REQUEST['regexpid']) . andDbNode('re.regexpid'))); $data['name'] = $regExp['name']; $data['test_string'] = $regExp['test_string']; $dbExpressions = DBselect('SELECT e.expressionid,e.expression,e.expression_type,e.exp_delimiter,e.case_sensitive' . ' FROM expressions e' . ' WHERE e.regexpid=' . zbx_dbstr($_REQUEST['regexpid']) . andDbNode('e.expressionid') . ' ORDER BY e.expression_type'); $data['expressions'] = DBfetchArray($dbExpressions); } else { $data['name'] = get_request('name', ''); $data['test_string'] = get_request('test_string', ''); $data['expressions'] = get_request('expressions', array()); } $regExpForm = new CView('administration.general.regularexpressions.edit', $data); } else { $data = array('displayNodes' => is_array(get_current_nodeid()), 'cnf_wdgt' => &$regExpWidget, 'regexps' => array(), 'regexpids' => array()); $dbRegExp = DBselect('SELECT re.* FROM regexps re ' . whereDbNode('re.regexpid')); while ($regExp = DBfetch($dbRegExp)) { $regExp['expressions'] = array(); $regExp['nodename'] = $data['displayNodes'] ? get_node_name_by_elid($regExp['regexpid'], true) : ''; $data['regexps'][$regExp['regexpid']] = $regExp; $data['regexpids'][$regExp['regexpid']] = $regExp['regexpid']; } order_result($data['regexps'], 'name'); $data['db_exps'] = DBfetchArray(DBselect('SELECT e.*' . ' FROM expressions e' . ' WHERE ' . dbConditionInt('e.regexpid', $data['regexpids']) . andDbNode('e.expressionid') . ' ORDER BY e.expression_type')); $regExpForm = new CView('administration.general.regularexpressions.list', $data); } $regExpWidget->addItem($regExpForm->render()); $regExpWidget->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
$dbTrigger = API::Trigger()->get(array('triggerids' => $linkTrigger['triggerid'], 'output' => array('description', 'expression'), 'selectHosts' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'expandDescription' => true)); $dbTrigger = reset($dbTrigger); $host = reset($dbTrigger['hosts']); $link['linktriggers'][$lnum]['desc_exp'] = $host['name'] . NAME_DELIMITER . $dbTrigger['description']; } order_result($link['linktriggers'], 'desc_exp'); } unset($link); // get iconmapping if ($data['sysmap']['iconmapid']) { $iconMap = API::IconMap()->get(array('iconmapids' => $data['sysmap']['iconmapid'], 'output' => array('default_iconid'), 'preservekeys' => true)); $iconMap = reset($iconMap); $data['defaultAutoIconId'] = $iconMap['default_iconid']; } // get icon list $icons = DBselect('SELECT i.imageid,i.name' . ' FROM images i' . ' WHERE i.imagetype=' . IMAGE_TYPE_ICON . andDbNode('i.imageid')); while ($icon = DBfetch($icons)) { $data['iconList'][] = array('imageid' => $icon['imageid'], 'name' => $icon['name']); if ($icon['name'] == MAP_DEFAULT_ICON || !isset($data['defaultIconId'])) { $data['defaultIconId'] = $icon['imageid']; $data['defaultIconName'] = $icon['name']; } } if ($data['iconList']) { CArrayHelper::sort($data['iconList'], array('name')); $data['iconList'] = array_values($data['iconList']); } // render view $sysmapView = new CView('configuration.sysmap.constructor', $data); $sysmapView->render(); $sysmapView->show();
/** * Get scripts data. * * @param array $options * @param array $options['itemids'] * @param array $options['hostids'] deprecated (very slow) * @param array $options['groupids'] * @param array $options['triggerids'] * @param array $options['scriptids'] * @param bool $options['status'] * @param bool $options['editable'] * @param bool $options['count'] * @param string $options['pattern'] * @param int $options['limit'] * @param string $options['order'] * * @return array */ public function get(array $options) { $result = array(); $userType = self::$userData['type']; $userid = self::$userData['userid']; $sqlParts = array('select' => array('scripts' => 's.scriptid'), 'from' => array('scripts s'), 'where' => array(), 'order' => array(), 'limit' => null); $defOptions = array('nodeids' => null, 'groupids' => null, 'hostids' => null, 'scriptids' => null, 'usrgrpids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectGroups' => null, 'selectHosts' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null); $options = zbx_array_merge($defOptions, $options); // editable + permission check if ($userType != USER_TYPE_SUPER_ADMIN) { if (!is_null($options['editable'])) { return $result; } $userGroups = getUserGroupsByUserId($userid); $sqlParts['where'][] = '(s.usrgrpid IS NULL OR ' . dbConditionInt('s.usrgrpid', $userGroups) . ')'; $sqlParts['where'][] = '(s.groupid IS NULL OR EXISTS (' . 'SELECT NULL' . ' FROM rights r' . ' WHERE s.groupid=r.id' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' GROUP BY r.id' . ' HAVING MIN(r.permission)>' . PERM_DENY . '))'; } // groupids if (!is_null($options['groupids'])) { zbx_value2array($options['groupids']); $sqlParts['where'][] = '(s.groupid IS NULL OR ' . dbConditionInt('s.groupid', $options['groupids']) . ')'; } // hostids if (!is_null($options['hostids'])) { zbx_value2array($options['hostids']); // only fetch scripts from the same nodes as the hosts $hostNodeIds = array(); foreach ($options['hostids'] as $hostId) { $hostNodeIds[] = id2nodeid($hostId); } $hostNodeIds = array_unique($hostNodeIds); // return scripts that are assigned to the hosts' groups or to no group $hostGroups = API::HostGroup()->get(array('output' => array('groupid'), 'hostids' => $options['hostids'], 'nodeids' => $hostNodeIds)); $hostGroupIds = zbx_objectValues($hostGroups, 'groupid'); $sqlParts['where'][] = '(' . dbConditionInt('s.groupid', $hostGroupIds) . ' OR ' . '(s.groupid IS NULL' . andDbNode('s.scriptid', $hostNodeIds) . '))'; } // usrgrpids if (!is_null($options['usrgrpids'])) { zbx_value2array($options['usrgrpids']); $sqlParts['where'][] = '(s.usrgrpid IS NULL OR ' . dbConditionInt('s.usrgrpid', $options['usrgrpids']) . ')'; } // scriptids if (!is_null($options['scriptids'])) { zbx_value2array($options['scriptids']); $sqlParts['where'][] = dbConditionInt('s.scriptid', $options['scriptids']); } // search if (is_array($options['search'])) { zbx_db_search('scripts s', $options, $sqlParts); } // filter if (is_array($options['filter'])) { $this->dbFilter('scripts s', $options, $sqlParts); } // limit if (zbx_ctype_digit($options['limit']) && $options['limit']) { $sqlParts['limit'] = $options['limit']; } $sqlParts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts); $sqlParts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts); $sqlParts = $this->applyQueryNodeOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts); $res = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']); while ($script = DBfetch($res)) { if ($options['countOutput']) { $result = $script['rowscount']; } else { $result[$script['scriptid']] = $script; } } if (!is_null($options['countOutput'])) { return $result; } if ($result) { $result = $this->addRelatedObjects($options, $result); $result = $this->unsetExtraFields($result, array('groupid', 'host_access'), $options['output']); } // removing keys (hash -> array) if (is_null($options['preservekeys'])) { $result = zbx_cleanHashes($result); } return $result; }
/** * Get users ids by groups ids. * * @param array $userGroupIds * * @return array */ function get_userid_by_usrgrpid($userGroupIds) { zbx_value2array($userGroupIds); $userIds = array(); $dbUsers = DBselect('SELECT DISTINCT u.userid' . ' FROM users u,users_groups ug' . ' WHERE u.userid=ug.userid' . ' AND ' . dbConditionInt('ug.usrgrpid', $userGroupIds) . andDbNode('ug.usrgrpid', false)); while ($user = DBFetch($dbUsers)) { $userIds[$user['userid']] = $user['userid']; } return $userIds; }
// filter template $templateComboBox = new CComboBox('filter_hostid', $_REQUEST['filter_hostid'], 'javascript: submit();'); $templateComboBox->addItem(0, _('all')); $templates = API::Template()->get(array('output' => array('templateid', 'name'), 'groupids' => empty($_REQUEST['filter_groupid']) ? null : $_REQUEST['filter_groupid'], 'with_triggers' => true)); order_result($templates, 'name'); $templateIds = array(); foreach ($templates as $template) { $templateIds[$template['templateid']] = $template['templateid']; $templateComboBox->addItem($template['templateid'], get_node_name_by_elid($template['templateid'], null, NAME_DELIMITER) . $template['name']); } $filterForm->addRow(_('Template'), $templateComboBox); // filter trigger $triggerComboBox = new CComboBox('tpl_triggerid', get_request('tpl_triggerid', 0), 'javascript: submit()'); $triggerComboBox->addItem(0, _('all')); $sqlCondition = empty($_REQUEST['filter_hostid']) ? ' AND ' . dbConditionInt('h.hostid', $templateIds) : ' AND h.hostid=' . zbx_dbstr($_REQUEST['filter_hostid']); $sql = 'SELECT DISTINCT t.triggerid,t.description,h.name' . ' FROM triggers t,hosts h,items i,functions f' . ' WHERE f.itemid=i.itemid' . ' AND h.hostid=i.hostid' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND t.triggerid=f.triggerid' . ' AND h.status=' . HOST_STATUS_TEMPLATE . ' AND i.status=' . ITEM_STATUS_ACTIVE . $sqlCondition . andDbNode('t.triggerid') . ' ORDER BY t.description'; $triggers = DBfetchArrayAssoc(DBselect($sql), 'triggerid'); foreach ($triggers as $trigger) { $templateName = empty($_REQUEST['filter_hostid']) ? $trigger['name'] . NAME_DELIMITER : ''; $triggerComboBox->addItem($trigger['triggerid'], get_node_name_by_elid($trigger['triggerid'], null, NAME_DELIMITER) . $templateName . $trigger['description']); } if (isset($_REQUEST['tpl_triggerid']) && !isset($triggers[$_REQUEST['tpl_triggerid']])) { unset($triggerOptions['filter']['templateid']); } $filterForm->addRow(_('Template trigger'), $triggerComboBox); // filter host group $hostGroupsComboBox = new CComboBox('hostgroupid', get_request('hostgroupid', 0), 'javascript: submit()'); $hostGroupsComboBox->addItem(0, _('all')); $hostGroups = API::HostGroup()->get(array('output' => array('groupid', 'name'), 'hostids' => $triggerOptions['hostids'], 'monitored_hosts' => true, 'preservekeys' => true)); order_result($hostGroups, 'name'); foreach ($hostGroups as $hostGroup) {
updateValueMap($valueMap, $mappings); } else { $msgOk = _('Value map added'); $msgFail = _('Cannot add value map'); $audit_action = AUDIT_ACTION_ADD; addValueMap($valueMap, $mappings); } add_audit($audit_action, AUDIT_RESOURCE_VALUE_MAP, _s('Value map "%1$s".', $valueMap['name'])); show_messages(true, $msgOk); unset($_REQUEST['form']); DBend(true); } elseif (isset($_REQUEST['delete']) && isset($_REQUEST['valuemapid'])) { DBstart(); $msgOk = _('Value map deleted'); $msgFail = _('Cannot delete value map'); $sql = 'SELECT v.name,v.valuemapid' . ' FROM valuemaps v' . ' WHERE v.valuemapid=' . zbx_dbstr($_REQUEST['valuemapid']) . andDbNode('v.valuemapid'); if ($valueMapToDelete = DBfetch(DBselect($sql))) { deleteValueMap($_REQUEST['valuemapid']); } else { throw new Exception(_s('Value map with valuemapid "%1$s" does not exist.', $_REQUEST['valuemapid'])); } add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_VALUE_MAP, _s('Value map "%1$s" "%2$s".', $valueMapToDelete['name'], $valueMapToDelete['valuemapid'])); show_messages(true, $msgOk); unset($_REQUEST['form']); DBend(true); } } catch (Exception $e) { DBend(false); error($e->getMessage()); show_messages(false, null, $msgFail); }
/** * Returns the host groups that are accessible by the current user with the permission level given in $perm. * * Can return results in different formats, based on the $per_res parameter. Possible values are: * - PERM_RES_IDS_ARRAY - return only host group ids; * - PERM_RES_DATA_ARRAY - return an array of host groups. * * @param array $userData an array defined as array('userid' => userid, 'type' => type) * @param int $perm requested permission level * @param int|null $permRes result format * @param int $nodeId * * @return array */ function get_accessible_groups_by_user($userData, $perm, $permRes = PERM_RES_IDS_ARRAY, $nodeId = null) { $userId =& $userData['userid']; if (!isset($userId)) { fatal_error(_('Incorrect user data in "get_accessible_groups_by_user".')); } if (is_null($nodeId)) { $nodeId = get_current_nodeid(); } $userType =& $userData['type']; $result = array(); $processed = array(); if ($userType == USER_TYPE_SUPER_ADMIN) { $sql = 'SELECT n.nodeid AS nodeid,n.name AS node_name,hg.groupid,hg.name' . ' FROM groups hg' . ' LEFT JOIN nodes n ON ' . DBid2nodeid('hg.groupid') . '=n.nodeid' . whereDbNode('hg.groupid', $nodeId) . ' GROUP BY n.nodeid,n.name,hg.groupid,hg.name'; } else { $sql = 'SELECT n.nodeid AS nodeid,n.name AS node_name,hg.groupid,hg.name,MAX(r.permission) AS permission,MIN(r.permission) AS permission_deny,g.userid' . ' FROM groups hg' . ' LEFT JOIN rights r ON r.id=hg.groupid' . ' LEFT JOIN users_groups g ON r.groupid=g.usrgrpid' . ' LEFT JOIN nodes n ON ' . DBid2nodeid('hg.groupid') . '=n.nodeid' . ' WHERE g.userid=' . zbx_dbstr($userId) . andDbNode('hg.groupid', $nodeId) . ' GROUP BY n.nodeid,n.name,hg.groupid,hg.name,g.userid'; } $dbGroups = DBselect($sql); while ($groupData = DBfetch($dbGroups)) { if (zbx_empty($groupData['nodeid'])) { $groupData['nodeid'] = id2nodeid($groupData['groupid']); } // calculate permissions if ($userType == USER_TYPE_SUPER_ADMIN) { $groupData['permission'] = PERM_READ_WRITE; } elseif (isset($processed[$groupData['groupid']])) { if ($groupData['permission_deny'] == PERM_DENY) { unset($result[$groupData['groupid']]); } elseif ($processed[$groupData['groupid']] > $groupData['permission']) { unset($processed[$groupData['groupid']]); } else { continue; } } $processed[$groupData['groupid']] = $groupData['permission']; if ($groupData['permission'] < $perm) { continue; } switch ($permRes) { case PERM_RES_DATA_ARRAY: $result[$groupData['groupid']] = $groupData; break; default: $result[$groupData['groupid']] = $groupData['groupid']; break; } } unset($processed, $groupData, $dbGroups); if ($userType == USER_TYPE_SUPER_ADMIN) { CArrayHelper::sort($result, array(array('field' => 'node_name', 'order' => ZBX_SORT_UP), array('field' => 'name', 'order' => ZBX_SORT_UP))); } else { CArrayHelper::sort($result, array(array('field' => 'node_name', 'order' => ZBX_SORT_UP), array('field' => 'name', 'order' => ZBX_SORT_UP), array('field' => 'permission', 'order' => ZBX_SORT_UP))); } return $result; }
} } else { $data['name'] = get_request('gname', ''); $data['users_status'] = get_request('users_status', GROUP_STATUS_ENABLED); $data['gui_access'] = get_request('gui_access', GROUP_GUI_ACCESS_SYSTEM); $data['debug_mode'] = get_request('debug_mode', GROUP_DEBUG_MODE_DISABLED); $data['group_users'] = get_request('group_users', array()); $data['group_rights'] = get_request('group_rights', array()); } $data['selected_usrgrp'] = get_request('selusrgrp', 0); // sort group rights order_result($data['group_rights'], 'name'); // get users if ($data['selected_usrgrp'] > 0) { $sqlFrom = ',users_groups g'; $sqlWhere = ' WHERE ' . dbConditionInt('u.userid', $data['group_users']) . ' OR (u.userid=g.userid AND g.usrgrpid=' . zbx_dbstr($data['selected_usrgrp']) . andDbNode('u.userid') . ')'; } else { $sqlFrom = ''; $sqlWhere = whereDbNode('u.userid'); } $data['users'] = DBfetchArray(DBselect('SELECT DISTINCT u.userid,u.alias,u.name,u.surname' . ' FROM users u' . $sqlFrom . $sqlWhere)); order_result($data['users'], 'alias'); // get user groups $data['usergroups'] = DBfetchArray(DBselect('SELECT ug.usrgrpid,ug.name' . ' FROM usrgrp ug' . whereDbNode('usrgrpid'))); order_result($data['usergroups'], 'name'); // render view $userGroupsView = new CView('administration.usergroups.edit', $data); $userGroupsView->render(); $userGroupsView->show(); } else { $data = array('displayNodes' => is_array(get_current_nodeid()));
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $sortfield = 'clock'; $sortorder = ZBX_SORT_DOWN; $sorttitle = _('Time'); switch ($this->screenitem['sort_triggers']) { case SCREEN_SORT_TRIGGERS_TIME_ASC: $sortfield = 'clock'; $sortorder = ZBX_SORT_UP; $sorttitle = _('Time'); break; case SCREEN_SORT_TRIGGERS_TIME_DESC: $sortfield = 'clock'; $sortorder = ZBX_SORT_DOWN; $sorttitle = _('Time'); break; case SCREEN_SORT_TRIGGERS_TYPE_ASC: $sortfield = 'description'; $sortorder = ZBX_SORT_UP; $sorttitle = _('Type'); break; case SCREEN_SORT_TRIGGERS_TYPE_DESC: $sortfield = 'description'; $sortorder = ZBX_SORT_DOWN; $sorttitle = _('Type'); break; case SCREEN_SORT_TRIGGERS_STATUS_ASC: $sortfield = 'status'; $sortorder = ZBX_SORT_UP; $sorttitle = _('Status'); break; case SCREEN_SORT_TRIGGERS_STATUS_DESC: $sortfield = 'status'; $sortorder = ZBX_SORT_DOWN; $sorttitle = _('Status'); break; case SCREEN_SORT_TRIGGERS_RETRIES_LEFT_ASC: $sortfield = 'retries'; $sortorder = ZBX_SORT_UP; $sorttitle = _('Retries left'); break; case SCREEN_SORT_TRIGGERS_RETRIES_LEFT_DESC: $sortfield = 'retries'; $sortorder = ZBX_SORT_DOWN; $sorttitle = _('Retries left'); break; case SCREEN_SORT_TRIGGERS_RECIPIENT_ASC: $sortfield = 'sendto'; $sortorder = ZBX_SORT_UP; $sorttitle = _('Recipient(s)'); break; case SCREEN_SORT_TRIGGERS_RECIPIENT_DESC: $sortfield = 'sendto'; $sortorder = ZBX_SORT_DOWN; $sorttitle = _('Recipient(s)'); break; } $sql = 'SELECT a.alertid,a.clock,mt.description,a.sendto,a.subject,a.message,a.status,a.retries,a.error' . ' FROM events e,alerts a' . ' LEFT JOIN media_type mt ON mt.mediatypeid=a.mediatypeid' . ' WHERE e.eventid=a.eventid' . ' AND alerttype=' . ALERT_TYPE_MESSAGE . andDbNode('a.alertid'); if (CWebUser::getType() != USER_TYPE_SUPER_ADMIN) { $userid = CWebUser::$data['userid']; $userGroups = getUserGroupsByUserId($userid); $sql .= ' AND EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE e.objectid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY f.triggerid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ')'; } $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder; $alerts = DBfetchArray(DBselect($sql, $this->screenitem['elements'])); order_result($alerts, $sortfield, $sortorder); // indicator of sort field $sortfieldSpan = new CSpan(array($sorttitle, SPACE)); $sortorderSpan = new CSpan(SPACE, $sortorder == ZBX_SORT_DOWN ? 'icon_sortdown default_cursor' : 'icon_sortup default_cursor'); // create alert table $actionTable = new CTableInfo(_('No actions found.')); $actionTable->setHeader(array(is_show_all_nodes() ? _('Nodes') : null, $sortfield == 'clock' ? array($sortfieldSpan, $sortorderSpan) : _('Time'), $sortfield == 'description' ? array($sortfieldSpan, $sortorderSpan) : _('Type'), $sortfield == 'status' ? array($sortfieldSpan, $sortorderSpan) : _('Status'), $sortfield == 'retries' ? array($sortfieldSpan, $sortorderSpan) : _('Retries left'), $sortfield == 'sendto' ? array($sortfieldSpan, $sortorderSpan) : _('Recipient(s)'), _('Message'), _('Error'))); foreach ($alerts as $alert) { if ($alert['status'] == ALERT_STATUS_SENT) { $status = new CSpan(_('sent'), 'green'); $retries = new CSpan(SPACE, 'green'); } elseif ($alert['status'] == ALERT_STATUS_NOT_SENT) { $status = new CSpan(_('In progress'), 'orange'); $retries = new CSpan(ALERT_MAX_RETRIES - $alert['retries'], 'orange'); } else { $status = new CSpan(_('not sent'), 'red'); $retries = new CSpan(0, 'red'); } $message = array(bold(_('Subject') . NAME_DELIMITER), br(), $alert['subject'], br(), br(), bold(_('Message') . NAME_DELIMITER), br(), $alert['message']); $error = empty($alert['error']) ? new CSpan(SPACE, 'off') : new CSpan($alert['error'], 'on'); $actionTable->addRow(array(get_node_name_by_elid($alert['alertid']), new CCol(zbx_date2str(HISTORY_OF_ACTIONS_DATE_FORMAT, $alert['clock']), 'top'), new CCol(!empty($alert['description']) ? $alert['description'] : '-', 'top'), new CCol($status, 'top'), new CCol($retries, 'top'), new CCol($alert['sendto'], 'top'), new CCol($message, 'top pre'), new CCol($error, 'wraptext top'))); } return $this->getOutput($actionTable); }
/** * Get UserGroup ID by UserGroup name. * * @param array $groupData * @return string|boolean */ public function getObjects($groupData) { $result = array(); $usrgrpids = array(); $res = DBselect('SELECT g.usrgrpid' . ' FROM usrgrp g' . ' WHERE g.name=' . zbx_dbstr($groupData['name']) . andDbNode('g.usrgrpid', false)); while ($group = DBfetch($res)) { $usrgrpids[$group['usrgrpid']] = $group['usrgrpid']; } if (!empty($usrgrpids)) { $result = $this->get(array('usrgrpids' => $usrgrpids, 'output' => API_OUTPUT_EXTEND)); } return $result; }
$table->setHeader(_('Name')); $dRules = API::DRule()->get(array('selectDChecks' => array('dcheckid', 'type', 'key_', 'ports'), 'output' => array('name'), 'nodeids' => $nodeId)); foreach ($dRules as $dRule) { foreach ($dRule['dchecks'] as $dCheck) { $name = $dRule['name'] . NAME_DELIMITER . discovery_check2str($dCheck['type'], $dCheck['key_'], $dCheck['ports']); $action = get_window_opener($dstfrm, $dstfld1, $dCheck[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $name) : ''); $name = new CSpan($name, 'link'); $name->setAttribute('onclick', $action . ' close_window(); return false;'); $table->addRow($name); } } $table->show(); } elseif ($srctbl == 'proxies') { $table = new CTableInfo(_('No proxies found.')); $table->setHeader(_('Name')); $result = DBselect('SELECT h.hostid,h.host' . ' FROM hosts h' . ' WHERE h.status IN (' . HOST_STATUS_PROXY_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ')' . andDbNode('h.hostid', $nodeId) . ' ORDER BY h.host,h.hostid'); while ($row = DBfetch($result)) { $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : ''); $name = new CSpan($row['host'], 'link'); $name->setAttribute('onclick', $action . ' close_window(); return false;'); $table->addRow($name); } $table->show(); } elseif ($srctbl == 'scripts') { $form = new CForm(); $form->setName('scriptform'); $form->attr('id', 'scripts'); $table = new CTableInfo(_('No scripts found.')); if ($multiselect) { $header = array(array(new CCheckBox('all_scripts', null, "javascript: checkAll('" . $form->getName() . "', 'all_scripts', 'scripts');"), _('Name')), _('Execute on'), _('Commands')); } else {
* Display */ $hostsWidget = new CWidget(); $pageFilter = new CPageFilter(array('groups' => array('real_hosts' => true, 'editable' => true), 'groupid' => get_request('groupid', null))); $_REQUEST['groupid'] = $pageFilter->groupid; $_REQUEST['hostid'] = get_request('hostid', 0); if ($_REQUEST['go'] == 'massupdate' && isset($_REQUEST['hosts'])) { $hostsWidget->addPageHeader(_('CONFIGURATION OF HOSTS')); $data = array('hosts' => get_request('hosts', array()), 'visible' => get_request('visible', array()), 'mass_replace_tpls' => get_request('mass_replace_tpls'), 'mass_clear_tpls' => get_request('mass_clear_tpls'), 'groups' => get_request('groups', array()), 'newgroup' => get_request('newgroup', ''), 'status' => get_request('status', HOST_STATUS_MONITORED), 'proxy_hostid' => get_request('proxy_hostid', ''), 'ipmi_authtype' => get_request('ipmi_authtype', -1), 'ipmi_privilege' => get_request('ipmi_privilege', 2), 'ipmi_username' => get_request('ipmi_username', ''), 'ipmi_password' => get_request('ipmi_password', ''), 'inventory_mode' => get_request('inventory_mode', HOST_INVENTORY_DISABLED), 'host_inventory' => get_request('host_inventory', array()), 'templates' => get_request('templates', array())); // sort templates natsort($data['templates']); // get groups $data['all_groups'] = API::HostGroup()->get(array('output' => API_OUTPUT_EXTEND, 'editable' => true)); order_result($data['all_groups'], 'name'); // get proxies $data['proxies'] = DBfetchArray(DBselect('SELECT h.hostid,h.host' . ' FROM hosts h' . ' WHERE h.status IN (' . HOST_STATUS_PROXY_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ')' . andDbNode('h.hostid'))); order_result($data['proxies'], 'host'); // get inventories if ($data['inventory_mode'] != HOST_INVENTORY_DISABLED) { $data['inventories'] = getHostInventories(); $data['inventories'] = zbx_toHash($data['inventories'], 'db_field'); } // get templates data $data['linkedTemplates'] = null; if (!empty($data['templates'])) { $getLinkedTemplates = API::Template()->get(array('templateids' => $data['templates'], 'output' => array('templateid', 'name'))); foreach ($getLinkedTemplates as $getLinkedTemplate) { $data['linkedTemplates'][] = array('id' => $getLinkedTemplate['templateid'], 'name' => $getLinkedTemplate['name']); } } $hostForm = new CView('configuration.host.massupdate', $data);
// proxy if (!empty($data['proxyid'])) { $dbProxy = reset($dbProxy); if (!isset($_REQUEST['form_refresh'])) { $data['name'] = $dbProxy['host']; $data['status'] = $dbProxy['status']; $data['interface'] = $dbProxy['interface']; $data['hosts'] = zbx_objectValues($dbProxy['hosts'], 'hostid'); } } // interface if ($data['status'] == HOST_STATUS_PROXY_PASSIVE && empty($data['interface'])) { $data['interface'] = array('dns' => 'localhost', 'ip' => '127.0.0.1', 'useip' => 1, 'port' => '10051'); } // fetch available hosts, skip host prototypes $data['dbHosts'] = DBfetchArray(DBselect('SELECT h.hostid,h.proxy_hostid,h.name,h.flags' . ' FROM hosts h' . ' WHERE h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . andDbNode('h.hostid') . ' AND h.flags<>' . ZBX_FLAG_DISCOVERY_PROTOTYPE)); order_result($data['dbHosts'], 'name'); // render view $proxyView = new CView('administration.proxy.edit', $data); $proxyView->render(); $proxyView->show(); } else { $data = array('displayNodes' => is_array(get_current_nodeid()), 'config' => select_config()); $sortfield = getPageSortField('host'); $data['proxies'] = API::Proxy()->get(array('editable' => true, 'selectHosts' => array('hostid', 'host', 'name', 'status'), 'output' => API_OUTPUT_EXTEND, 'sortfield' => $sortfield, 'limit' => $config['search_limit'] + 1)); $data['proxies'] = zbx_toHash($data['proxies'], 'proxyid'); $proxyIds = array_keys($data['proxies']); // sorting & paging order_result($data['proxies'], $sortfield, getPageSortOrder()); $data['paging'] = getPagingLine($data['proxies'], array('proxyid')); // nodes
function check_dynamic_items($elid, $config = 0) { if ($config == 0) { $sql = 'SELECT si.screenitemid' . ' FROM screens_items si' . ' WHERE si.screenid=' . zbx_dbstr($elid) . ' AND si.dynamic=' . SCREEN_DYNAMIC_ITEM . ' ' . andDbNode('si.screenitemid'); } else { $sql = 'SELECT si.screenitemid' . ' FROM slides s,screens_items si' . ' WHERE s.slideshowid=' . zbx_dbstr($elid) . ' AND si.screenid=s.screenid' . ' AND si.dynamic=' . SCREEN_DYNAMIC_ITEM . ' ' . andDbNode('si.screenitemid'); } if (DBfetch(DBselect($sql, 1))) { return true; } return false; }
/** * Get mapping for value. * If there is no mapping return false. * * @param string $value value that mapping should be applied to * @param int $valueMapId value map id which should be used * * @return string|bool */ function getMappedValue($value, $valueMapId) { static $valueMaps = array(); if ($valueMapId < 1) { return false; } if (isset($valueMaps[$valueMapId][$value])) { return $valueMaps[$valueMapId][$value]; } $dbMappings = DBselect('SELECT m.newvalue' . ' FROM mappings m' . ' WHERE m.valuemapid=' . zbx_dbstr($valueMapId) . ' AND m.value=' . zbx_dbstr($value) . ' ' . andDbNode('m.mappingid')); if ($mapping = DBfetch($dbMappings)) { $valueMaps[$valueMapId][$value] = $mapping['newvalue']; return $mapping['newvalue']; } return false; }
function get_maintenance_by_maintenanceid($maintenanceid) { return DBfetch(DBselect('SELECT m.*' . ' FROM maintenances m' . ' WHERE m.maintenanceid=' . zbx_dbstr($maintenanceid) . andDbNode('m.maintenanceid'))); }
case AUDIT_ACTION_ENABLE: $action = _('Enabled'); break; case AUDIT_ACTION_DISABLE: $action = _('Disabled'); break; default: $action = _('Unknown action'); } $audit['action'] = $action; $audit['resourcetype'] = audit_resource2str($audit['resourcetype']); if (empty($audit['details'])) { $audit['details'] = DBfetchArray(DBselect('SELECT ad.table_name,ad.field_name,ad.oldvalue,ad.newvalue' . ' FROM auditlog_details ad' . ' WHERE ad.auditid=' . $audit['auditid'])); } $data['actions'][$audit['auditid']] = $audit; } if (!empty($data['actions'])) { order_result($data['actions'], 'clock', ZBX_SORT_DOWN); } // get paging $data['paging'] = getPagingLine($data['actions']); // get timeline unset($sqlWhere['from'], $sqlWhere['till']); $sql = 'SELECT MIN(a.clock) AS clock' . ' FROM auditlog a,users u' . ' WHERE a.userid=u.userid' . implode('', $sqlWhere) . andDbNode('u.userid', get_current_nodeid(null, PERM_READ)); $firstAudit = DBfetch(DBselect($sql, $config['search_limit'] + 1)); $data['timeline'] = array('period' => $effectivePeriod, 'starttime' => date(TIMESTAMP_FORMAT, $firstAudit ? $firstAudit['clock'] : null), 'usertime' => isset($_REQUEST['stime']) ? date(TIMESTAMP_FORMAT, zbxDateToTime($data['stime']) + $effectivePeriod) : null); // render view $auditView = new CView('administration.auditlogs.list', $data); $auditView->render(); $auditView->show(); require_once dirname(__FILE__) . '/include/page_footer.php';