本文整理汇总了PHP中API::getApiService方法的典型用法代码示例。如果您正苦于以下问题:PHP API::getApiService方法的具体用法?PHP API::getApiService怎么用?PHP API::getApiService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::getApiService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkIfGlobalMacrosExist
/**
* Checks if all of the global macros with globalmacroids given in $globalmacroids are present in $globalmacros.
* Assumes the "globalmacroids" field is valid.
*
* @param array $globalmacroids
*
* @throws APIException if any of the global macros is not present in $globalmacros.
*/
protected function checkIfGlobalMacrosExist(array $globalmacroids)
{
if ($globalmacroids) {
$db_globamacros = API::getApiService()->select('globalmacro', ['output' => ['globalmacroid'], 'globalmacroids' => $globalmacroids, 'preservekeys' => true]);
foreach ($globalmacroids as $globalmacroid) {
if (!array_key_exists($globalmacroid, $db_globamacros)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Macro with globalmacroid "%1$s" does not exist.', $globalmacroid));
}
}
}
}
示例2: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
// selectGroups
if ($options['selectGroups'] !== null && $options['selectGroups'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'maintenanceid', 'groupid', 'maintenances_groups');
$groups = API::HostGroup()->get(['output' => $options['selectGroups'], 'hostgroupids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
$result = $relationMap->mapMany($result, $groups, 'groups');
}
// selectHosts
if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'maintenanceid', 'hostid', 'maintenances_hosts');
$groups = API::Host()->get(['output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
$result = $relationMap->mapMany($result, $groups, 'hosts');
}
// selectTimeperiods
if ($options['selectTimeperiods'] !== null && $options['selectTimeperiods'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'maintenanceid', 'timeperiodid', 'maintenances_windows');
$timeperiods = API::getApiService()->select('timeperiods', ['output' => $options['selectTimeperiods'], 'filter' => ['timeperiodid' => $relationMap->getRelatedIds()], 'preservekeys' => true]);
$result = $relationMap->mapMany($result, $timeperiods, 'timeperiods');
}
return $result;
}
示例3: extendObjects
/**
* Fetches the fields given in $fields from the database and extends the objects with the loaded data.
*
* @param string $tableName
* @param array $objects
* @param array $fields
*
* @return array
*/
protected function extendObjects($tableName, array $objects, array $fields)
{
if ($objects) {
$dbObjects = API::getApiService()->select($tableName, ['output' => $fields, $this->pkOption($tableName) => zbx_objectValues($objects, $this->pk($tableName)), 'preservekeys' => true]);
foreach ($objects as &$object) {
$pk = $object[$this->pk($tableName)];
if (isset($dbObjects[$pk])) {
check_db_fields($dbObjects[$pk], $object);
}
}
unset($object);
}
return $objects;
}
示例4: checkIfGlobalMacrosExist
/**
* Checks if all of the global macros with globalmacroids given in $globalMacroIds are present in $globalMacros.
* Assumes the "globalmacroids" field is valid.
*
* @param array $globalMacroIds
*
* @throws APIException if any of the global macros is not present in $globalMacros
*/
protected function checkIfGlobalMacrosExist(array $globalMacroIds)
{
$globalMacros = API::getApiService()->select('globalmacro', array('output' => array('globalmacroid'), 'globalmacroids' => $globalMacroIds));
$globalMacros = zbx_toHash($globalMacros, 'globalmacroid');
foreach ($globalMacroIds as $globalMacroId) {
if (!isset($globalMacros[$globalMacroId])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Macro with globalmacroid "%1$s" does not exist.', $globalMacroId));
}
}
}
示例5: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$hostids = array_keys($result);
// adding inventories
if ($options['selectInventory'] !== null) {
$relationMap = $this->createRelationMap($result, 'hostid', 'hostid');
$inventory = API::getApiService()->select('host_inventory', ['output' => $options['selectInventory'], 'filter' => ['hostid' => $hostids]]);
$result = $relationMap->mapOne($result, zbx_toHash($inventory, 'hostid'), 'inventory');
}
// adding hostinterfaces
if ($options['selectInterfaces'] !== null) {
if ($options['selectInterfaces'] != API_OUTPUT_COUNT) {
$interfaces = API::HostInterface()->get(['output' => $this->outputExtend($options['selectInterfaces'], ['hostid', 'interfaceid']), 'hostids' => $hostids, 'nopermissions' => true, 'preservekeys' => true]);
// we need to order interfaces for proper linkage and viewing
order_result($interfaces, 'interfaceid', ZBX_SORT_UP);
$relationMap = $this->createRelationMap($interfaces, 'hostid', 'interfaceid');
$interfaces = $this->unsetExtraFields($interfaces, ['hostid', 'interfaceid'], $options['selectInterfaces']);
$result = $relationMap->mapMany($result, $interfaces, 'interfaces', $options['limitSelects']);
} else {
$interfaces = API::HostInterface()->get(['hostids' => $hostids, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true]);
$interfaces = zbx_toHash($interfaces, 'hostid');
foreach ($result as $hostid => $host) {
$result[$hostid]['interfaces'] = isset($interfaces[$hostid]) ? $interfaces[$hostid]['rowscount'] : 0;
}
}
}
// adding screens
if ($options['selectScreens'] !== null) {
if ($options['selectScreens'] != API_OUTPUT_COUNT) {
$screens = API::TemplateScreen()->get(['output' => $this->outputExtend($options['selectScreens'], ['hostid']), 'hostids' => $hostids, 'nopermissions' => true]);
if (!is_null($options['limitSelects'])) {
order_result($screens, 'name');
}
// inherited screens do not have a unique screenid, so we're building a map using array keys
$relationMap = new CRelationMap();
foreach ($screens as $key => $screen) {
$relationMap->addRelation($screen['hostid'], $key);
}
$screens = $this->unsetExtraFields($screens, ['hostid'], $options['selectScreens']);
$result = $relationMap->mapMany($result, $screens, 'screens', $options['limitSelects']);
} else {
$screens = API::TemplateScreen()->get(['hostids' => $hostids, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true]);
$screens = zbx_toHash($screens, 'hostid');
foreach ($result as $hostid => $host) {
$result[$hostid]['screens'] = isset($screens[$hostid]) ? $screens[$hostid]['rowscount'] : 0;
}
}
}
// adding discovery rule
if ($options['selectDiscoveryRule'] !== null && $options['selectDiscoveryRule'] != API_OUTPUT_COUNT) {
// discovered items
$discoveryRules = DBFetchArray(DBselect('SELECT hd.hostid,hd2.parent_itemid' . ' FROM host_discovery hd,host_discovery hd2' . ' WHERE ' . dbConditionInt('hd.hostid', $hostids) . ' AND hd.parent_hostid=hd2.hostid'));
$relationMap = $this->createRelationMap($discoveryRules, 'hostid', 'parent_itemid');
$discoveryRules = API::DiscoveryRule()->get(['output' => $options['selectDiscoveryRule'], 'itemids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
$result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule');
}
// adding host discovery
if ($options['selectHostDiscovery'] !== null) {
$hostDiscoveries = API::getApiService()->select('host_discovery', ['output' => $this->outputExtend($options['selectHostDiscovery'], ['hostid']), 'filter' => ['hostid' => $hostids], 'preservekeys' => true]);
$relationMap = $this->createRelationMap($hostDiscoveries, 'hostid', 'hostid');
$hostDiscoveries = $this->unsetExtraFields($hostDiscoveries, ['hostid'], $options['selectHostDiscovery']);
$result = $relationMap->mapOne($result, $hostDiscoveries, 'hostDiscovery');
}
return $result;
}
示例6: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$iconMapIds = array_keys($result);
if ($options['selectMappings'] !== null && $options['selectMappings'] != API_OUTPUT_COUNT) {
$mappings = API::getApiService()->select('icon_mapping', ['output' => $this->outputExtend($options['selectMappings'], ['iconmapid', 'iconmappingid']), 'filter' => ['iconmapid' => $iconMapIds], 'preservekeys' => true]);
$relationMap = $this->createRelationMap($mappings, 'iconmapid', 'iconmappingid');
$mappings = $this->unsetExtraFields($mappings, ['iconmapid', 'iconmappingid'], $options['selectMappings']);
$result = $relationMap->mapMany($result, $mappings, 'mappings');
}
return $result;
}
示例7: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
// Select mappings for value map.
if ($options['selectMappings'] !== null) {
if ($options['selectMappings'] == API_OUTPUT_COUNT) {
$db_mappings = DBselect('SELECT m.valuemapid,COUNT(*) AS cnt' . ' FROM mappings m' . ' WHERE ' . dbConditionInt('m.valuemapid', array_keys($result)) . ' GROUP BY m.valuemapid');
foreach ($result as &$valuemap) {
$valuemap['mappings'] = 0;
}
unset($valuemap);
while ($db_mapping = DBfetch($db_mappings)) {
$result[$db_mapping['valuemapid']]['mappings'] = $db_mapping['cnt'];
}
} else {
$db_mappings = API::getApiService()->select('mappings', ['output' => $this->outputExtend($options['selectMappings'], ['valuemapid']), 'filter' => ['valuemapid' => array_keys($result)]]);
foreach ($result as &$valuemap) {
$valuemap['mappings'] = [];
}
unset($valuemap);
foreach ($db_mappings as $db_mapping) {
$valuemapid = $db_mapping['valuemapid'];
unset($db_mapping['mappingid'], $db_mapping['valuemapid']);
$result[$valuemapid]['mappings'][] = $db_mapping;
}
}
}
return $result;
}
示例8: get
//.........这里部分代码省略.........
}
// filter
if (is_array($options['filter'])) {
$this->dbFilter('screens s', $options, $sqlParts);
}
// search
if (is_array($options['search'])) {
zbx_db_search('screens 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 ($screen = DBfetch($res)) {
if (!is_null($options['countOutput'])) {
if (!is_null($options['groupCount'])) {
$result[] = $screen;
} else {
$result = $screen['rowscount'];
}
} else {
$result[$screen['screenid']] = $screen;
}
}
if ($options['countOutput'] !== null && $options['groupCount'] === null) {
return $result;
}
$screenIds = array_keys($result);
// adding screenitems
if ($options['selectScreenItems'] !== null && $options['selectScreenItems'] != API_OUTPUT_COUNT) {
$screenItems = API::getApiService()->select('screens_items', array('output' => $this->outputExtend($options['selectScreenItems'], array('screenid', 'screenitemid', 'resourcetype', 'resourceid')), 'filter' => array('screenid' => $screenIds), 'preservekeys' => true));
$relationMap = $this->createRelationMap($screenItems, 'screenid', 'screenitemid');
foreach ($screenItems as $screenItem) {
switch ($screenItem['resourcetype']) {
case SCREEN_RESOURCE_GRAPH:
$graphids[$screenItem['resourceid']] = $screenItem['resourceid'];
break;
case SCREEN_RESOURCE_SIMPLE_GRAPH:
case SCREEN_RESOURCE_PLAIN_TEXT:
$itemids[$screenItem['resourceid']] = $screenItem['resourceid'];
break;
}
}
$screenItems = $this->unsetExtraFields($screenItems, array('screenid', 'screenitemid', 'resourceid', 'resourcetype'), $options['selectScreenItems']);
$result = $relationMap->mapMany($result, $screenItems, 'screenitems');
}
// creating linkage of template -> real objects
if (!is_null($options['selectScreenItems']) && !is_null($options['hostids'])) {
// prepare graphs
if (!empty($graphids)) {
$tplGraphs = API::Graph()->get(array('output' => array('graphid', 'name'), 'graphids' => $graphids, 'nopermissions' => true, 'preservekeys' => true));
$dbGraphs = API::Graph()->get(array('output' => array('graphid', 'name'), 'selectHosts' => array('hostid'), 'hostids' => $options['hostids'], 'filter' => array('name' => zbx_objectValues($tplGraphs, 'name')), 'nopermissions' => true, 'preservekeys' => true));
$realGraphs = array();
foreach ($dbGraphs as $graph) {
$host = reset($graph['hosts']);
unset($graph['hosts']);
if (!isset($realGraphs[$host['hostid']])) {
$realGraphs[$host['hostid']] = array();
}
$realGraphs[$host['hostid']][$graph['name']] = $graph;
}
}
// prepare items
示例9: validateMassRemove
protected function validateMassRemove(array $data)
{
// check permissions
$this->checkHostPermissions($data['hostids']);
// check interfaces
foreach ($data['interfaces'] as $interface) {
if (!isset($interface['dns']) || !isset($interface['ip']) || !isset($interface['port'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect arguments passed to function.'));
}
$this->checkDns($interface);
$this->checkIp($interface);
$this->checkPort($interface);
$this->checkBulk($interface);
// check main interfaces
$interfacesToRemove = API::getApiService()->select($this->tableName(), ['output' => ['interfaceid'], 'filter' => ['hostid' => $data['hostids'], 'ip' => $interface['ip'], 'dns' => $interface['dns'], 'port' => $interface['port'], 'bulk' => $interface['bulk']]]);
if ($interfacesToRemove) {
$this->checkMainInterfacesOnDelete(zbx_objectValues($interfacesToRemove, 'interfaceid'));
}
}
}
示例10: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$actionIds = array_keys($result);
// adding formulas
if ($options['selectFilter'] !== null) {
$formulaRequested = $this->outputIsRequested('formula', $options['selectFilter']);
$evalFormulaRequested = $this->outputIsRequested('eval_formula', $options['selectFilter']);
$conditionsRequested = $this->outputIsRequested('conditions', $options['selectFilter']);
$filters = array();
foreach ($result as $action) {
$filters[$action['actionid']] = array('evaltype' => $action['evaltype'], 'formula' => isset($action['formula']) ? $action['formula'] : '');
}
if ($formulaRequested || $evalFormulaRequested || $conditionsRequested) {
$conditions = API::getApiService()->select('conditions', array('output' => array('actionid', 'conditionid', 'conditiontype', 'operator', 'value'), 'filter' => array('actionid' => $actionIds), 'preservekeys' => true));
$relationMap = $this->createRelationMap($conditions, 'actionid', 'conditionid');
$filters = $relationMap->mapMany($filters, $conditions, 'conditions');
foreach ($filters as &$filter) {
// in case of a custom expression - use the given formula
if ($filter['evaltype'] == CONDITION_EVAL_TYPE_EXPRESSION) {
$formula = $filter['formula'];
} else {
$conditions = $filter['conditions'];
// sort conditions
$sortFields = array(array('field' => 'conditiontype', 'order' => ZBX_SORT_DOWN), array('field' => 'operator', 'order' => ZBX_SORT_DOWN), array('field' => 'value', 'order' => ZBX_SORT_DOWN));
CArrayHelper::sort($conditions, $sortFields);
$conditionsForFormula = array();
foreach ($conditions as $condition) {
$conditionsForFormula[$condition['conditionid']] = $condition['conditiontype'];
}
$formula = CConditionHelper::getFormula($conditionsForFormula, $filter['evaltype']);
}
// generate formulaids from the effective formula
$formulaIds = CConditionHelper::getFormulaIds($formula);
foreach ($filter['conditions'] as &$condition) {
$condition['formulaid'] = $formulaIds[$condition['conditionid']];
}
unset($condition);
// generated a letter based formula only for actions with custom expressions
if ($formulaRequested && $filter['evaltype'] == CONDITION_EVAL_TYPE_EXPRESSION) {
$filter['formula'] = CConditionHelper::replaceNumericIds($formula, $formulaIds);
}
if ($evalFormulaRequested) {
$filter['eval_formula'] = CConditionHelper::replaceNumericIds($formula, $formulaIds);
}
}
unset($filter);
}
// add filters to the result
foreach ($result as &$action) {
$action['filter'] = $filters[$action['actionid']];
}
unset($action);
}
// adding operations
if ($options['selectOperations'] !== null && $options['selectOperations'] != API_OUTPUT_COUNT) {
$operations = API::getApiService()->select('operations', array('output' => $this->outputExtend($options['selectOperations'], array('operationid', 'actionid', 'operationtype')), 'filter' => array('actionid' => $actionIds), 'preservekeys' => true));
$relationMap = $this->createRelationMap($operations, 'actionid', 'operationid');
$operationIds = $relationMap->getRelatedIds();
if ($this->outputIsRequested('opconditions', $options['selectOperations'])) {
foreach ($operations as &$operation) {
$operation['opconditions'] = array();
}
unset($operation);
$res = DBselect('SELECT op.* FROM opconditions op WHERE ' . dbConditionInt('op.operationid', $operationIds));
while ($opcondition = DBfetch($res)) {
$operations[$opcondition['operationid']]['opconditions'][] = $opcondition;
}
}
$opmessage = $opcommand = $opgroup = $optemplate = array();
foreach ($operations as $operationid => $operation) {
switch ($operation['operationtype']) {
case OPERATION_TYPE_MESSAGE:
$opmessage[] = $operationid;
break;
case OPERATION_TYPE_COMMAND:
$opcommand[] = $operationid;
break;
case OPERATION_TYPE_GROUP_ADD:
case OPERATION_TYPE_GROUP_REMOVE:
$opgroup[] = $operationid;
break;
case OPERATION_TYPE_TEMPLATE_ADD:
case OPERATION_TYPE_TEMPLATE_REMOVE:
$optemplate[] = $operationid;
break;
case OPERATION_TYPE_HOST_ADD:
case OPERATION_TYPE_HOST_REMOVE:
case OPERATION_TYPE_HOST_ENABLE:
case OPERATION_TYPE_HOST_DISABLE:
}
}
// get OPERATION_TYPE_MESSAGE data
if (!empty($opmessage)) {
if ($this->outputIsRequested('opmessage', $options['selectOperations'])) {
foreach ($opmessage as $operationId) {
$operations[$operationId]['opmessage'] = array();
}
$dbOpmessages = DBselect('SELECT o.operationid,o.default_msg,o.subject,o.message,o.mediatypeid' . ' FROM opmessage o' . ' WHERE ' . dbConditionInt('operationid', $opmessage));
while ($dbOpmessage = DBfetch($dbOpmessages)) {
//.........这里部分代码省略.........
示例11: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$graphids = array_keys($result);
// adding Items
if ($options['selectItems'] !== null && $options['selectItems'] !== API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'graphid', 'itemid', 'graphs_items');
$items = API::Item()->get(array('output' => $options['selectItems'], 'itemids' => $relationMap->getRelatedIds(), 'webitems' => true, 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapMany($result, $items, 'items');
}
// adding discoveryRule
if ($options['selectDiscoveryRule'] !== null) {
$dbRules = DBselect('SELECT id.parent_itemid,gd.graphid' . ' FROM graph_discovery gd,item_discovery id,graphs_items gi' . ' WHERE ' . dbConditionInt('gd.graphid', $graphids) . ' AND gd.parent_graphid=gi.graphid' . ' AND gi.itemid=id.itemid');
$relationMap = new CRelationMap();
while ($relation = DBfetch($dbRules)) {
$relationMap->addRelation($relation['graphid'], $relation['parent_itemid']);
}
$discoveryRules = API::DiscoveryRule()->get(array('output' => $options['selectDiscoveryRule'], 'itemids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule');
}
// adding graph discovery
if ($options['selectGraphDiscovery'] !== null) {
$graphDiscoveries = API::getApiService()->select('graph_discovery', array('output' => $this->outputExtend($options['selectGraphDiscovery'], array('graphid')), 'filter' => array('graphid' => array_keys($result)), 'preservekeys' => true));
$relationMap = $this->createRelationMap($graphDiscoveries, 'graphid', 'graphid');
$graphDiscoveries = $this->unsetExtraFields($graphDiscoveries, array('graphid'), $options['selectGraphDiscovery']);
$result = $relationMap->mapOne($result, $graphDiscoveries, 'graphDiscovery');
}
return $result;
}
示例12: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$itemIds = array_keys($result);
// adding items
if (!is_null($options['selectItems'])) {
if ($options['selectItems'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'parent_itemid', 'itemid', 'item_discovery');
$items = API::ItemPrototype()->get(array('output' => $options['selectItems'], 'itemids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapMany($result, $items, 'items', $options['limitSelects']);
} else {
$items = API::ItemPrototype()->get(array('discoveryids' => $itemIds, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true));
$items = zbx_toHash($items, 'parent_itemid');
foreach ($result as $itemid => $item) {
$result[$itemid]['items'] = isset($items[$itemid]) ? $items[$itemid]['rowscount'] : 0;
}
}
}
// adding triggers
if (!is_null($options['selectTriggers'])) {
if ($options['selectTriggers'] != API_OUTPUT_COUNT) {
$relationMap = new CRelationMap();
$res = DBselect('SELECT id.parent_itemid,f.triggerid' . ' FROM item_discovery id,items i,functions f' . ' WHERE ' . dbConditionInt('id.parent_itemid', $itemIds) . ' AND id.itemid=i.itemid' . ' AND i.itemid=f.itemid');
while ($relation = DBfetch($res)) {
$relationMap->addRelation($relation['parent_itemid'], $relation['triggerid']);
}
$triggers = API::TriggerPrototype()->get(array('output' => $options['selectTriggers'], 'triggerids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
$result = $relationMap->mapMany($result, $triggers, 'triggers', $options['limitSelects']);
} else {
$triggers = API::TriggerPrototype()->get(array('discoveryids' => $itemIds, 'countOutput' => true, 'groupCount' => true));
$triggers = zbx_toHash($triggers, 'parent_itemid');
foreach ($result as $itemid => $item) {
$result[$itemid]['triggers'] = isset($triggers[$itemid]) ? $triggers[$itemid]['rowscount'] : 0;
}
}
}
// adding graphs
if (!is_null($options['selectGraphs'])) {
if ($options['selectGraphs'] != API_OUTPUT_COUNT) {
$relationMap = new CRelationMap();
$res = DBselect('SELECT id.parent_itemid,gi.graphid' . ' FROM item_discovery id,items i,graphs_items gi' . ' WHERE ' . dbConditionInt('id.parent_itemid', $itemIds) . ' AND id.itemid=i.itemid' . ' AND i.itemid=gi.itemid');
while ($relation = DBfetch($res)) {
$relationMap->addRelation($relation['parent_itemid'], $relation['graphid']);
}
$graphs = API::GraphPrototype()->get(array('output' => $options['selectGraphs'], 'graphids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
$result = $relationMap->mapMany($result, $graphs, 'graphs', $options['limitSelects']);
} else {
$graphs = API::GraphPrototype()->get(array('discoveryids' => $itemIds, 'countOutput' => true, 'groupCount' => true));
$graphs = zbx_toHash($graphs, 'parent_itemid');
foreach ($result as $itemid => $item) {
$result[$itemid]['graphs'] = isset($graphs[$itemid]) ? $graphs[$itemid]['rowscount'] : 0;
}
}
}
// adding hosts
if ($options['selectHostPrototypes'] !== null) {
if ($options['selectHostPrototypes'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'parent_itemid', 'hostid', 'host_discovery');
$hostPrototypes = API::HostPrototype()->get(array('output' => $options['selectHostPrototypes'], 'hostids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapMany($result, $hostPrototypes, 'hostPrototypes', $options['limitSelects']);
} else {
$hostPrototypes = API::HostPrototype()->get(array('discoveryids' => $itemIds, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true));
$hostPrototypes = zbx_toHash($hostPrototypes, 'parent_itemid');
foreach ($result as $itemid => $item) {
$result[$itemid]['hostPrototypes'] = isset($hostPrototypes[$itemid]) ? $hostPrototypes[$itemid]['rowscount'] : 0;
}
}
}
if ($options['selectFilter'] !== null) {
$formulaRequested = $this->outputIsRequested('formula', $options['selectFilter']);
$evalFormulaRequested = $this->outputIsRequested('eval_formula', $options['selectFilter']);
$conditionsRequested = $this->outputIsRequested('conditions', $options['selectFilter']);
$filters = array();
foreach ($result as $rule) {
$filters[$rule['itemid']] = array('evaltype' => $rule['evaltype'], 'formula' => isset($rule['formula']) ? $rule['formula'] : '');
}
// adding conditions
if ($formulaRequested || $evalFormulaRequested || $conditionsRequested) {
$conditions = API::getApiService()->select('item_condition', array('output' => array('item_conditionid', 'macro', 'value', 'itemid', 'operator'), 'filter' => array('itemid' => $itemIds), 'preservekeys' => true, 'sortfield' => 'item_conditionid'));
$relationMap = $this->createRelationMap($conditions, 'itemid', 'item_conditionid');
$filters = $relationMap->mapMany($filters, $conditions, 'conditions');
foreach ($filters as &$filter) {
// in case of a custom expression - use the given formula
if ($filter['evaltype'] == CONDITION_EVAL_TYPE_EXPRESSION) {
$formula = $filter['formula'];
} else {
// sort the conditions by macro before generating the formula
$conditions = zbx_toHash($filter['conditions'], 'item_conditionid');
$conditions = order_macros($conditions, 'macro');
$formulaConditions = array();
foreach ($conditions as $condition) {
$formulaConditions[$condition['item_conditionid']] = $condition['macro'];
}
$formula = CConditionHelper::getFormula($formulaConditions, $filter['evaltype']);
}
// generate formulaids from the effective formula
$formulaIds = CConditionHelper::getFormulaIds($formula);
foreach ($filter['conditions'] as &$condition) {
$condition['formulaid'] = $formulaIds[$condition['item_conditionid']];
}
//.........这里部分代码省略.........
示例13: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$screenIds = array_keys($result);
// adding ScreenItems
if ($options['selectScreenItems'] !== null && $options['selectScreenItems'] != API_OUTPUT_COUNT) {
$screenItems = API::getApiService()->select('screens_items', array('output' => $this->outputExtend($options['selectScreenItems'], array('screenid', 'screenitemid')), 'filter' => array('screenid' => $screenIds), 'preservekeys' => true));
$relationMap = $this->createRelationMap($screenItems, 'screenid', 'screenitemid');
$screenItems = $this->unsetExtraFields($screenItems, array('screenid', 'screenitemid'), $options['selectScreenItems']);
$result = $relationMap->mapMany($result, $screenItems, 'screenitems');
}
return $result;
}
示例14: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$alertIds = array_keys($result);
// adding hosts
if ($options['selectHosts'] !== null && $options['selectHosts'] !== API_OUTPUT_COUNT) {
// trigger events
if ($options['eventobject'] == EVENT_OBJECT_TRIGGER) {
$query = DBselect('SELECT a.alertid,i.hostid' . ' FROM alerts a,events e,functions f,items i' . ' WHERE ' . dbConditionInt('a.alertid', $alertIds) . ' AND a.eventid=e.eventid' . ' AND e.objectid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND e.object=' . zbx_dbstr($options['eventobject']) . ' AND e.source=' . zbx_dbstr($options['eventsource']));
} elseif ($options['eventobject'] == EVENT_OBJECT_ITEM || $options['eventobject'] == EVENT_OBJECT_LLDRULE) {
$query = DBselect('SELECT a.alertid,i.hostid' . ' FROM alerts a,events e,items i' . ' WHERE ' . dbConditionInt('a.alertid', $alertIds) . ' AND a.eventid=e.eventid' . ' AND e.objectid=i.itemid' . ' AND e.object=' . zbx_dbstr($options['eventobject']) . ' AND e.source=' . zbx_dbstr($options['eventsource']));
}
$relationMap = new CRelationMap();
while ($relation = DBfetch($query)) {
$relationMap->addRelation($relation['alertid'], $relation['hostid']);
}
$hosts = API::Host()->get(['output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
$result = $relationMap->mapMany($result, $hosts, 'hosts');
}
// adding users
if ($options['selectUsers'] !== null && $options['selectUsers'] !== API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'alertid', 'userid');
$users = API::User()->get(['output' => $options['selectUsers'], 'userids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
$result = $relationMap->mapMany($result, $users, 'users');
}
// adding media types
if ($options['selectMediatypes'] !== null && $options['selectMediatypes'] !== API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'alertid', 'mediatypeid');
$mediatypes = API::getApiService()->select('media_type', ['output' => $options['selectMediatypes'], 'filter' => ['mediatypeid' => $relationMap->getRelatedIds()], 'preservekeys' => true]);
$result = $relationMap->mapMany($result, $mediatypes, 'mediatypes');
}
return $result;
}
示例15: update
/**
* Update existing drules.
*
* @param array(
* druleid => int,
* name => string,
* proxy_hostid => int,
* iprange => string,
* delay => string,
* status => int,
* dchecks => array(
* array(
* dcheckid => int,
* type => int,
* ports => string,
* key_ => string,
* snmp_community => string,
* snmpv3_securityname => string,
* snmpv3_securitylevel => int,
* snmpv3_authpassphrase => string,
* snmpv3_privpassphrase => string,
* uniq => int,
* ), ...
* )
* ) $dRules
*
* @return array
*/
public function update(array $dRules)
{
$this->checkInput($dRules);
$this->validateRequiredFields($dRules, __FUNCTION__);
$dRuleIds = zbx_objectValues($dRules, 'druleid');
$dRulesDb = API::DRule()->get(array('druleids' => $dRuleIds, 'output' => API_OUTPUT_EXTEND, 'selectDChecks' => API_OUTPUT_EXTEND, 'editable' => true, 'preservekeys' => true));
$defaultValues = DB::getDefaults('dchecks');
$dRulesUpdate = array();
$dCheckIdsDelete = array();
$dChecksCreate = array();
$dRuleNamesChanged = array();
// validate drule duplicate names
foreach ($dRules as $dRule) {
if (!isset($dRulesDb[$dRule['druleid']])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!'));
}
if ($dRulesDb[$dRule['druleid']]['name'] !== $dRule['name']) {
if (isset($dRuleNamesChanged[$dRule['name']])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Discovery rule "%1$s" already exists.', $dRule['name']));
} else {
$dRuleNamesChanged[$dRule['name']] = $dRule['name'];
}
}
}
if ($dRuleNamesChanged) {
$dbDRules = API::getApiService()->select($this->tableName(), array('output' => array('name'), 'filter' => array('name' => $dRuleNamesChanged), 'limit' => 1));
if ($dbDRules) {
$dbDRule = reset($dbDRules);
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Discovery rule "%1$s" already exists.', $dbDRule['name']));
}
}
foreach ($dRules as $dRule) {
$dRulesUpdate[] = array('values' => $dRule, 'where' => array('druleid' => $dRule['druleid']));
// update dchecks
$dbChecks = $dRulesDb[$dRule['druleid']]['dchecks'];
$newChecks = array();
$oldChecks = array();
foreach ($dRule['dchecks'] as $check) {
$check['druleid'] = $dRule['druleid'];
if (!isset($check['dcheckid'])) {
$newChecks[] = array_merge($defaultValues, $check);
} else {
$oldChecks[] = $check;
}
}
$delDCheckIds = array_diff(zbx_objectValues($dbChecks, 'dcheckid'), zbx_objectValues($oldChecks, 'dcheckid'));
if ($delDCheckIds) {
$this->deleteActionConditions($delDCheckIds);
}
DB::replace('dchecks', $dbChecks, array_merge($oldChecks, $newChecks));
}
DB::update('drules', $dRulesUpdate);
return array('druleids' => $dRuleIds);
}