本文整理汇总了PHP中zbx_db_search函数的典型用法代码示例。如果您正苦于以下问题:PHP zbx_db_search函数的具体用法?PHP zbx_db_search怎么用?PHP zbx_db_search使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zbx_db_search函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Get IconMap data.
* @param array $options
* @param array $options['iconmapids']
* @param array $options['sysmapids']
* @param array $options['editable']
* @param array $options['count']
* @param array $options['limit']
* @param array $options['order']
* @return array
*/
public function get(array $options = [])
{
$result = [];
$sqlParts = ['select' => ['icon_map' => 'im.iconmapid'], 'from' => ['icon_map' => 'icon_map im'], 'where' => [], 'order' => [], 'limit' => null];
$defOptions = ['iconmapids' => null, 'sysmapids' => null, 'nopermissions' => null, 'editable' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_EXTEND, 'selectMappings' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null];
$options = zbx_array_merge($defOptions, $options);
// editable + PERMISSION CHECK
if ($options['editable'] && self::$userData['type'] != USER_TYPE_SUPER_ADMIN) {
return [];
}
// iconmapids
if (!is_null($options['iconmapids'])) {
zbx_value2array($options['iconmapids']);
$sqlParts['where'][] = dbConditionInt('im.iconmapid', $options['iconmapids']);
}
// sysmapids
if (!is_null($options['sysmapids'])) {
zbx_value2array($options['sysmapids']);
$sqlParts['from']['sysmaps'] = 'sysmaps s';
$sqlParts['where'][] = dbConditionInt('s.sysmapid', $options['sysmapids']);
$sqlParts['where']['ims'] = 'im.iconmapid=s.iconmapid';
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('icon_map im', $options, $sqlParts);
}
// search
if (is_array($options['search'])) {
zbx_db_search('icon_map im', $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);
$dbRes = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
while ($iconMap = DBfetch($dbRes)) {
if ($options['countOutput']) {
$result = $iconMap['rowscount'];
} else {
$result[$iconMap['iconmapid']] = $iconMap;
}
}
if (!is_null($options['countOutput'])) {
return $result;
}
if ($result) {
$result = $this->addRelatedObjects($options, $result);
}
// removing keys (hash -> array)
if (is_null($options['preservekeys'])) {
$result = zbx_cleanHashes($result);
}
return $result;
}
示例2: get
//.........这里部分代码省略.........
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where'][] = dbConditionInt('gi.graphid', $options['graphids']);
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
if (!$nodeCheck) {
$nodeCheck = true;
$sqlParts['where'][] = DBin_node('gi.graphid', $nodeids);
}
}
// node check !!!!
// should last, after all ****IDS checks
if (!$nodeCheck) {
$sqlParts['where'][] = DBin_node('h.hostid', $nodeids);
}
// with_items
if (!is_null($options['with_items'])) {
$sqlParts['where'][] = 'EXISTS (SELECT NULL FROM items i WHERE h.hostid=i.hostid )';
}
// with_triggers
if (!is_null($options['with_triggers'])) {
$sqlParts['where'][] = 'EXISTS(' . 'SELECT NULL' . ' FROM items i,functions f,triggers t' . ' WHERE i.hostid=h.hostid' . ' AND i.itemid=f.itemid' . ' AND f.triggerid=t.triggerid)';
}
// with_graphs
if (!is_null($options['with_graphs'])) {
$sqlParts['where'][] = 'EXISTS(' . 'SELECT NULL' . ' FROM items i,graphs_items gi' . ' WHERE i.hostid=h.hostid' . ' AND i.itemid=gi.itemid)';
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('hosts h', $options, $sqlParts);
}
// search
if (is_array($options['search'])) {
zbx_db_search('hosts h', $options, $sqlParts);
}
// output
if ($options['output'] == API_OUTPUT_EXTEND) {
$sqlParts['select']['templates'] = 'h.*';
}
// countOutput
if (!is_null($options['countOutput'])) {
$options['sortfield'] = '';
$sqlParts['select'] = array('count(DISTINCT h.hostid) as rowscount');
// groupCount
if (!is_null($options['groupCount'])) {
foreach ($sqlParts['group'] as $key => $fields) {
$sqlParts['select'][$key] = $fields;
}
}
}
// sorting
zbx_db_sorting($sqlParts, $options, $sortColumns, 'h');
// limit
if (zbx_ctype_digit($options['limit']) && $options['limit']) {
$sqlParts['limit'] = $options['limit'];
}
//-------------
$templateids = array();
$res = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
while ($template = DBfetch($res)) {
if (!is_null($options['countOutput'])) {
if (!is_null($options['groupCount'])) {
$result[] = $template;
} else {
$result = $template['rowscount'];
}
示例3: get
/**
* 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('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_EXTEND, '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']);
// return scripts that are assigned to the hosts' groups or to no group
$hostGroups = API::HostGroup()->get(array('output' => array('groupid'), 'hostids' => $options['hostids']));
$hostGroupIds = zbx_objectValues($hostGroups, 'groupid');
$sqlParts['where'][] = '(' . dbConditionInt('s.groupid', $hostGroupIds) . ' OR s.groupid IS NULL)';
}
// 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);
$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;
}
示例4: get
//.........这里部分代码省略.........
}
if (!$nodeCheck) {
$nodeCheck = true;
$sqlParts['where'][] = DBin_node('dh.druleid', $nodeids);
}
}
// node check !!!!!
// should last, after all ****IDS checks
if (!$nodeCheck) {
$nodeCheck = true;
$sqlParts['where'][] = DBin_node('ds.dserviceid', $nodeids);
}
// output
if ($options['output'] == API_OUTPUT_EXTEND) {
$sqlParts['select']['dservices'] = 'ds.*';
}
// countOutput
if (!is_null($options['countOutput'])) {
$options['sortfield'] = '';
$sqlParts['select'] = array('count(DISTINCT ds.dserviceid) as rowscount');
//groupCount
if (!is_null($options['groupCount'])) {
foreach ($sqlParts['group'] as $key => $fields) {
$sqlParts['select'][$key] = $fields;
}
}
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('dservices ds', $options, $sqlParts);
}
// search
if (is_array($options['search'])) {
zbx_db_search('dservices ds', $options, $sqlParts);
}
// sorting
zbx_db_sorting($sqlParts, $options, $sortColumns, 'ds');
// limit
if (zbx_ctype_digit($options['limit']) && $options['limit']) {
$sqlParts['limit'] = $options['limit'];
}
//-------
$dserviceids = array();
$sqlParts['select'] = array_unique($sqlParts['select']);
$sqlParts['from'] = array_unique($sqlParts['from']);
$sqlParts['where'] = array_unique($sqlParts['where']);
$sqlParts['group'] = array_unique($sqlParts['group']);
$sqlParts['order'] = array_unique($sqlParts['order']);
$sqlSelect = '';
$sqlFrom = '';
$sqlWhere = '';
$sqlGroup = '';
$sqlOrder = '';
if (!empty($sqlParts['select'])) {
$sqlSelect .= implode(',', $sqlParts['select']);
}
if (!empty($sqlParts['from'])) {
$sqlFrom .= implode(',', $sqlParts['from']);
}
if (!empty($sqlParts['where'])) {
$sqlWhere .= implode(' AND ', $sqlParts['where']);
}
if (!empty($sqlParts['group'])) {
$sqlWhere .= ' GROUP BY ' . implode(',', $sqlParts['group']);
}
if (!empty($sqlParts['order'])) {
示例5: get
//.........这里部分代码省略.........
if ($options['output'] != API_OUTPUT_SHORTEN) {
$sql_parts['select']['hostid'] = 'i.hostid';
}
$sql_parts['from']['items'] = 'items i';
$sql_parts['where']['i'] = DBcondition('i.hostid', $options['hostids']);
$sql_parts['where']['hi'] = 'h.itemid=i.itemid';
if (!$nodeCheck) {
$nodeCheck = true;
$sql_parts['where'][] = DBin_node('i.hostid', $nodeids);
}
}
// node check !!!!!
// should be last, after all ****IDS checks
if (!$nodeCheck) {
$nodeCheck = true;
$sql_parts['where'][] = DBin_node('h.itemid', $nodeids);
}
// time_from
if (!is_null($options['time_from'])) {
$sql_parts['select']['clock'] = 'h.clock';
$sql_parts['where']['clock_from'] = 'h.clock>=' . $options['time_from'];
}
// time_till
if (!is_null($options['time_till'])) {
$sql_parts['select']['clock'] = 'h.clock';
$sql_parts['where']['clock_till'] = 'h.clock<=' . $options['time_till'];
}
// filter
if (is_array($options['filter'])) {
zbx_db_filter($sql_parts['from']['history'], $options, $sql_parts);
}
// search
if (is_array($options['search'])) {
zbx_db_search($sql_parts['from']['history'], $options, $sql_parts);
}
// output
if ($options['output'] == API_OUTPUT_EXTEND) {
unset($sql_parts['select']['clock']);
$sql_parts['select']['history'] = 'h.*';
}
// countOutput
if (!is_null($options['countOutput'])) {
$options['sortfield'] = '';
$sql_parts['select'] = array('count(DISTINCT h.hostid) as rowscount');
//groupCount
if (!is_null($options['groupCount'])) {
foreach ($sql_parts['group'] as $key => $fields) {
$sql_parts['select'][$key] = $fields;
}
}
}
// groupOutput
$groupOutput = false;
if (!is_null($options['groupOutput'])) {
if (str_in_array('h.' . $options['groupOutput'], $sql_parts['select']) || str_in_array('h.*', $sql_parts['select'])) {
$groupOutput = true;
}
}
// order
// restrict not allowed columns for sorting
$options['sortfield'] = str_in_array($options['sortfield'], $sort_columns) ? $options['sortfield'] : '';
if (!zbx_empty($options['sortfield'])) {
$sortorder = $options['sortorder'] == ZBX_SORT_DOWN ? ZBX_SORT_DOWN : ZBX_SORT_UP;
if ($options['sortfield'] == 'clock') {
$sql_parts['order']['itemid'] = 'h.itemid ' . $sortorder;
}
示例6: get
//.........这里部分代码省略.........
// itemids
if (!is_null($options['itemids'])) {
zbx_value2array($options['itemids']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where'][] = dbConditionInt('gi.itemid', $options['itemids']);
if (!is_null($options['groupCount'])) {
$sqlParts['group']['gi'] = 'gi.itemid';
}
}
// discoveryids
if (!is_null($options['discoveryids'])) {
zbx_value2array($options['discoveryids']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['item_discovery'] = 'item_discovery id';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where']['giid'] = 'gi.itemid=id.itemid';
$sqlParts['where'][] = dbConditionInt('id.parent_itemid', $options['discoveryids']);
if (!is_null($options['groupCount'])) {
$sqlParts['group']['id'] = 'id.parent_itemid';
}
}
// templated
if (!is_null($options['templated'])) {
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['from']['hosts'] = 'hosts h';
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
$sqlParts['where']['ggi'] = 'g.graphid=gi.graphid';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
if ($options['templated']) {
$sqlParts['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE;
} else {
$sqlParts['where'][] = 'h.status<>' . HOST_STATUS_TEMPLATE;
}
}
// inherited
if (!is_null($options['inherited'])) {
if ($options['inherited']) {
$sqlParts['where'][] = 'g.templateid IS NOT NULL';
} else {
$sqlParts['where'][] = 'g.templateid IS NULL';
}
}
// search
if (is_array($options['search'])) {
zbx_db_search('graphs g', $options, $sqlParts);
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('graphs g', $options, $sqlParts);
if (isset($options['filter']['host'])) {
zbx_value2array($options['filter']['host']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['from']['hosts'] = 'hosts h';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
$sqlParts['where']['host'] = dbConditionString('h.host', $options['filter']['host']);
}
if (isset($options['filter']['hostid'])) {
zbx_value2array($options['filter']['hostid']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
$sqlParts['where']['hostid'] = dbConditionInt('i.hostid', $options['filter']['hostid']);
}
}
// 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);
$dbRes = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
while ($graph = DBfetch($dbRes)) {
if (!is_null($options['countOutput'])) {
if (!is_null($options['groupCount'])) {
$result[] = $graph;
} else {
$result = $graph['rowscount'];
}
} else {
$result[$graph['graphid']] = $graph;
}
}
if (!is_null($options['countOutput'])) {
return $result;
}
if ($result) {
$result = $this->addRelatedObjects($options, $result);
}
// removing keys (hash -> array)
if (is_null($options['preservekeys'])) {
$result = zbx_cleanHashes($result);
}
return $result;
}
示例7: get
//.........这里部分代码省略.........
$sqlParts['where']['ggi'] = 'g.graphid=gi.graphid';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
if ($options['templated']) {
$sqlParts['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE;
} else {
$sqlParts['where'][] = 'h.status<>' . HOST_STATUS_TEMPLATE;
}
}
// inherited
if (!is_null($options['inherited'])) {
if ($options['inherited']) {
$sqlParts['where'][] = 'g.templateid IS NOT NULL';
} else {
$sqlParts['where'][] = 'g.templateid IS NULL';
}
}
// output
if ($options['output'] == API_OUTPUT_EXTEND) {
$sqlParts['select']['graphs'] = 'g.*';
}
// countOutput
if (!is_null($options['countOutput'])) {
$options['sortfield'] = '';
$sqlParts['select'] = array('count(DISTINCT g.graphid) as rowscount');
// groupCount
if (!is_null($options['groupCount'])) {
foreach ($sqlParts['group'] as $key => $fields) {
$sqlParts['select'][$key] = $fields;
}
}
}
// search
if (is_array($options['search'])) {
zbx_db_search('graphs g', $options, $sqlParts);
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('graphs g', $options, $sqlParts);
if (isset($options['filter']['host'])) {
zbx_value2array($options['filter']['host']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['from']['hosts'] = 'hosts h';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
$sqlParts['where']['host'] = dbConditionString('h.host', $options['filter']['host']);
}
if (isset($options['filter']['hostid'])) {
zbx_value2array($options['filter']['hostid']);
$sqlParts['from']['graphs_items'] = 'graphs_items gi';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
$sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
$sqlParts['where']['hostid'] = dbConditionInt('i.hostid', $options['filter']['hostid']);
}
}
// sorting
zbx_db_sorting($sqlParts, $options, $sortColumns, 'g');
// limit
if (zbx_ctype_digit($options['limit']) && $options['limit']) {
$sqlParts['limit'] = $options['limit'];
}
$graphids = array();
$sqlParts['select'] = array_unique($sqlParts['select']);
$sqlParts['from'] = array_unique($sqlParts['from']);
示例8: get
/**
* Get maintenances data.
*
* @param array $options
* @param array $options['itemids']
* @param array $options['hostids']
* @param array $options['groupids']
* @param array $options['triggerids']
* @param array $options['maintenanceids']
* @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 = [];
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
$sqlParts = ['select' => ['maintenance' => 'm.maintenanceid'], 'from' => ['maintenances' => 'maintenances m'], 'where' => [], 'group' => [], 'order' => [], 'limit' => null];
$defOptions = ['groupids' => null, 'hostids' => null, 'maintenanceids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'filter' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_EXTEND, 'selectGroups' => null, 'selectHosts' => null, 'selectTimeperiods' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null];
$options = zbx_array_merge($defOptions, $options);
// editable + PERMISSION CHECK
$maintenanceids = [];
if ($userType == USER_TYPE_SUPER_ADMIN || $options['nopermissions']) {
if (!is_null($options['groupids']) || !is_null($options['hostids'])) {
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
$res = DBselect('SELECT mmg.maintenanceid' . ' FROM maintenances_groups mmg' . ' WHERE ' . dbConditionInt('mmg.groupid', $options['groupids']));
while ($maintenance = DBfetch($res)) {
$maintenanceids[] = $maintenance['maintenanceid'];
}
}
$sql = 'SELECT mmh.maintenanceid' . ' FROM maintenances_hosts mmh,hosts_groups hg' . ' WHERE hg.hostid=mmh.hostid';
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
$sql .= ' AND ' . dbConditionInt('hg.groupid', $options['groupids']);
}
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$sql .= ' AND ' . dbConditionInt('hg.hostid', $options['hostids']);
}
$res = DBselect($sql);
while ($maintenance = DBfetch($res)) {
$maintenanceids[] = $maintenance['maintenanceid'];
}
$sqlParts['where'][] = dbConditionInt('m.maintenanceid', $maintenanceids);
}
} else {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
$userGroups = getUserGroupsByUserId($userid);
$sql = 'SELECT m.maintenanceid' . ' FROM maintenances m' . ' WHERE NOT EXISTS (' . 'SELECT NULL' . ' FROM maintenances_hosts mh,hosts_groups hg' . ' LEFT JOIN rights r' . ' ON r.id=hg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE m.maintenanceid=mh.maintenanceid' . ' AND mh.hostid=hg.hostid' . ' GROUP by mh.hostid' . ' HAVING MIN(r.permission) IS NULL' . ' OR MIN(r.permission)=' . PERM_DENY . ' OR MAX(r.permission)<' . zbx_dbstr($permission) . ')' . ' AND NOT EXISTS (' . 'SELECT NULL' . ' FROM maintenances_groups mg' . ' LEFT JOIN rights r' . ' ON r.id=mg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE m.maintenanceid=mg.maintenanceid' . ' GROUP by mg.groupid' . ' HAVING MIN(r.permission) IS NULL' . ' OR MIN(r.permission)=' . PERM_DENY . ' OR MAX(r.permission)<' . zbx_dbstr($permission) . ')';
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
$sql .= ' AND (' . 'EXISTS (' . 'SELECT NULL' . ' FROM maintenances_groups mg' . ' WHERE m.maintenanceid=mg.maintenanceid' . ' AND ' . dbConditionInt('mg.groupid', $options['groupids']) . ')' . ' OR EXISTS (' . 'SELECT NULL' . ' FROM maintenances_hosts mh,hosts_groups hg' . ' WHERE m.maintenanceid=mh.maintenanceid' . ' AND mh.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.groupid', $options['groupids']) . ')' . ')';
}
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$sql .= ' AND EXISTS (' . 'SELECT NULL' . ' FROM maintenances_hosts mh' . ' WHERE m.maintenanceid=mh.maintenanceid' . ' AND ' . dbConditionInt('mh.hostid', $options['hostids']) . ')';
}
if (!is_null($options['maintenanceids'])) {
zbx_value2array($options['maintenanceids']);
$sql .= ' AND ' . dbConditionInt('m.maintenanceid', $options['maintenanceids']);
}
$res = DBselect($sql);
while ($maintenance = DBfetch($res)) {
$maintenanceids[] = $maintenance['maintenanceid'];
}
$sqlParts['where'][] = dbConditionInt('m.maintenanceid', $maintenanceids);
}
// maintenanceids
if (!is_null($options['maintenanceids'])) {
zbx_value2array($options['maintenanceids']);
$sqlParts['where'][] = dbConditionInt('m.maintenanceid', $options['maintenanceids']);
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('maintenances m', $options, $sqlParts);
}
// search
if (is_array($options['search'])) {
zbx_db_search('maintenances m', $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);
$res = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
while ($maintenance = DBfetch($res)) {
if (!is_null($options['countOutput'])) {
if (!is_null($options['groupCount'])) {
$result[] = $maintenance;
} else {
$result = $maintenance['rowscount'];
//.........这里部分代码省略.........
示例9: get
//.........这里部分代码省略.........
if (!is_null($options['active'])) {
$sqlParts['where']['active'] = ' NOT EXISTS (' . ' SELECT NULL' . ' FROM functions ff' . ' WHERE ff.triggerid=t.triggerid' . ' AND EXISTS (' . ' SELECT NULL' . ' FROM items ii,hosts hh' . ' WHERE ff.itemid=ii.itemid' . ' AND hh.hostid=ii.hostid' . ' AND hh.status<>' . HOST_STATUS_MONITORED . ' )' . ' )';
$sqlParts['where']['status'] = 't.status=' . TRIGGER_STATUS_ENABLED;
}
// maintenance
if (!is_null($options['maintenance'])) {
$sqlParts['where'][] = ($options['maintenance'] == 0 ? ' NOT ' : '') . ' EXISTS (' . ' SELECT NULL' . ' FROM functions ff' . ' WHERE ff.triggerid=t.triggerid' . ' AND EXISTS (' . ' SELECT NULL' . ' FROM items ii,hosts hh' . ' WHERE ff.itemid=ii.itemid' . ' AND hh.hostid=ii.hostid' . ' AND hh.maintenance_status=1' . ' )' . ' )';
$sqlParts['where'][] = 't.status=' . TRIGGER_STATUS_ENABLED;
}
// templated
if (!is_null($options['templated'])) {
$sqlParts['from']['functions'] = 'functions f';
$sqlParts['from']['items'] = 'items i';
$sqlParts['from']['hosts'] = 'hosts h';
$sqlParts['where']['ft'] = 'f.triggerid=t.triggerid';
$sqlParts['where']['fi'] = 'f.itemid=i.itemid';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
if ($options['templated']) {
$sqlParts['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE;
} else {
$sqlParts['where'][] = 'h.status<>' . HOST_STATUS_TEMPLATE;
}
}
// inherited
if (!is_null($options['inherited'])) {
if ($options['inherited']) {
$sqlParts['where'][] = 't.templateid IS NOT NULL';
} else {
$sqlParts['where'][] = 't.templateid IS NULL';
}
}
// search
if (is_array($options['search'])) {
zbx_db_search('triggers t', $options, $sqlParts);
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('triggers t', $options, $sqlParts);
if (isset($options['filter']['host']) && !is_null($options['filter']['host'])) {
zbx_value2array($options['filter']['host']);
$sqlParts['from']['functions'] = 'functions f';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where']['ft'] = 'f.triggerid=t.triggerid';
$sqlParts['where']['fi'] = 'f.itemid=i.itemid';
$sqlParts['from']['hosts'] = 'hosts h';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
$sqlParts['where']['host'] = dbConditionString('h.host', $options['filter']['host']);
}
if (isset($options['filter']['hostid']) && !is_null($options['filter']['hostid'])) {
zbx_value2array($options['filter']['hostid']);
$sqlParts['from']['functions'] = 'functions f';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where']['ft'] = 'f.triggerid=t.triggerid';
$sqlParts['where']['fi'] = 'f.itemid=i.itemid';
$sqlParts['where']['hostid'] = dbConditionInt('i.hostid', $options['filter']['hostid']);
}
}
// group
if (!is_null($options['group'])) {
$sqlParts['select']['name'] = 'g.name';
$sqlParts['from']['functions'] = 'functions f';
$sqlParts['from']['items'] = 'items i';
$sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
$sqlParts['from']['groups'] = 'groups g';
$sqlParts['where']['ft'] = 'f.triggerid=t.triggerid';
$sqlParts['where']['fi'] = 'f.itemid=i.itemid';
示例10: get
/**
* Get IconMap data.
* @param array $options
* @param array $options['nodeids']
* @param array $options['iconmapids']
* @param array $options['sysmapids']
* @param array $options['editable']
* @param array $options['count']
* @param array $options['limit']
* @param array $options['order']
* @return array
*/
public function get(array $options = array())
{
$result = array();
// allowed columns for sorting
$sortColumns = array('iconmapid', 'name');
// allowed output options for [ select_* ] params
$subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
$sqlParts = array('select' => array('icon_map' => 'im.iconmapid'), 'from' => array('icon_map' => 'icon_map im'), 'where' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('nodeids' => null, 'iconmapids' => null, 'sysmapids' => null, 'nopermissions' => null, 'editable' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectMappings' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
$options = zbx_array_merge($defOptions, $options);
if (is_array($options['output'])) {
$dbTable = DB::getSchema('icon_map');
foreach ($options['output'] as $field) {
if (isset($dbTable['fields'][$field])) {
$sqlParts['select'][$field] = 'im.' . $field;
}
}
$options['output'] = API_OUTPUT_CUSTOM;
}
// editable + PERMISSION CHECK
if ($options['editable'] && self::$userData['type'] != USER_TYPE_SUPER_ADMIN) {
return array();
}
// nodeids
$nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
// iconmapids
if (!is_null($options['iconmapids'])) {
zbx_value2array($options['iconmapids']);
$sqlParts['where'][] = dbConditionInt('im.iconmapid', $options['iconmapids']);
}
// sysmapids
if (!is_null($options['sysmapids'])) {
zbx_value2array($options['sysmapids']);
if ($options['output'] != API_OUTPUT_SHORTEN) {
$sqlParts['select']['sysmapids'] = 's.sysmapid';
}
$sqlParts['from']['sysmaps'] = 'sysmaps s';
$sqlParts['where'][] = dbConditionInt('s.sysmapid', $options['sysmapids']);
$sqlParts['where']['ims'] = 'im.iconmapid=s.iconmapid';
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('icon_map im', $options, $sqlParts);
}
// search
if (is_array($options['search'])) {
zbx_db_search('icon_map im', $options, $sqlParts);
}
// output
if ($options['output'] == API_OUTPUT_EXTEND) {
$sqlParts['select']['icon_map'] = 'im.*';
}
// countOutput
if (!is_null($options['countOutput'])) {
$options['sortfield'] = '';
$sqlParts['select'] = array('COUNT(DISTINCT im.iconmapid) AS rowscount');
}
// sorting
zbx_db_sorting($sqlParts, $options, $sortColumns, 'im');
// limit
if (zbx_ctype_digit($options['limit']) && $options['limit']) {
$sqlParts['limit'] = $options['limit'];
}
$iconMapids = array();
$sqlParts['select'] = array_unique($sqlParts['select']);
$sqlParts['from'] = array_unique($sqlParts['from']);
$sqlParts['where'] = array_unique($sqlParts['where']);
$sqlParts['order'] = array_unique($sqlParts['order']);
$sqlSelect = '';
$sqlFrom = '';
$sqlWhere = '';
$sqlOrder = '';
if (!empty($sqlParts['select'])) {
$sqlSelect .= implode(',', $sqlParts['select']);
}
if (!empty($sqlParts['from'])) {
$sqlFrom .= implode(',', $sqlParts['from']);
}
if (!empty($sqlParts['where'])) {
$sqlWhere .= ' AND ' . implode(' AND ', $sqlParts['where']);
}
if (!empty($sqlParts['order'])) {
$sqlOrder .= ' ORDER BY ' . implode(',', $sqlParts['order']);
}
$sqlLimit = $sqlParts['limit'];
$sql = 'SELECT ' . $sqlSelect . ' FROM ' . $sqlFrom . ' WHERE ' . DBin_node('im.iconmapid', $nodeids) . $sqlWhere . $sqlOrder;
$dbRes = DBselect($sql, $sqlLimit);
while ($iconMap = DBfetch($dbRes)) {
//.........这里部分代码省略.........
示例11: get
/**
* Get data about web scenarios.
*
* @param array $options
*
* @return array
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
// allowed columns for sorting
$sortColumns = array('httptestid', 'name');
// allowed output options for [ select_* ] params
$subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
$sqlParts = array('select' => array('httptests' => 'ht.httptestid'), 'from' => array('httptest' => 'httptest ht'), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('nodeids' => null, 'httptestids' => null, 'applicationids' => null, 'hostids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'exludeSearch' => null, 'output' => API_OUTPUT_REFER, 'selectHosts' => null, 'selectSteps' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
$options = zbx_array_merge($defOptions, $options);
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
$userGroups = getUserGroupsByUserId($userid);
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM applications a,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE a.applicationid=ht.applicationid' . ' AND a.hostid=hgg.hostid' . ' GROUP BY a.applicationid' . ' HAVING MIN(r.permission)>=' . $permission . ')';
}
// nodeids
$nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
// httptestids
if (!is_null($options['httptestids'])) {
zbx_value2array($options['httptestids']);
if ($options['output'] != API_OUTPUT_SHORTEN) {
$sqlParts['select']['httptestid'] = 'ht.httptestid';
}
$sqlParts['where']['httptestid'] = dbConditionInt('ht.httptestid', $options['httptestids']);
}
// hostids
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
if ($options['output'] != API_OUTPUT_SHORTEN) {
$sqlParts['select']['hostid'] = 'a.hostid';
}
$sqlParts['from']['applications'] = 'applications a';
$sqlParts['where'][] = 'a.applicationid=ht.applicationid';
$sqlParts['where']['hostid'] = dbConditionInt('a.hostid', $options['hostids']);
if (!is_null($options['groupCount'])) {
$sqlParts['group']['hostid'] = 'a.hostid';
}
}
// applicationids
if (!is_null($options['applicationids'])) {
zbx_value2array($options['applicationids']);
if ($options['output'] != API_OUTPUT_EXTEND) {
$sqlParts['select']['applicationid'] = 'a.applicationid';
}
$sqlParts['where'][] = dbConditionInt('ht.applicationid', $options['applicationids']);
}
// output
if ($options['output'] == API_OUTPUT_EXTEND) {
$sqlParts['select']['httptests'] = 'ht.*';
}
// countOutput
if (!is_null($options['countOutput'])) {
$options['sortfield'] = '';
$sqlParts['select'] = array('count(ht.httptestid) as rowscount');
// groupCount
if (!is_null($options['groupCount'])) {
foreach ($sqlParts['group'] as $key => $fields) {
$sqlParts['select'][$key] = $fields;
}
}
}
// search
if (is_array($options['search'])) {
zbx_db_search('httptest ht', $options, $sqlParts);
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('httptest ht', $options, $sqlParts);
}
// sorting
zbx_db_sorting($sqlParts, $options, $sortColumns, 'ht');
// limit
if (zbx_ctype_digit($options['limit']) && $options['limit']) {
$sqlParts['limit'] = $options['limit'];
}
$httpTestIds = array();
$sqlParts['select'] = array_unique($sqlParts['select']);
$sqlParts['from'] = array_unique($sqlParts['from']);
$sqlParts['where'] = array_unique($sqlParts['where']);
$sqlParts['group'] = array_unique($sqlParts['group']);
$sqlParts['order'] = array_unique($sqlParts['order']);
$sqlSelect = '';
$sqlFrom = '';
$sqlWhere = '';
$sqlGroup = '';
$sqlOrder = '';
if (!empty($sqlParts['select'])) {
$sqlSelect .= implode(',', $sqlParts['select']);
}
if (!empty($sqlParts['from'])) {
//.........这里部分代码省略.........
示例12: get
//.........这里部分代码省略.........
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM items i' . ' WHERE h.hostid=i.hostid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ')';
} elseif (!is_null($options['with_historical_items'])) {
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM items i' . ' WHERE h.hostid=i.hostid' . ' AND i.status IN (' . ITEM_STATUS_ACTIVE . ',' . ITEM_STATUS_NOTSUPPORTED . ')' . ' AND i.lastvalue IS NOT NULL' . ')';
} elseif (!is_null($options['with_simple_graph_items'])) {
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM items i' . ' WHERE h.hostid=i.hostid' . ' AND i.value_type IN (' . ITEM_VALUE_TYPE_FLOAT . ',' . ITEM_VALUE_TYPE_UINT64 . ')' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.flags IN (' . ZBX_FLAG_DISCOVERY_NORMAL . ',' . ZBX_FLAG_DISCOVERY_CREATED . ')' . ')';
}
// with_triggers, with_monitored_triggers
if (!is_null($options['with_triggers'])) {
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM items i,functions f,triggers t' . ' WHERE h.hostid=i.hostid' . ' AND i.itemid=f.itemid' . ' AND f.triggerid=t.triggerid' . ')';
} elseif (!is_null($options['with_monitored_triggers'])) {
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM items i,functions f,triggers t' . ' WHERE h.hostid=i.hostid' . ' AND i.itemid=f.itemid' . ' AND f.triggerid=t.triggerid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ')';
}
// with_httptests, with_monitored_httptests
if (!is_null($options['with_httptests'])) {
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM applications a,httptest ht' . ' WHERE h.hostid=a.hostid' . ' AND a.applicationid=ht.applicationid' . ')';
} elseif (!is_null($options['with_monitored_httptests'])) {
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM applications a,httptest ht' . ' WHERE h.hostid=a.hostid' . ' AND a.applicationid=ht.applicationid' . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE . ')';
}
// with_graphs
if (!is_null($options['with_graphs'])) {
$sqlParts['where'][] = 'EXISTS (' . ' SELECT 1' . ' FROM items i,graphs_items gi' . ' WHERE i.hostid=h.hostid' . ' AND i.itemid=gi.itemid ' . zbx_limit(1) . ')';
}
// with applications
if (!is_null($options['with_applications'])) {
$sqlParts['from']['applications'] = 'applications a';
$sqlParts['where'][] = 'a.hostid=h.hostid';
}
// withInventory
if (!is_null($options['withInventory']) && $options['withInventory']) {
$sqlParts['where'][] = ' h.hostid IN (' . ' SELECT hin.hostid' . ' FROM host_inventory hin)';
}
// search
if (is_array($options['search'])) {
zbx_db_search('hosts h', $options, $sqlParts);
if (zbx_db_search('interface hi', $options, $sqlParts)) {
$sqlParts['from']['interface'] = 'interface hi';
$sqlParts['where']['hi'] = 'h.hostid=hi.hostid';
}
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('hosts h', $options, $sqlParts);
if ($this->dbFilter('interface hi', $options, $sqlParts)) {
$sqlParts['from']['interface'] = 'interface hi';
$sqlParts['where']['hi'] = 'h.hostid=hi.hostid';
}
}
// output
if ($options['output'] == API_OUTPUT_EXTEND) {
$sqlParts['select']['hosts'] = 'h.*';
}
// countOutput
if (!is_null($options['countOutput'])) {
$options['sortfield'] = '';
$sqlParts['select'] = array('COUNT(DISTINCT h.hostid) AS rowscount');
// groupCount
if (!is_null($options['groupCount'])) {
foreach ($sqlParts['group'] as $key => $fields) {
$sqlParts['select'][$key] = $fields;
}
}
}
// sorting
zbx_db_sorting($sqlParts, $options, $sortColumns, 'h');
// limit
if (zbx_ctype_digit($options['limit']) && $options['limit']) {
示例13: get
/**
* Get applications data.
*
* @param array $options
* @param array $options['itemids']
* @param array $options['hostids']
* @param array $options['groupids']
* @param array $options['triggerids']
* @param array $options['applicationids']
* @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 item data as array or false if error
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$userid = self::$userData['userid'];
$sqlParts = array('select' => array('apps' => 'a.applicationid'), 'from' => array('applications' => 'applications a'), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('groupids' => null, 'templateids' => null, 'hostids' => null, 'itemids' => null, 'applicationids' => null, 'templated' => null, 'editable' => null, 'inherited' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_EXTEND, 'expandData' => null, 'selectHost' => null, 'selectHosts' => null, 'selectItems' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
$options = zbx_array_merge($defOptions, $options);
$this->checkDeprecatedParam($options, 'expandData');
$this->checkDeprecatedParam($options, 'selectHosts');
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
$userGroups = getUserGroupsByUserId($userid);
$sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE a.hostid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ' AND MAX(r.permission)>=' . zbx_dbstr($permission) . ')';
}
// groupids
if (!is_null($options['groupids'])) {
zbx_value2array($options['groupids']);
$sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
$sqlParts['where']['ahg'] = 'a.hostid=hg.hostid';
$sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
if (!is_null($options['groupCount'])) {
$sqlParts['group']['hg'] = 'hg.groupid';
}
}
// templateids
if (!is_null($options['templateids'])) {
zbx_value2array($options['templateids']);
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$options['hostids'] = array_merge($options['hostids'], $options['templateids']);
} else {
$options['hostids'] = $options['templateids'];
}
}
// hostids
if (!is_null($options['hostids'])) {
zbx_value2array($options['hostids']);
$sqlParts['where']['hostid'] = dbConditionInt('a.hostid', $options['hostids']);
if (!is_null($options['groupCount'])) {
$sqlParts['group']['hostid'] = 'a.hostid';
}
}
// itemids
if (!is_null($options['itemids'])) {
zbx_value2array($options['itemids']);
$sqlParts['from']['items_applications'] = 'items_applications ia';
$sqlParts['where'][] = dbConditionInt('ia.itemid', $options['itemids']);
$sqlParts['where']['aia'] = 'a.applicationid=ia.applicationid';
}
// applicationids
if (!is_null($options['applicationids'])) {
zbx_value2array($options['applicationids']);
$sqlParts['where'][] = dbConditionInt('a.applicationid', $options['applicationids']);
}
// templated
if (!is_null($options['templated'])) {
$sqlParts['from']['hosts'] = 'hosts h';
$sqlParts['where']['ah'] = 'a.hostid=h.hostid';
if ($options['templated']) {
$sqlParts['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE;
} else {
$sqlParts['where'][] = 'h.status<>' . HOST_STATUS_TEMPLATE;
}
}
// inherited
if (!is_null($options['inherited'])) {
$sqlParts['where'][] = ($options['inherited'] ? '' : 'NOT') . ' EXISTS (' . 'SELECT NULL' . ' FROM application_template at' . ' WHERE a.applicationid=at.applicationid' . ')';
}
// search
if (is_array($options['search'])) {
zbx_db_search('applications a', $options, $sqlParts);
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('applications a', $options, $sqlParts);
}
// limit
if (zbx_ctype_digit($options['limit']) && $options['limit']) {
$sqlParts['limit'] = $options['limit'];
}
//.........这里部分代码省略.........
示例14: get
/**
* Get UserGroups
*
* @param array $options
* @param array $options['nodeids'] Node IDs
* @param array $options['usrgrpids'] UserGroup IDs
* @param array $options['userids'] User IDs
* @param boolean $options['status']
* @param boolean $options['with_gui_access']
* @param boolean $options['selectUsers']
* @param int $options['count']
* @param string $options['pattern']
* @param int $options['limit'] limit selection
* @param string $options['order']
* @return array
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$sqlParts = array('select' => array('usrgrp' => 'g.usrgrpid'), 'from' => array('usrgrp' => 'usrgrp g'), 'where' => array(), 'order' => array(), 'limit' => null);
$defOptions = array('nodeids' => null, 'usrgrpids' => null, 'userids' => null, 'status' => null, 'with_gui_access' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'editable' => null, 'output' => API_OUTPUT_REFER, 'selectUsers' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
$options = zbx_array_merge($defOptions, $options);
// permission check
if (USER_TYPE_SUPER_ADMIN == $userType) {
} elseif (is_null($options['editable']) && self::$userData['type'] == USER_TYPE_ZABBIX_ADMIN) {
$sqlParts['where'][] = 'g.usrgrpid IN (' . 'SELECT uug.usrgrpid' . ' FROM users_groups uug' . ' WHERE uug.userid=' . self::$userData['userid'] . ')';
} elseif (!is_null($options['editable']) && self::$userData['type'] != USER_TYPE_SUPER_ADMIN) {
return array();
}
// usrgrpids
if (!is_null($options['usrgrpids'])) {
zbx_value2array($options['usrgrpids']);
$sqlParts['where'][] = dbConditionInt('g.usrgrpid', $options['usrgrpids']);
}
// userids
if (!is_null($options['userids'])) {
zbx_value2array($options['userids']);
$sqlParts['select']['userid'] = 'ug.userid';
$sqlParts['from']['users_groups'] = 'users_groups ug';
$sqlParts['where'][] = dbConditionInt('ug.userid', $options['userids']);
$sqlParts['where']['gug'] = 'g.usrgrpid=ug.usrgrpid';
}
// status
if (!is_null($options['status'])) {
$sqlParts['where'][] = 'g.users_status=' . zbx_dbstr($options['status']);
}
// with_gui_access
if (!is_null($options['with_gui_access'])) {
$sqlParts['where'][] = 'g.gui_access=' . GROUP_GUI_ACCESS_ENABLED;
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('usrgrp g', $options, $sqlParts);
}
// search
if (is_array($options['search'])) {
zbx_db_search('usrgrp g', $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 ($usrgrp = DBfetch($res)) {
if ($options['countOutput']) {
$result = $usrgrp['rowscount'];
} else {
if (!isset($result[$usrgrp['usrgrpid']])) {
$result[$usrgrp['usrgrpid']] = array();
}
// groupids
if (isset($usrgrp['userid']) && is_null($options['selectUsers'])) {
if (!isset($result[$usrgrp['usrgrpid']]['users'])) {
$result[$usrgrp['usrgrpid']]['users'] = array();
}
$result[$usrgrp['usrgrpid']]['users'][] = array('userid' => $usrgrp['userid']);
unset($usrgrp['userid']);
}
$result[$usrgrp['usrgrpid']] += $usrgrp;
}
}
if (!is_null($options['countOutput'])) {
return $result;
}
if ($result) {
$result = $this->addRelatedObjects($options, $result);
}
// removing keys (hash -> array)
if (is_null($options['preservekeys'])) {
$result = zbx_cleanHashes($result);
}
return $result;
}
示例15: get
/**
* Get proxy data.
*
* @param array $options
* @param array $options['nodeids']
* @param array $options['proxyids']
* @param bool $options['editable'] only with read-write permission. Ignored for SuperAdmins
* @param int $options['count'] returns value in rowscount
* @param string $options['pattern']
* @param int $options['limit']
* @param string $options['sortfield']
* @param string $options['sortorder']
*
* @return array
*/
public function get($options = array())
{
$result = array();
$userType = self::$userData['type'];
$sqlParts = array('select' => array('hostid' => 'h.hostid'), 'from' => array('hosts' => 'hosts h'), 'where' => array('h.status IN (' . HOST_STATUS_PROXY_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ')'), 'order' => array(), 'limit' => null);
$defOptions = array('nodeids' => null, 'proxyids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'countOutput' => null, 'preservekeys' => null, 'selectHosts' => null, 'selectInterface' => null, 'selectInterfaces' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
$options = zbx_array_merge($defOptions, $options);
// deprecated
$this->checkDeprecatedParam($options, 'selectInterfaces');
// editable + PERMISSION CHECK
if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
$permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ;
if ($permission == PERM_READ_WRITE) {
return array();
}
}
// proxyids
if (!is_null($options['proxyids'])) {
zbx_value2array($options['proxyids']);
$sqlParts['where'][] = dbConditionInt('h.hostid', $options['proxyids']);
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('hosts h', $options, $sqlParts);
}
// search
if (is_array($options['search'])) {
zbx_db_search('hosts h', $options, $sqlParts);
}
// output
if ($options['output'] == API_OUTPUT_EXTEND) {
$sqlParts['select']['hostid'] = 'h.hostid';
$sqlParts['select']['host'] = 'h.host';
$sqlParts['select']['status'] = 'h.status';
$sqlParts['select']['lastaccess'] = 'h.lastaccess';
}
// countOutput
if (!is_null($options['countOutput'])) {
$options['sortfield'] = '';
$sqlParts['select'] = array('COUNT(DISTINCT h.hostid) AS rowscount');
}
// 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 ($proxy = DBfetch($res)) {
if ($options['countOutput']) {
$result = $proxy['rowscount'];
} else {
$proxy['proxyid'] = $proxy['hostid'];
unset($proxy['hostid']);
if (!isset($result[$proxy['proxyid']])) {
$result[$proxy['proxyid']] = array();
}
$result[$proxy['proxyid']] += $proxy;
}
}
if (!is_null($options['countOutput'])) {
return $result;
}
if ($result) {
$result = $this->addRelatedObjects($options, $result);
$result = $this->unsetExtraFields($result, array('hostid'), $options['output']);
}
// removing keys (hash -> array)
if (is_null($options['preservekeys'])) {
$result = zbx_cleanHashes($result);
}
return $result;
}