本文整理汇总了PHP中API::getApi方法的典型用法代码示例。如果您正苦于以下问题:PHP API::getApi方法的具体用法?PHP API::getApi怎么用?PHP API::getApi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::getApi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$serviceIds = array_keys($result);
// selectDependencies
if ($options['selectDependencies'] !== null) {
$dependencyOutput = $this->extendOutputOption('services_links', 'serviceupid', $options['selectDependencies']);
$dependencies = $this->fetchChildDependencies($serviceIds, $dependencyOutput);
foreach ($result as &$service) {
$service['dependencies'] = array();
}
unset($service);
foreach ($dependencies as $dependency) {
$refId = $dependency['serviceupid'];
$dependency = $this->unsetExtraFields('services_links', $dependency, $options['selectDependencies']);
$result[$refId]['dependencies'][] = $dependency;
}
}
// selectParentDependencies
if ($options['selectParentDependencies'] !== null) {
$dependencyOutput = $this->extendOutputOption('services_links', 'servicedownid', $options['selectParentDependencies']);
$dependencies = $this->fetchParentDependencies($serviceIds, $dependencyOutput);
foreach ($result as &$service) {
$service['parentDependencies'] = array();
}
unset($service);
foreach ($dependencies as $dependency) {
$refId = $dependency['servicedownid'];
$dependency = $this->unsetExtraFields('services_links', $dependency, $options['selectParentDependencies']);
$result[$refId]['parentDependencies'][] = $dependency;
}
}
// selectParent
if ($options['selectParent'] !== null) {
$parents = $this->get(array('output' => $options['selectParent'], 'childids' => $serviceIds, 'selectDependencies' => array('servicedownid', 'soft')));
foreach ($result as &$service) {
$service['parent'] = array();
}
unset($service);
// map the parents to their children, look for the first hard linked dependency
foreach ($parents as $parent) {
foreach ($parent['dependencies'] as $dependency) {
if (!$dependency['soft']) {
unset($parent['dependencies']);
if (isset($result[$dependency['servicedownid']])) {
$result[$dependency['servicedownid']]['parent'] = $parent;
}
}
}
}
}
// selectTimes
if ($options['selectTimes'] !== null) {
$timesOutput = $this->extendOutputOption('services_times', array('serviceid', 'type'), $options['selectTimes']);
$serviceTimes = API::getApi()->select('services_times', array('output' => $timesOutput, 'filter' => array('serviceid' => $serviceIds)));
foreach ($result as &$service) {
$service['times'] = array();
}
unset($service);
foreach ($serviceTimes as $serviceTime) {
$refId = $serviceTime['serviceid'];
// convert periodical service time timestamps from old 1.8 format
if ($serviceTime['type'] == SERVICE_TIME_TYPE_UPTIME || $serviceTime['type'] == SERVICE_TIME_TYPE_DOWNTIME) {
if (isset($serviceTime['ts_from'])) {
$serviceTime['ts_from'] = prepareServiceTime($serviceTime['ts_from']);
}
if (isset($serviceTime['ts_to'])) {
$serviceTime['ts_to'] = prepareServiceTime($serviceTime['ts_to']);
}
}
$serviceTime = $this->unsetExtraFields('services_times', $serviceTime, $options['selectTimes']);
$result[$refId]['times'][] = $serviceTime;
}
}
// selectAlarms
if ($options['selectAlarms'] !== null) {
$alarmsOutput = $this->extendOutputOption('service_alarms', 'serviceid', $options['selectAlarms']);
$alarmsTimes = API::getApi()->select('service_alarms', array('output' => $alarmsOutput, 'filter' => array('serviceid' => $serviceIds)));
foreach ($result as &$service) {
$service['times'] = array();
}
unset($service);
foreach ($alarmsTimes as $serviceAlarm) {
$refId = $serviceAlarm['serviceid'];
$serviceAlarm = $this->unsetExtraFields('service_alarms', $serviceAlarm, $options['selectAlarms']);
$result[$refId]['times'][] = $serviceAlarm;
}
}
// selectTrigger
if ($options['selectTrigger'] !== null) {
$triggers = API::getApi()->select('triggers', array('output' => $options['selectTrigger'], 'triggerids' => array_unique(zbx_objectValues($result, 'triggerid')), 'preservekeys' => true));
foreach ($result as &$service) {
$service['trigger'] = $service['triggerid'] ? $triggers[$service['triggerid']] : array();
}
unset($service);
}
return $result;
}
示例2: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$triggerids = array_keys($result);
// adding groups
if ($options['selectGroups'] !== null && $options['selectGroups'] != API_OUTPUT_COUNT) {
$res = DBselect('SELECT f.triggerid,hg.groupid' . ' FROM functions f,items i,hosts_groups hg' . ' WHERE ' . dbConditionInt('f.triggerid', $triggerids) . ' AND f.itemid=i.itemid' . ' AND i.hostid=hg.hostid');
$relationMap = new CRelationMap();
while ($relation = DBfetch($res)) {
$relationMap->addRelation($relation['triggerid'], $relation['groupid']);
}
$groups = API::HostGroup()->get(array('nodeids' => $options['nodeids'], 'output' => $options['selectGroups'], 'groupids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
$result = $relationMap->mapMany($result, $groups, 'groups');
}
// adding hosts
if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) {
$res = DBselect('SELECT f.triggerid,i.hostid' . ' FROM functions f,items i' . ' WHERE ' . dbConditionInt('f.triggerid', $triggerids) . ' AND f.itemid=i.itemid');
$relationMap = new CRelationMap();
while ($relation = DBfetch($res)) {
$relationMap->addRelation($relation['triggerid'], $relation['hostid']);
}
$hosts = API::Host()->get(array('output' => $options['selectHosts'], 'nodeids' => $options['nodeids'], 'hostids' => $relationMap->getRelatedIds(), 'templated_hosts' => true, 'nopermissions' => true, 'preservekeys' => true));
if (!is_null($options['limitSelects'])) {
order_result($hosts, 'host');
}
$result = $relationMap->mapMany($result, $hosts, 'hosts', $options['limitSelects']);
}
// adding functions
if ($options['selectFunctions'] !== null && $options['selectFunctions'] != API_OUTPUT_COUNT) {
$functions = API::getApi()->select('functions', array('output' => $this->outputExtend('functions', array('triggerid', 'functionid'), $options['selectFunctions']), 'filter' => array('triggerid' => $triggerids), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
$relationMap = $this->createRelationMap($functions, 'triggerid', 'functionid');
$functions = $this->unsetExtraFields($functions, array('triggerid', 'functionid'), $options['selectFunctions']);
$result = $relationMap->mapMany($result, $functions, 'functions');
}
return $result;
}
示例3: 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::getApi()->select('host_inventory', array('output' => $options['selectInventory'], 'filter' => array('hostid' => $hostids), 'nodeids' => get_current_nodeid(true)));
$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(array('output' => $this->outputExtend('interface', array('hostid', 'interfaceid'), $options['selectInterfaces']), 'nodeids' => $options['nodeids'], '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, array('hostid', 'interfaceid'), $options['selectInterfaces']);
$result = $relationMap->mapMany($result, $interfaces, 'interfaces', $options['limitSelects']);
} else {
$interfaces = API::HostInterface()->get(array('nodeids' => $options['nodeids'], '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(array('output' => $this->outputExtend('screens', 'hostid', $options['selectScreens']), 'nodeids' => $options['nodeids'], '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, array('hostid'), $options['selectScreens']);
$result = $relationMap->mapMany($result, $screens, 'screens', $options['limitSelects']);
} else {
$screens = API::TemplateScreen()->get(array('nodeids' => $options['nodeids'], '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(array('output' => $options['selectDiscoveryRule'], 'nodeids' => $options['nodeids'], 'itemids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
$result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule');
}
// adding host discovery
if ($options['selectHostDiscovery'] !== null) {
$hostDiscoveries = API::getApi()->select('host_discovery', array('output' => $this->outputExtend('host_discovery', array('hostid'), $options['selectHostDiscovery']), 'filter' => array('hostid' => $hostids), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
$relationMap = $this->createRelationMap($hostDiscoveries, 'hostid', 'hostid');
$hostDiscoveries = $this->unsetExtraFields($hostDiscoveries, array('hostid'), $options['selectHostDiscovery']);
$result = $relationMap->mapOne($result, $hostDiscoveries, 'hostDiscovery');
}
return $result;
}
示例4: checkCanBeAcknowledged
/**
* Checks if the given events exist, are accessible and can be acknowledged.
*
* @throws APIException if an event does not exist, is not accessible or is not a trigger event
*
* @param array $eventIds
*
* @return void
*/
protected function checkCanBeAcknowledged(array $eventIds)
{
$allowedEvents = $this->get(array('eventids' => $eventIds, 'output' => API_OUTPUT_REFER, 'preservekeys' => true));
foreach ($eventIds as $eventId) {
if (!isset($allowedEvents[$eventId])) {
// check if an event actually exists but maybe belongs to a different source or object
$event = API::getApi()->select($this->tableName(), array('output' => array('eventid', 'source', 'object'), 'eventids' => $eventId, 'limit' => 1));
$event = reset($event);
// if the event exists, check if we have permissions to access it
if ($event) {
$event = $this->get(array('output' => array('eventid'), 'eventids' => $event['eventid'], 'source' => $event['source'], 'object' => $event['object'], 'limit' => 1));
}
// the event exists, is accessible but belongs to a different object or source
if ($event) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('Only trigger events can be acknowledged.'));
} else {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
}
}
}
}
示例5: addRelatedObjects
public function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$itemids = array_keys($result);
// adding applications
if ($options['selectApplications'] !== null && $options['selectApplications'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'itemid', 'applicationid', 'items_applications');
$applications = API::Application()->get(array('output' => $options['selectApplications'], 'nodeids' => $options['nodeids'], 'applicationids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
$result = $relationMap->mapMany($result, $applications, 'applications');
}
// adding interfaces
if ($options['selectInterfaces'] !== null && $options['selectInterfaces'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'itemid', 'interfaceid');
$interfaces = API::HostInterface()->get(array('nodeids' => $options['nodeids'], 'output' => $options['selectInterfaces'], 'intefaceids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapMany($result, $interfaces, 'interfaces');
}
// adding triggers
if (!is_null($options['selectTriggers'])) {
if ($options['selectTriggers'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'itemid', 'triggerid', 'functions');
$triggers = API::Trigger()->get(array('output' => $options['selectTriggers'], 'nodeids' => $options['nodeids'], 'triggerids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
if (!is_null($options['limitSelects'])) {
order_result($triggers, 'description');
}
$result = $relationMap->mapMany($result, $triggers, 'triggers', $options['limitSelects']);
} else {
$triggers = API::Trigger()->get(array('countOutput' => true, 'groupCount' => true, 'nodeids' => $options['nodeids'], 'itemids' => $itemids));
$triggers = zbx_toHash($triggers, 'itemid');
foreach ($result as $itemid => $item) {
if (isset($triggers[$itemid])) {
$result[$itemid]['triggers'] = $triggers[$itemid]['rowscount'];
} else {
$result[$itemid]['triggers'] = 0;
}
}
}
}
// adding graphs
if (!is_null($options['selectGraphs'])) {
if ($options['selectGraphs'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'itemid', 'graphid', 'graphs_items');
$graphs = API::Graph()->get(array('output' => $options['selectGraphs'], 'nodeids' => $options['nodeids'], 'graphids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
if (!is_null($options['limitSelects'])) {
order_result($graphs, 'name');
}
$result = $relationMap->mapMany($result, $graphs, 'graphs', $options['limitSelects']);
} else {
$graphs = API::Graph()->get(array('countOutput' => true, 'groupCount' => true, 'nodeids' => $options['nodeids'], 'itemids' => $itemids));
$graphs = zbx_toHash($graphs, 'itemid');
foreach ($result as $itemid => $item) {
if (isset($graphs[$itemid])) {
$result[$itemid]['graphs'] = $graphs[$itemid]['rowscount'];
} else {
$result[$itemid]['graphs'] = 0;
}
}
}
}
// adding discoveryrule
if ($options['selectDiscoveryRule'] !== null && $options['selectDiscoveryRule'] != API_OUTPUT_COUNT) {
$relationMap = new CRelationMap();
// discovered items
$dbRules = DBselect('SELECT id1.itemid,id2.parent_itemid' . ' FROM item_discovery id1,item_discovery id2,items i' . ' WHERE ' . dbConditionInt('id1.itemid', $itemids) . ' AND id1.parent_itemid=id2.itemid' . ' AND i.itemid=id1.itemid' . ' AND i.flags=' . ZBX_FLAG_DISCOVERY_CREATED);
while ($rule = DBfetch($dbRules)) {
$relationMap->addRelation($rule['itemid'], $rule['parent_itemid']);
}
// item prototypes
// TODO: this should not be in the item API
$dbRules = DBselect('SELECT id.parent_itemid,id.itemid' . ' FROM item_discovery id,items i' . ' WHERE ' . dbConditionInt('id.itemid', $itemids) . ' AND i.itemid=id.itemid' . ' AND i.flags=' . ZBX_FLAG_DISCOVERY_PROTOTYPE);
while ($rule = DBfetch($dbRules)) {
$relationMap->addRelation($rule['itemid'], $rule['parent_itemid']);
}
$discoveryRules = API::DiscoveryRule()->get(array('output' => $options['selectDiscoveryRule'], 'nodeids' => $options['nodeids'], 'itemids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule');
}
// adding item discovery
if ($options['selectItemDiscovery'] !== null) {
$itemDiscoveries = API::getApi()->select('item_discovery', array('output' => $this->outputExtend('item_discovery', array('itemdiscoveryid', 'itemid'), $options['selectItemDiscovery']), 'filter' => array('itemid' => array_keys($result)), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
$relationMap = $this->createRelationMap($itemDiscoveries, 'itemid', 'itemdiscoveryid');
$itemDiscoveries = $this->unsetExtraFields($itemDiscoveries, array('itemid', 'itemdiscoveryid'), $options['selectItemDiscovery']);
$result = $relationMap->mapOne($result, $itemDiscoveries, 'itemDiscovery');
}
// adding history data
$requestedOutput = array();
if ($this->outputIsRequested('lastclock', $options['output'])) {
$requestedOutput['lastclock'] = true;
}
if ($this->outputIsRequested('lastns', $options['output'])) {
$requestedOutput['lastns'] = true;
}
if ($this->outputIsRequested('lastvalue', $options['output'])) {
$requestedOutput['lastvalue'] = true;
}
if ($this->outputIsRequested('prevvalue', $options['output'])) {
$requestedOutput['prevvalue'] = true;
}
if ($requestedOutput) {
$history = Manager::History()->getLast($result, 2);
foreach ($result as &$item) {
$lastHistory = isset($history[$item['itemid']][0]) ? $history[$item['itemid']][0] : null;
//.........这里部分代码省略.........
示例6: extendObjects
/**
* Fetches the fields given in $fields from the database and extends the objects with the loaded data.
*
* @param $tableName
* @param array $objects
* @param array $fields
*
* @return array
*/
protected function extendObjects($tableName, array $objects, array $fields)
{
$dbObjects = API::getApi()->select($tableName, array('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);
}
}
return $objects;
}
示例7: 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::getApi()->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));
}
}
}
示例8: get
//.........这里部分代码省略.........
$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 ($screen = DBfetch($res)) {
if (!is_null($options['countOutput'])) {
if (!is_null($options['groupCount'])) {
$result[] = $screen;
} else {
$result = $screen['rowscount'];
}
} else {
if (!isset($result[$screen['screenid']])) {
$result[$screen['screenid']] = array();
}
if (isset($screen['screenitemid']) && is_null($options['selectScreenItems'])) {
if (!isset($result[$screen['screenid']]['screenitems'])) {
$result[$screen['screenid']]['screenitems'] = array();
}
$result[$screen['screenid']]['screenitems'][] = array('screenitemid' => $screen['screenitemid']);
unset($screen['screenitemid']);
}
$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::getApi()->select('screens_items', array('output' => $this->outputExtend('screens_items', array('screenid', 'screenitemid', 'resourcetype', 'resourceid'), $options['selectScreenItems']), 'filter' => array('screenid' => $screenIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(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: validateUpdate
/**
* Validates the input parameters for the update() method.
*
* @throws APIException if the input is invalid
*
* @param array $screenItems
*
* @return void
*/
protected function validateUpdate(array $screenItems)
{
foreach ($screenItems as $screenItem) {
if (empty($screenItem['screenitemid'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Invalid method parameters.'));
}
}
$screenItemIds = zbx_objectValues($screenItems, 'screenitemid');
$screens = API::getApi()->select('screens', array('output' => array('screenid', 'hsize', 'vsize'), 'screenitemids' => $screenItemIds, 'preservekeys' => true));
$screenItems = $this->extendObjects($this->tableName(), $screenItems, array('screenid', 'x', 'y', 'rowspan', 'colspan'));
foreach ($screenItems as $screenItem) {
$screen = $screens[$screenItem['screenid']];
$this->checkSpans($screenItem);
$this->checkSpansInBounds($screenItem, $screen);
}
// old validation
// fetch the items we're updating
$dbScreenItems = API::getApi()->select('screens_items', array('screenitemids' => $screenItemIds, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true));
// validate input
$this->checkInput($screenItems, $dbScreenItems);
}
示例10: addRelatedObjects
public function addRelatedObjects(array $options, array $result)
{
// TODO: move selectItemHosts to CItemGeneral::addRelatedObjects();
// TODO: move selectInterfaces to CItemGeneral::addRelatedObjects();
// TODO: move selectTriggers to CItemGeneral::addRelatedObjects();
// TODO: move selectGraphs to CItemGeneral::addRelatedObjects();
// TODO: move selectApplications to CItemGeneral::addRelatedObjects();
$result = parent::addRelatedObjects($options, $result);
$itemids = zbx_objectValues($result, 'itemid');
// adding item discovery
if ($options['selectItemDiscovery']) {
$itemDiscoveryOutput = $this->extendOutputOption('item_discovery', 'itemid', $options['selectItemDiscovery']);
$itemDiscoveries = API::getApi()->select('item_discovery', array('output' => $itemDiscoveryOutput, 'filter' => array('itemid' => $itemids)));
foreach ($itemDiscoveries as $itemDiscovery) {
$refId = $itemDiscovery['itemid'];
$itemDiscovery = $this->unsetExtraFields('item_discovery', $itemDiscovery, $options['selectItemDiscovery']);
$result[$refId]['itemDiscovery'] = $itemDiscovery;
}
}
return $result;
}
示例11: 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::getApi()->select('screens_items', array('output' => $this->outputExtend('screens_items', array('screenid', 'screenitemid'), $options['selectScreenItems']), 'filter' => array('screenid' => $screenIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
$relationMap = $this->createRelationMap($screenItems, 'screenid', 'screenitemid');
$screenItems = $this->unsetExtraFields($screenItems, array('screenid', 'screenitemid'), $options['selectScreenItems']);
$result = $relationMap->mapMany($result, $screenItems, 'screenitems');
}
return $result;
}
示例12: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$hostPrototypeIds = array_keys($result);
// adding discovery rule
if ($options['selectDiscoveryRule'] !== null && $options['selectDiscoveryRule'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'hostid', 'parent_itemid', 'host_discovery');
$discoveryRules = API::DiscoveryRule()->get(array('output' => $options['selectDiscoveryRule'], 'nodeids' => $options['nodeids'], 'itemids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule');
}
// adding group links
if ($options['selectGroupLinks'] !== null && $options['selectGroupLinks'] != API_OUTPUT_COUNT) {
$groupPrototypes = DBFetchArray(DBselect('SELECT hg.group_prototypeid,hg.hostid' . ' FROM group_prototype hg' . ' WHERE ' . dbConditionInt('hg.hostid', $hostPrototypeIds) . ' AND hg.groupid IS NOT NULL'));
$relationMap = $this->createRelationMap($groupPrototypes, 'hostid', 'group_prototypeid');
$groupPrototypes = API::getApi()->select('group_prototype', array('output' => $options['selectGroupLinks'], 'nodeids' => $options['nodeids'], 'group_prototypeids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
foreach ($groupPrototypes as &$groupPrototype) {
unset($groupPrototype['name']);
}
unset($groupPrototype);
$result = $relationMap->mapMany($result, $groupPrototypes, 'groupLinks');
}
// adding group prototypes
if ($options['selectGroupPrototypes'] !== null && $options['selectGroupPrototypes'] != API_OUTPUT_COUNT) {
$groupPrototypes = DBFetchArray(DBselect('SELECT hg.group_prototypeid,hg.hostid' . ' FROM group_prototype hg' . ' WHERE ' . dbConditionInt('hg.hostid', $hostPrototypeIds) . ' AND hg.groupid IS NULL'));
$relationMap = $this->createRelationMap($groupPrototypes, 'hostid', 'group_prototypeid');
$groupPrototypes = API::getApi()->select('group_prototype', array('output' => $options['selectGroupPrototypes'], 'nodeids' => $options['nodeids'], 'group_prototypeids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
foreach ($groupPrototypes as &$groupPrototype) {
unset($groupPrototype['groupid']);
}
unset($groupPrototype);
$result = $relationMap->mapMany($result, $groupPrototypes, 'groupPrototypes');
}
// adding host
if ($options['selectParentHost'] !== null && $options['selectParentHost'] != API_OUTPUT_COUNT) {
$relationMap = new CRelationMap();
$dbRules = DBselect('SELECT hd.hostid,i.hostid AS parent_hostid' . ' FROM host_discovery hd,items i' . ' WHERE ' . dbConditionInt('hd.hostid', $hostPrototypeIds) . ' AND hd.parent_itemid=i.itemid');
while ($relation = DBfetch($dbRules)) {
$relationMap->addRelation($relation['hostid'], $relation['parent_hostid']);
}
$hosts = API::Host()->get(array('output' => $options['selectParentHost'], 'nodeids' => $options['nodeids'], 'hostids' => $relationMap->getRelatedIds(), 'templated_hosts' => true, 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapOne($result, $hosts, 'parentHost');
}
// adding templates
if ($options['selectTemplates'] !== null) {
if ($options['selectTemplates'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'hostid', 'templateid', 'hosts_templates');
$templates = API::Template()->get(array('output' => $options['selectTemplates'], 'nodeids' => $options['nodeids'], 'templateids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
$result = $relationMap->mapMany($result, $templates, 'templates');
} else {
$templates = API::Template()->get(array('nodeids' => $options['nodeids'], 'hostids' => $hostPrototypeIds, 'countOutput' => true, 'groupCount' => true));
$templates = zbx_toHash($templates, 'hostid');
foreach ($result as $hostid => $host) {
$result[$hostid]['templates'] = isset($templates[$hostid]) ? $templates[$hostid]['rowscount'] : 0;
}
}
}
// adding inventory
if ($options['selectInventory'] !== null) {
$relationMap = $this->createRelationMap($result, 'hostid', 'hostid');
// only allow to retrieve the hostid and inventory_mode fields
$output = array();
if ($this->outputIsRequested('hostid', $options['selectInventory'])) {
$output[] = 'hostid';
}
if ($this->outputIsRequested('inventory_mode', $options['selectInventory'])) {
$output[] = 'inventory_mode';
}
$inventory = API::getApi()->select('host_inventory', array('output' => $output, 'filter' => array('hostid' => $hostPrototypeIds), 'nodeids' => get_current_nodeid(true)));
$result = $relationMap->mapOne($result, zbx_toHash($inventory, 'hostid'), 'inventory');
}
return $result;
}
示例13: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$serviceIds = array_keys($result);
// selectDependencies
if ($options['selectDependencies'] !== null && $options['selectDependencies'] != API_OUTPUT_COUNT) {
$dependencies = $this->fetchChildDependencies($serviceIds, $this->outputExtend('services_links', array('serviceupid', 'linkid'), $options['selectDependencies']));
$dependencies = zbx_toHash($dependencies, 'linkid');
$relationMap = $this->createRelationMap($dependencies, 'serviceupid', 'linkid');
$dependencies = $this->unsetExtraFields($dependencies, array('serviceupid', 'linkid'), $options['selectDependencies']);
$result = $relationMap->mapMany($result, $dependencies, 'dependencies');
}
// selectParentDependencies
if ($options['selectParentDependencies'] !== null && $options['selectParentDependencies'] != API_OUTPUT_COUNT) {
$dependencies = $this->fetchParentDependencies($serviceIds, $this->outputExtend('services_links', array('servicedownid', 'linkid'), $options['selectParentDependencies']));
$dependencies = zbx_toHash($dependencies, 'linkid');
$relationMap = $this->createRelationMap($dependencies, 'servicedownid', 'linkid');
$dependencies = $this->unsetExtraFields($dependencies, array('servicedownid', 'linkid'), $options['selectParentDependencies']);
$result = $relationMap->mapMany($result, $dependencies, 'parentDependencies');
}
// selectParent
if ($options['selectParent'] !== null && $options['selectParent'] != API_OUTPUT_COUNT) {
$dependencies = $this->fetchParentDependencies($serviceIds, array('servicedownid', 'serviceupid'), false);
$relationMap = $this->createRelationMap($dependencies, 'servicedownid', 'serviceupid');
$parents = $this->get(array('output' => $options['selectParent'], 'serviceids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
$result = $relationMap->mapOne($result, $parents, 'parent');
}
// selectTimes
if ($options['selectTimes'] !== null && $options['selectTimes'] != API_OUTPUT_COUNT) {
$serviceTimes = API::getApi()->select('services_times', array('output' => $this->outputExtend('services_times', array('serviceid', 'timeid'), $options['selectTimes']), 'filter' => array('serviceid' => $serviceIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
$relationMap = $this->createRelationMap($serviceTimes, 'serviceid', 'timeid');
$serviceTimes = $this->unsetExtraFields($serviceTimes, array('serviceid', 'timeid'), $options['selectTimes']);
$result = $relationMap->mapMany($result, $serviceTimes, 'times');
}
// selectAlarms
if ($options['selectAlarms'] !== null && $options['selectAlarms'] != API_OUTPUT_COUNT) {
$serviceAlarms = API::getApi()->select('service_alarms', array('output' => $this->outputExtend('service_alarms', array('serviceid', 'servicealarmid'), $options['selectAlarms']), 'filter' => array('serviceid' => $serviceIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
$relationMap = $this->createRelationMap($serviceAlarms, 'serviceid', 'servicealarmid');
$serviceAlarms = $this->unsetExtraFields($serviceAlarms, array('serviceid', 'servicealarmid'), $options['selectAlarms']);
$result = $relationMap->mapMany($result, $serviceAlarms, 'alarms');
}
// selectTrigger
if ($options['selectTrigger'] !== null && $options['selectTrigger'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'serviceid', 'triggerid');
$triggers = API::getApi()->select('triggers', array('output' => $options['selectTrigger'], 'triggerids' => $relationMap->getRelatedIds(), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
$result = $relationMap->mapOne($result, $triggers, 'trigger');
}
return $result;
}
示例14: 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::getApi()->select('icon_mapping', array('output' => $this->outputExtend('icon_mapping', array('iconmapid', 'iconmappingid'), $options['selectMappings']), 'filter' => array('iconmapid' => $iconMapIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
$relationMap = $this->createRelationMap($mappings, 'iconmapid', 'iconmappingid');
$mappings = $this->unsetExtraFields($mappings, array('iconmapid', 'iconmappingid'), $options['selectMappings']);
$result = $relationMap->mapMany($result, $mappings, 'mappings');
}
return $result;
}
示例15: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$sysmapIds = array_keys($result);
// adding elements
if ($options['selectSelements'] !== null && $options['selectSelements'] != API_OUTPUT_COUNT) {
$selements = API::getApi()->select('sysmaps_elements', array('output' => $this->outputExtend('sysmaps_elements', array('selementid', 'sysmapid'), $options['selectSelements']), 'filter' => array('sysmapid' => $sysmapIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
$relationMap = $this->createRelationMap($selements, 'sysmapid', 'selementid');
// add selement URLs
if ($this->outputIsRequested('urls', $options['selectSelements'])) {
foreach ($selements as &$selement) {
$selement['urls'] = array();
}
unset($selement);
if (!is_null($options['expandUrls'])) {
$dbMapUrls = DBselect('SELECT su.sysmapurlid,su.sysmapid,su.name,su.url,su.elementtype' . ' FROM sysmap_url su' . ' WHERE ' . dbConditionInt('su.sysmapid', $sysmapIds));
while ($mapUrl = DBfetch($dbMapUrls)) {
foreach ($selements as $snum => $selement) {
if (bccomp($selement['sysmapid'], $mapUrl['sysmapid']) == 0 && ($selement['elementtype'] == $mapUrl['elementtype'] && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP || $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS && $mapUrl['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST)) {
$selements[$snum]['urls'][] = $this->expandUrlMacro($mapUrl, $selement);
}
}
}
}
$dbSelementUrls = DBselect('SELECT seu.sysmapelementurlid,seu.selementid,seu.name,seu.url' . ' FROM sysmap_element_url seu' . ' WHERE ' . dbConditionInt('seu.selementid', array_keys($selements)));
while ($selementUrl = DBfetch($dbSelementUrls)) {
$selements[$selementUrl['selementid']]['urls'][] = is_null($options['expandUrls']) ? $selementUrl : $this->expandUrlMacro($selementUrl, $selements[$selementUrl['selementid']]);
}
}
$selements = $this->unsetExtraFields($selements, array('sysmapid', 'selementid'), $options['selectSelements']);
$result = $relationMap->mapMany($result, $selements, 'selements');
}
// adding icon maps
if ($options['selectIconMap'] !== null && $options['selectIconMap'] != API_OUTPUT_COUNT) {
$iconMaps = API::IconMap()->get(array('output' => $this->outputExtend('icon_map', array('sysmapid', 'iconmapid'), $options['selectIconMap']), 'sysmapids' => $sysmapIds, 'preservekeys' => true, 'nopermissions' => true));
$relationMap = $this->createRelationMap($iconMaps, 'sysmapid', 'iconmapid');
$iconMaps = $this->unsetExtraFields($iconMaps, array('sysmapid', 'iconmapid'), $options['selectIconMap']);
$result = $relationMap->mapOne($result, $iconMaps, 'iconmap');
}
// adding links
if ($options['selectLinks'] !== null && $options['selectLinks'] != API_OUTPUT_COUNT) {
$links = API::getApi()->select('sysmaps_links', array('output' => $this->outputExtend('sysmaps_links', array('sysmapid', 'linkid'), $options['selectLinks']), 'filter' => array('sysmapid' => $sysmapIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
$relationMap = $this->createRelationMap($links, 'sysmapid', 'linkid');
// add link triggers
if ($this->outputIsRequested('linktriggers', $options['selectLinks'])) {
$linkTriggers = DBFetchArrayAssoc(DBselect('SELECT DISTINCT slt.*' . ' FROM sysmaps_link_triggers slt' . ' WHERE ' . dbConditionInt('slt.linkid', $relationMap->getRelatedIds())), 'linktriggerid');
$linkTriggerRelationMap = $this->createRelationMap($linkTriggers, 'linkid', 'linktriggerid');
$links = $linkTriggerRelationMap->mapMany($links, $linkTriggers, 'linktriggers');
}
$links = $this->unsetExtraFields($links, array('sysmapid', 'linkid'), $options['selectLinks']);
$result = $relationMap->mapMany($result, $links, 'links');
}
// adding urls
if ($options['selectUrls'] !== null && $options['selectUrls'] != API_OUTPUT_COUNT) {
$links = API::getApi()->select('sysmap_url', array('output' => $this->outputExtend('sysmap_url', array('sysmapid', 'sysmapurlid'), $options['selectUrls']), 'filter' => array('sysmapid' => $sysmapIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
$relationMap = $this->createRelationMap($links, 'sysmapid', 'sysmapurlid');
$links = $this->unsetExtraFields($links, array('sysmapid', 'sysmapurlid'), $options['selectUrls']);
$result = $relationMap->mapMany($result, $links, 'urls');
}
return $result;
}