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; }
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; }
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; }
/** * 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!')); } } } }
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; $prevHistory = isset($history[$item['itemid']][1]) ? $history[$item['itemid']][1] : null; if (isset($requestedOutput['lastclock'])) { $item['lastclock'] = $lastHistory ? $lastHistory['clock'] : '0'; } if (isset($requestedOutput['lastns'])) { $item['lastns'] = $lastHistory ? $lastHistory['ns'] : '0'; } if (isset($requestedOutput['lastvalue'])) { $item['lastvalue'] = $lastHistory ? $lastHistory['value'] : '0'; } if (isset($requestedOutput['prevvalue'])) { $item['prevvalue'] = $prevHistory ? $prevHistory['value'] : '0'; } } unset($item); } return $result; }
/** * 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; }
/** * 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)); } } }
/** * Get screen data. * * @param array $options * @param array $options['nodeids'] Node IDs * @param bool $options['with_items'] only with items * @param bool $options['editable'] only with read-write permission. Ignored for SuperAdmins * @param int $options['count'] count Hosts, returned column name is rowscount * @param string $options['pattern'] search hosts by pattern in host names * @param int $options['limit'] limit selection * @param string $options['order'] deprecated parameter (for now) * * @return array */ public function get($options = array()) { $result = array(); $userType = self::$userData['type']; $userid = self::$userData['userid']; $sqlParts = array('select' => array('screens' => 's.screenid,s.templateid'), 'from' => array('screens' => 'screens s'), 'where' => array('template' => 's.templateid IS NOT NULL'), 'order' => array(), 'group' => array(), 'limit' => null); $defOptions = array('nodeids' => null, 'screenids' => null, 'screenitemids' => null, 'templateids' => null, 'hostids' => null, 'editable' => null, 'noInheritance' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectScreenItems' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null); $options = zbx_array_merge($defOptions, $options); if (!is_null($options['editable']) || is_null($options['hostids']) && is_null($options['templateids'])) { $options['noInheritance'] = 1; } // editable + PERMISSION CHECK if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) { // TODO: think how we could combine templateids && hostids options if (!is_null($options['templateids'])) { unset($options['hostids']); $options['templateids'] = API::Template()->get(array('templateids' => $options['templateids'], 'editable' => $options['editable'], 'preservekeys' => true)); $options['templateids'] = array_keys($options['templateids']); } elseif (!is_null($options['hostids'])) { $options['templateids'] = API::Host()->get(array('hostids' => $options['hostids'], 'editable' => $options['editable'], 'preservekeys' => true)); $options['templateids'] = array_keys($options['templateids']); } else { // TODO: get screen $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 s.templateid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ' AND MAX(r.permission)>=' . $permission . ')'; } } // nodeids $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid(); // screenids if (!is_null($options['screenids'])) { zbx_value2array($options['screenids']); $sqlParts['where'][] = dbConditionInt('s.screenid', $options['screenids']); } // screenitemids if (!is_null($options['screenitemids'])) { zbx_value2array($options['screenitemids']); if ($options['output'] != API_OUTPUT_EXTEND) { $sqlParts['select']['screenitemid'] = 'si.screenitemid'; } $sqlParts['from']['screens_items'] = 'screens_items si'; $sqlParts['where']['ssi'] = 'si.screenid=s.screenid'; $sqlParts['where'][] = dbConditionInt('si.screenitemid', $options['screenitemids']); } // templateids if (!is_null($options['templateids'])) { zbx_value2array($options['templateids']); if (isset($options['hostids']) && !is_null($options['hostids'])) { zbx_value2array($options['hostids']); $options['hostids'] = array_merge($options['hostids'], $options['templateids']); } else { $options['hostids'] = $options['templateids']; } } // hostids $templatesChain = array(); if (!is_null($options['hostids'])) { zbx_value2array($options['hostids']); // collecting template chain $linkedTemplateids = $options['hostids']; $childTemplateids = $options['hostids']; while (is_null($options['noInheritance']) && !empty($childTemplateids)) { $sql = 'SELECT ht.*' . ' FROM hosts_templates ht' . ' WHERE ' . dbConditionInt('hostid', $childTemplateids); $dbTemplates = DBselect($sql); $childTemplateids = array(); while ($link = DBfetch($dbTemplates)) { $childTemplateids[$link['templateid']] = $link['templateid']; $linkedTemplateids[$link['templateid']] = $link['templateid']; createParentToChildRelation($templatesChain, $link, 'templateid', 'hostid'); } } if (!is_null($options['groupCount'])) { $sqlParts['group']['templateid'] = 's.templateid'; } $sqlParts['where']['templateid'] = dbConditionInt('s.templateid', $linkedTemplateids); } // 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); $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 if (!empty($itemids)) { $tplItems = API::Item()->get(array('output' => array('itemid', 'key_', 'hostid'), 'itemids' => $itemids, 'nopermissions' => true, 'preservekeys' => true)); $dbItems = API::Item()->get(array('output' => array('itemid', 'key_', 'hostid'), 'hostids' => $options['hostids'], 'filter' => array('key_' => zbx_objectValues($tplItems, 'key_')), 'nopermissions' => true, 'preservekeys' => true)); $realItems = array(); foreach ($dbItems as $item) { unset($item['hosts']); if (!isset($realItems[$item['hostid']])) { $realItems[$item['hostid']] = array(); } $realItems[$item['hostid']][$item['key_']] = $item; } } } // hashing $options['hostids'] = zbx_toHash($options['hostids']); if (is_null($options['countOutput']) || !is_null($options['countOutput']) && !is_null($options['groupCount'])) { // creating copies of templated screens (inheritance) // screenNum is needed due to we can't refer to screenid/hostid/templateid as they will repeat $screenNum = 0; $vrtResult = array(); foreach ($result as $screen) { if (is_null($options['hostids']) || isset($options['hostids'][$screen['templateid']])) { $screenNum++; $vrtResult[$screenNum] = $screen; $vrtResult[$screenNum]['hostid'] = $screen['templateid']; } if (!isset($templatesChain[$screen['templateid']])) { continue; } foreach ($templatesChain[$screen['templateid']] as $hostid) { if (!isset($options['hostids'][$hostid])) { continue; } $screenNum++; $vrtResult[$screenNum] = $screen; $vrtResult[$screenNum]['hostid'] = $hostid; if (!isset($vrtResult[$screenNum]['screenitems'])) { continue; } foreach ($vrtResult[$screenNum]['screenitems'] as &$screenitem) { switch ($screenitem['resourcetype']) { case SCREEN_RESOURCE_GRAPH: $graphName = $tplGraphs[$screenitem['resourceid']]['name']; $screenitem['real_resourceid'] = $realGraphs[$hostid][$graphName]['graphid']; break; case SCREEN_RESOURCE_SIMPLE_GRAPH: case SCREEN_RESOURCE_PLAIN_TEXT: $itemKey = $tplItems[$screenitem['resourceid']]['key_']; $screenitem['real_resourceid'] = $realItems[$hostid][$itemKey]['itemid']; break; } } unset($screenitem); } } $result = array_values($vrtResult); } if (!is_null($options['countOutput'])) { return $result; } if ($result) { $result = $this->unsetExtraFields($result, array('templateid'), $options['output']); } // removing keys (hash -> array) if (is_null($options['preservekeys'])) { $result = zbx_cleanHashes($result); } elseif (!is_null($options['noInheritance'])) { $result = zbx_toHash($result, 'screenid'); } return $result; }
/** * 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); }
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; }
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; }
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; }
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; }
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; }
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; }
/** * Deletes all trigger dependencies from the given triggers and their children. * * @param array $triggers an array of triggers with the 'triggerid' field defined * * @return boolean */ public function deleteDependencies(array $triggers) { $triggers = zbx_toArray($triggers); $this->validateDeleteDependencies($triggers); $triggerids = zbx_objectValues($triggers, 'triggerid'); try { // delete the dependencies from the child triggers $childTriggers = API::getApi()->select($this->tableName(), array('output' => array('triggerid'), 'filter' => array('templateid' => $triggerids))); if ($childTriggers) { $this->deleteDependencies($childTriggers); } DB::delete('trigger_depends', array('triggerid_down' => $triggerids)); } catch (APIException $e) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete dependency')); } return array('triggerids' => $triggerids); }
/** * Check if trigger prototype has at least one item prototype and belongs to one discovery rule. * * @throws APIException if trigger prototype has no item prototype or items belong to multiple discovery rules. * * @param array $triggers array of triggers * @param array $triggers['items'] array if trigger items * @param string $triggers['description'] trigger description */ protected function checkDiscoveryRuleCount(array $triggers) { foreach ($triggers as $trigger) { $itemDiscoveries = API::getApi()->select('item_discovery', array('nodeids' => get_current_nodeid(true), 'output' => array('parent_itemid'), 'filter' => array('itemid' => zbx_objectValues($trigger['items'], 'itemid')))); $itemDiscoveryIds = array_flip(zbx_objectValues($itemDiscoveries, 'parent_itemid')); if (count($itemDiscoveryIds) > 1) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Trigger prototype "%1$s" contains item prototypes from multiple discovery rules.', $trigger['description'])); } elseif (!$itemDiscoveryIds) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Trigger prototype "%1$s" must contain at least one item prototype.', $trigger['description'])); } } }
} continue; } } } } } private function getAroundEpitech() { $bordeaux = array('name' => 'Bordeaux', 'phone' => '01.44.08.00.14', 'address' => '85, rue du Jardin Public\\n33000 BORDEAUX', 'mail' => '*****@*****.**', 'website' => 'http://www.bordeaux.epitech.eu', 'image' => 'https://epiglab.fr/images/bordeaux_epitech.jpg'); $lille = array('name' => 'Lille', 'phone' => '01.44.08.00.10', 'address' => '5-9, rue du Palais Rihour\\n59000 LILLE', 'mail' => '*****@*****.**', 'website' => 'http://www.lille.epitech.eu', 'image' => 'https://epiglab.fr/images/lille_epitech.jpg'); $lyon = array('name' => 'Lyon', 'phone' => '01.44.08.00.13', 'address' => '156, rue Paul Bert\\n69003 LYON', 'mail' => '*****@*****.**', 'website' => 'http://www.lyon.epitech.eu', 'image' => 'https://epiglab.fr/images/lyon_epitech.jpg'); $marseille = array('name' => 'Marseille', 'phone' => '01.44.08.01.37', 'address' => '21, rue Mires\\n13002 MARSEILLE', 'mail' => '*****@*****.**', 'website' => 'http://www.marseille.epitech.eu', 'image' => 'https://epiglab.fr/images/marseille_epitech.jpg'); $montpellier = array('name' => 'Montpellier', 'phone' => '01.44.08.00.75', 'address' => '16, boulevard du Jeu de Paume\\n34000 MONTPELLIER', 'mail' => '*****@*****.**', 'website' => 'http://www.montpellier.epitech.eu', 'image' => 'https://epiglab.fr/images/montpellier_epitech.jpg'); $nancy = array('name' => 'Nancy', 'phone' => '01.44.08.00.36', 'address' => '113, rue Saint Georges\\n54000 NANCY', 'mail' => '*****@*****.**', 'website' => 'http://www.nancy.epitech.eu', 'image' => 'https://epiglab.fr/images/nancy_epitech.jpg'); $nantes = array('name' => 'Nantes', 'phone' => '01.44.08.00.11', 'address' => '16bis-18, rue Flandres Dunkerque\\n44100 NANTES', 'mail' => '*****@*****.**', 'website' => 'http://www.nantes.epitech.eu', 'image' => 'https://epiglab.fr/images/nantes_epitech.jpg'); $nice = array('name' => 'Nice', 'phone' => '01.44.08.00.26', 'address' => '6, rue Desboutin\\n06300 NICE', 'mail' => '*****@*****.**', 'website' => 'http://www.nice.epitech.eu', 'image' => 'https://epiglab.fr/images/nice_epitech.jpg'); $paris = array('name' => 'Paris', 'phone' => '01.44.08.00.50', 'address' => '24, rue Pasteur\\n94270 Le Kremlin Bicêtre', 'mail' => '*****@*****.**', 'website' => 'http://www.paris.epitech.eu', 'image' => 'https://epiglab.fr/images/paris_epitech.jpg'); $rennes = array('name' => 'Rennes', 'phone' => '01.80.51.71.10', 'address' => '12, square Vercingétorix\\n35000 RENNES', 'mail' => '*****@*****.**', 'website' => 'http://www.rennes.epitech.eu', 'image' => 'https://epiglab.fr/images/rennes_epitech.jpg'); $strasbourg = array('name' => 'Strasbourg', 'phone' => '01.44.08.00.12', 'address' => '4, rue du Dôme\\n67000 STRASBOURG', 'mail' => '*****@*****.**', 'website' => 'http://www.strasbourg.epitech.eu', 'image' => 'https://epiglab.fr/images/strasbourg_epitech.jpg'); $toulouse = array('name' => 'Toulouse', 'phone' => '01.44.08.00.15', 'address' => '19, rue Bayard\\n31000 TOULOUSE', 'mail' => '*****@*****.**', 'website' => 'http://www.toulouse.epitech.eu', 'image' => 'https://epiglab.fr/images/toulouse_epitech.jpg'); echo json_encode(array('countries' => array($bordeaux, $lille, $lyon, $marseille, $montpellier, $nancy, $nantes, $nice, $paris, $rennes, $strasbourg, $toulouse))); } } if (!isset($_REQUEST['login']) || !isset($_REQUEST['password']) || !isset($_REQUEST['action'])) { echo json_encode(array('error' => 'login, password and action required')); exit; } $Api = new API($_REQUEST['login'], urlencode($_REQUEST['password']), $_REQUEST['action']); $Api->getApi();
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $groupIds = array_keys($result); sort($groupIds); // adding hosts if ($options['selectHosts'] !== null) { if ($options['selectHosts'] !== API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'groupid', 'hostid', 'hosts_groups'); $hosts = API::Host()->get(array('output' => $options['selectHosts'], 'nodeids' => $options['nodeids'], 'hostids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); if (!is_null($options['limitSelects'])) { order_result($hosts, 'host'); } $result = $relationMap->mapMany($result, $hosts, 'hosts', $options['limitSelects']); } else { $hosts = API::Host()->get(array('nodeids' => $options['nodeids'], 'groupids' => $groupIds, 'countOutput' => true, 'groupCount' => true)); $hosts = zbx_toHash($hosts, 'groupid'); foreach ($result as $groupid => $group) { if (isset($hosts[$groupid])) { $result[$groupid]['hosts'] = $hosts[$groupid]['rowscount']; } else { $result[$groupid]['hosts'] = 0; } } } } // adding templates if ($options['selectTemplates'] !== null) { if ($options['selectTemplates'] !== API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'groupid', 'hostid', 'hosts_groups'); $hosts = API::Template()->get(array('output' => $options['selectTemplates'], 'nodeids' => $options['nodeids'], 'templateids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); if (!is_null($options['limitSelects'])) { order_result($hosts, 'host'); } $result = $relationMap->mapMany($result, $hosts, 'templates', $options['limitSelects']); } else { $hosts = API::Template()->get(array('nodeids' => $options['nodeids'], 'groupids' => $groupIds, 'countOutput' => true, 'groupCount' => true)); $hosts = zbx_toHash($hosts, 'groupid'); foreach ($result as $groupid => $group) { if (isset($hosts[$groupid])) { $result[$groupid]['templates'] = $hosts[$groupid]['rowscount']; } else { $result[$groupid]['templates'] = 0; } } } } // adding discovery rule if ($options['selectDiscoveryRule'] !== null && $options['selectDiscoveryRule'] != API_OUTPUT_COUNT) { // discovered items $discoveryRules = DBFetchArray(DBselect('SELECT gd.groupid,hd.parent_itemid' . ' FROM group_discovery gd,group_prototype gp,host_discovery hd' . ' WHERE ' . dbConditionInt('gd.groupid', $groupIds) . ' AND gd.parent_group_prototypeid=gp.group_prototypeid' . ' AND gp.hostid=hd.hostid')); $relationMap = $this->createRelationMap($discoveryRules, 'groupid', '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 group discovery if ($options['selectGroupDiscovery'] !== null) { $groupDiscoveries = API::getApi()->select('group_discovery', array('output' => $this->outputExtend('group_discovery', array('groupid'), $options['selectGroupDiscovery']), 'filter' => array('groupid' => $groupIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true))); $relationMap = $this->createRelationMap($groupDiscoveries, 'groupid', 'groupid'); $groupDiscoveries = $this->unsetExtraFields($groupDiscoveries, array('groupid'), $options['selectGroupDiscovery']); $result = $relationMap->mapOne($result, $groupDiscoveries, 'groupDiscovery'); } return $result; }
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); // check main interfaces $interfacesToRemove = API::getApi()->select($this->tableName(), array('output' => array('interfaceid'), 'filter' => array('hostid' => $data['hostids'], 'ip' => $interface['ip'], 'dns' => $interface['dns'], 'port' => $interface['port']))); if ($interfacesToRemove) { $this->checkMainInterfacesOnDelete(zbx_objectValues($interfacesToRemove, 'interfaceid')); } } }
protected function checkLinkInput($links, $method) { $update = $method == 'updateLink'; $delete = $method == 'deleteLink'; // permissions if ($update || $delete) { $linkDbFields = array('linkid' => null); $dbLinks = API::getApi()->select('sysmap_element_url', array('filter' => array('selementid' => zbx_objectValues($links, 'linkid')), 'output' => array('linkid'), 'preservekeys' => true)); } else { $linkDbFields = array('sysmapid' => null, 'selementid1' => null, 'selementid2' => null); } $colorValidator = new CColorValidator(); foreach ($links as $link) { if (!check_db_fields($linkDbFields, $link)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Wrong fields for map link.')); } if (isset($link['color']) && !$colorValidator->validate($link['color'])) { self::exception(ZBX_API_ERROR_PARAMETERS, $colorValidator->getError()); } if ($update || $delete) { if (!isset($dbLinks[$link['linkid']])) { self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!')); } } } return true; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $httpTestIds = array_keys($result); // adding hosts if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'httptestid', 'hostid'); $hosts = API::Host()->get(array('output' => $options['selectHosts'], 'hostid' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'templated_hosts' => true, 'preservekeys' => true)); $result = $relationMap->mapMany($result, $hosts, 'hosts'); } // adding steps if ($options['selectSteps'] !== null) { if ($options['selectSteps'] != API_OUTPUT_COUNT) { $httpSteps = API::getApi()->select('httpstep', array('output' => $this->outputExtend('httpstep', array('httptestid', 'httpstepid'), $options['selectSteps']), 'filters' => array('httptestid' => $httpTestIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true))); $relationMap = $this->createRelationMap($httpSteps, 'httptestid', 'httpstepid'); // add the deprecated webstepid parameter if it's requested $httpSteps = $this->handleDeprecatedOutput($httpSteps, 'webstepid', 'httpstepid', $options['selectSteps']); $httpSteps = $this->unsetExtraFields($httpSteps, array('httptestid', 'httpstepid'), $options['selectSteps']); $result = $relationMap->mapMany($result, $httpSteps, 'steps'); } else { $dbHttpSteps = DBselect('SELECT hs.httptestid,COUNT(hs.httpstepid) AS stepscnt' . ' FROM httpstep hs' . ' WHERE ' . dbConditionInt('hs.httptestid', $httpTestIds) . ' GROUP BY hs.httptestid'); while ($dbHttpStep = DBfetch($dbHttpSteps)) { $result[$dbHttpStep['httptestid']]['steps'] = $dbHttpStep['stepscnt']; } } } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $actionIds = array_keys($result); // adding conditions if (!is_null($options['selectConditions']) && $options['selectConditions'] != API_OUTPUT_COUNT) { $conditions = API::getApi()->select('conditions', array('output' => $this->outputExtend('conditions', array('actionid', 'conditionid'), $options['selectConditions']), 'filter' => array('actionid' => $actionIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true))); $relationMap = $this->createRelationMap($conditions, 'actionid', 'conditionid'); $conditions = $this->unsetExtraFields($conditions, array('actionid', 'conditionid'), $options['selectConditions']); $result = $relationMap->mapMany($result, $conditions, 'conditions'); } // adding operations if ($options['selectOperations'] !== null && $options['selectOperations'] != API_OUTPUT_COUNT) { $operations = API::getApi()->select('operations', array('output' => $this->outputExtend('operations', array('operationid', 'actionid', 'operationtype'), $options['selectOperations']), 'filter' => array('actionid' => $actionIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(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)) { $operations[$dbOpmessage['operationid']]['opmessage'] = $dbOpmessage; } } if ($this->outputIsRequested('opmessage_grp', $options['selectOperations'])) { foreach ($opmessage as $operationId) { $operations[$operationId]['opmessage_grp'] = array(); } $dbOpmessageGrp = DBselect('SELECT og.operationid,og.usrgrpid' . ' FROM opmessage_grp og' . ' WHERE ' . dbConditionInt('operationid', $opmessage)); while ($opmessageGrp = DBfetch($dbOpmessageGrp)) { $operations[$opmessageGrp['operationid']]['opmessage_grp'][] = $opmessageGrp; } } if ($this->outputIsRequested('opmessage_usr', $options['selectOperations'])) { foreach ($opmessage as $operationId) { $operations[$operationId]['opmessage_usr'] = array(); } $dbOpmessageUsr = DBselect('SELECT ou.operationid,ou.userid' . ' FROM opmessage_usr ou' . ' WHERE ' . dbConditionInt('operationid', $opmessage)); while ($opmessageUsr = DBfetch($dbOpmessageUsr)) { $operations[$opmessageUsr['operationid']]['opmessage_usr'][] = $opmessageUsr; } } } // get OPERATION_TYPE_COMMAND data if (!empty($opcommand)) { if ($this->outputIsRequested('opcommand', $options['selectOperations'])) { foreach ($opcommand as $operationId) { $operations[$operationId]['opcommand'] = array(); } $dbOpcommands = DBselect('SELECT o.*' . ' FROM opcommand o' . ' WHERE ' . dbConditionInt('operationid', $opcommand)); while ($dbOpcommand = DBfetch($dbOpcommands)) { $operations[$dbOpcommand['operationid']]['opcommand'] = $dbOpcommand; } } if ($this->outputIsRequested('opcommand_hst', $options['selectOperations'])) { foreach ($opcommand as $operationId) { $operations[$operationId]['opcommand_hst'] = array(); } $dbOpcommandHst = DBselect('SELECT oh.opcommand_hstid,oh.operationid,oh.hostid' . ' FROM opcommand_hst oh' . ' WHERE ' . dbConditionInt('operationid', $opcommand)); while ($opcommandHst = DBfetch($dbOpcommandHst)) { $operations[$opcommandHst['operationid']]['opcommand_hst'][] = $opcommandHst; } } if ($this->outputIsRequested('opcommand_grp', $options['selectOperations'])) { foreach ($opcommand as $operationId) { $operations[$operationId]['opcommand_grp'] = array(); } $dbOpcommandGrp = DBselect('SELECT og.opcommand_grpid,og.operationid,og.groupid' . ' FROM opcommand_grp og' . ' WHERE ' . dbConditionInt('operationid', $opcommand)); while ($opcommandGrp = DBfetch($dbOpcommandGrp)) { $operations[$opcommandGrp['operationid']]['opcommand_grp'][] = $opcommandGrp; } } } // get OPERATION_TYPE_GROUP_ADD, OPERATION_TYPE_GROUP_REMOVE data if (!empty($opgroup)) { if ($this->outputIsRequested('opgroup', $options['selectOperations'])) { foreach ($opgroup as $operationId) { $operations[$operationId]['opgroup'] = array(); } $dbOpgroup = DBselect('SELECT o.operationid,o.groupid' . ' FROM opgroup o' . ' WHERE ' . dbConditionInt('operationid', $opgroup)); while ($opgroup = DBfetch($dbOpgroup)) { $operations[$opgroup['operationid']]['opgroup'][] = $opgroup; } } } // get OPERATION_TYPE_TEMPLATE_ADD, OPERATION_TYPE_TEMPLATE_REMOVE data if (!empty($optemplate)) { if ($this->outputIsRequested('optemplate', $options['selectOperations'])) { foreach ($optemplate as $operationId) { $operations[$operationId]['optemplate'] = array(); } $dbOptemplate = DBselect('SELECT o.operationid,o.templateid' . ' FROM optemplate o' . ' WHERE ' . dbConditionInt('operationid', $optemplate)); while ($optemplate = DBfetch($dbOptemplate)) { $operations[$optemplate['operationid']]['optemplate'][] = $optemplate; } } } $operations = $this->unsetExtraFields($operations, array('operationid', 'actionid', 'operationtype'), $options['selectOperations']); $result = $relationMap->mapMany($result, $operations, 'operations'); } return $result; }
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(array('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(array('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::getApi()->select('timeperiods', array('output' => $options['selectTimeperiods'], 'filter' => array('timeperiodid' => $relationMap->getRelatedIds()), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true))); $result = $relationMap->mapMany($result, $timeperiods, 'timeperiods'); } return $result; }
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(array('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(array('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::getApi()->select('media_type', array('output' => $options['selectMediatypes'], 'filter' => array('mediatypeid' => $relationMap->getRelatedIds()), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true))); $result = $relationMap->mapMany($result, $mediatypes, 'mediatypes'); } return $result; }