protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); // adding users if ($options['selectUsers'] !== null && $options['selectUsers'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'usrgrpid', 'userid', 'users_groups'); $dbUsers = API::User()->get(['output' => $options['selectUsers'], 'userids' => $relationMap->getRelatedIds(), 'getAccess' => $options['selectUsers'] == API_OUTPUT_EXTEND ? true : null, 'preservekeys' => true]); $result = $relationMap->mapMany($result, $dbUsers, 'users'); } // adding usergroup rights if ($options['selectRights'] !== null && $options['selectRights'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'groupid', 'rightid', 'rights'); if (is_array($options['selectRights'])) { $pk_field = $this->pk('rights'); $output_fields = [$pk_field => $this->fieldId($pk_field, 'r')]; foreach ($options['selectRights'] as $field) { if ($this->hasField($field, 'rights')) { $output_fields[$field] = $this->fieldId($field, 'r'); } } $output_fields = implode(',', $output_fields); } else { $output_fields = 'r.*'; } $db_rights = DBfetchArray(DBselect('SELECT ' . $output_fields . ' FROM rights r' . ' WHERE ' . dbConditionInt('r.rightid', $relationMap->getRelatedIds()) . (self::$userData['type'] == USER_TYPE_SUPER_ADMIN ? '' : ' AND r.permission>' . PERM_DENY))); $db_rights = zbx_toHash($db_rights, 'rightid'); foreach ($db_rights as &$db_right) { unset($db_right['rightid'], $db_right['groupid']); } unset($db_right); $result = $relationMap->mapMany($result, $db_rights, 'rights'); } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); // select_drules if ($options['selectDRules'] !== null && $options['selectDRules'] !== API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'dcheckid', 'druleid'); $drules = API::DRule()->get(array('output' => $options['selectDRules'], 'druleids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); if (!is_null($options['limitSelects'])) { order_result($drules, 'name'); } $result = $relationMap->mapMany($result, $drules, 'drules', $options['limitSelects']); } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); // adding graphs if ($options['selectGraphs'] !== null) { $relationMap = $this->createRelationMap($result, 'gitemid', 'graphid'); $graphs = API::Graph()->get(['output' => $options['selectGraphs'], 'gitemids' => $relationMap->getRelatedIds(), 'preservekeys' => true]); $result = $relationMap->mapMany($result, $graphs, 'graphs'); } 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('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'], '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::getApiService()->select('functions', array('output' => $this->outputExtend($options['selectFunctions'], array('triggerid', 'functionid')), 'filter' => array('triggerid' => $triggerids), 'preservekeys' => 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); $eventIds = array_keys($result); // adding hosts if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) { // trigger events if ($options['object'] == EVENT_OBJECT_TRIGGER) { $query = DBselect('SELECT e.eventid,i.hostid' . ' FROM events e,functions f,items i' . ' WHERE ' . dbConditionInt('e.eventid', $eventIds) . ' AND e.objectid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND e.object=' . zbx_dbstr($options['object']) . ' AND e.source=' . zbx_dbstr($options['source'])); } elseif ($options['object'] == EVENT_OBJECT_ITEM || $options['object'] == EVENT_OBJECT_LLDRULE) { $query = DBselect('SELECT e.eventid,i.hostid' . ' FROM events e,items i' . ' WHERE ' . dbConditionInt('e.eventid', $eventIds) . ' AND e.objectid=i.itemid' . ' AND e.object=' . zbx_dbstr($options['object']) . ' AND e.source=' . zbx_dbstr($options['source'])); } $relationMap = new CRelationMap(); while ($relation = DBfetch($query)) { $relationMap->addRelation($relation['eventid'], $relation['hostid']); } $hosts = API::Host()->get(array('output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true)); $result = $relationMap->mapMany($result, $hosts, 'hosts'); } // adding the related object if ($options['selectRelatedObject'] !== null && $options['selectRelatedObject'] != API_OUTPUT_COUNT && $options['object'] != EVENT_OBJECT_AUTOREGHOST) { $relationMap = new CRelationMap(); foreach ($result as $event) { $relationMap->addRelation($event['eventid'], $event['objectid']); } switch ($options['object']) { case EVENT_OBJECT_TRIGGER: $api = API::Trigger(); break; case EVENT_OBJECT_DHOST: $api = API::DHost(); break; case EVENT_OBJECT_DSERVICE: $api = API::DService(); break; case EVENT_OBJECT_ITEM: $api = API::Item(); break; case EVENT_OBJECT_LLDRULE: $api = API::DiscoveryRule(); break; } $objects = $api->get(array('output' => $options['selectRelatedObject'], $api->pkOption() => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true)); $result = $relationMap->mapOne($result, $objects, 'relatedObject'); } // adding alerts if ($options['select_alerts'] !== null && $options['select_alerts'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'eventid', 'alertid', 'alerts'); $alerts = API::Alert()->get(array('output' => $options['select_alerts'], 'selectMediatypes' => API_OUTPUT_EXTEND, 'alertids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true, 'sortfield' => 'clock', 'sortorder' => ZBX_SORT_DOWN)); $result = $relationMap->mapMany($result, $alerts, 'alerts'); } // adding acknowledges if ($options['select_acknowledges'] !== null) { if ($options['select_acknowledges'] != API_OUTPUT_COUNT) { // create the base query $sqlParts = API::getApiService()->createSelectQueryParts('acknowledges', 'a', array('output' => $this->outputExtend($options['select_acknowledges'], array('acknowledgeid', 'eventid', 'clock')), 'filter' => array('eventid' => $eventIds))); $sqlParts['order'][] = 'a.clock DESC'; // if the user data is requested via extended output or specified fields, join the users table $userFields = array('alias', 'name', 'surname'); $requestUserData = array(); foreach ($userFields as $userField) { if ($this->outputIsRequested($userField, $options['select_acknowledges'])) { $requestUserData[] = $userField; } } if ($requestUserData) { foreach ($requestUserData as $userField) { $sqlParts = $this->addQuerySelect('u.' . $userField, $sqlParts); } $sqlParts['from'][] = 'users u'; $sqlParts['where'][] = 'a.userid=u.userid'; } $acknowledges = DBFetchArrayAssoc(DBselect($this->createSelectQueryFromParts($sqlParts)), 'acknowledgeid'); $relationMap = $this->createRelationMap($acknowledges, 'eventid', 'acknowledgeid'); $acknowledges = $this->unsetExtraFields($acknowledges, array('eventid', 'acknowledgeid', 'clock'), $options['select_acknowledges']); $result = $relationMap->mapMany($result, $acknowledges, 'acknowledges'); } else { $acknowledges = DBFetchArrayAssoc(DBselect('SELECT COUNT(a.acknowledgeid) AS rowscount,a.eventid' . ' FROM acknowledges a' . ' WHERE ' . dbConditionInt('a.eventid', $eventIds) . ' GROUP BY a.eventid'), 'eventid'); foreach ($result as &$event) { if (isset($acknowledges[$event['eventid']])) { $event['acknowledges'] = $acknowledges[$event['eventid']]['rowscount']; } else { $event['acknowledges'] = 0; } } unset($event); } } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); // add application templates if ($this->outputIsRequested('templateids', $options['output'])) { $query = DBselect('SELECT at.application_templateid,at.applicationid,at.templateid' . ' FROM application_template at' . ' WHERE ' . dbConditionInt('at.applicationid', array_keys($result))); $relationMap = new CRelationMap(); $templateApplications = array(); while ($templateApplication = DBfetch($query)) { $relationMap->addRelation($templateApplication['applicationid'], $templateApplication['application_templateid']); $templateApplications[$templateApplication['application_templateid']] = $templateApplication['templateid']; } $result = $relationMap->mapMany($result, $templateApplications, 'templateids'); } // adding hosts (deprecated) if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'applicationid', 'hostid'); $hosts = API::Host()->get(array('output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'templated_hosts' => true, 'preservekeys' => true)); $result = $relationMap->mapMany($result, $hosts, 'hosts'); } // adding one host if ($options['selectHost'] !== null) { $relationMap = $this->createRelationMap($result, 'applicationid', 'hostid'); $hosts = API::Host()->get(array('output' => $options['selectHost'], 'hostids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'templated_hosts' => true, 'preservekeys' => true)); $result = $relationMap->mapOne($result, $hosts, 'host'); } // adding items if ($options['selectItems'] !== null && $options['selectItems'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'applicationid', 'itemid', 'items_applications'); $items = API::Item()->get(array('output' => $options['selectItems'], 'itemids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true)); $result = $relationMap->mapMany($result, $items, 'items'); } 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::getApiService()->select('icon_mapping', ['output' => $this->outputExtend($options['selectMappings'], ['iconmapid', 'iconmappingid']), 'filter' => ['iconmapid' => $iconMapIds], 'preservekeys' => true]); $relationMap = $this->createRelationMap($mappings, 'iconmapid', 'iconmappingid'); $mappings = $this->unsetExtraFields($mappings, ['iconmapid', 'iconmappingid'], $options['selectMappings']); $result = $relationMap->mapMany($result, $mappings, 'mappings'); } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $interfaceIds = array_keys($result); // adding hosts if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'interfaceid', 'hostid'); $hosts = API::Host()->get(['output' => $options['selectHosts'], 'hosts' => $relationMap->getRelatedIds(), 'preservekeys' => true]); $result = $relationMap->mapMany($result, $hosts, 'hosts'); } // adding items if ($options['selectItems'] !== null) { if ($options['selectItems'] != API_OUTPUT_COUNT) { $items = API::Item()->get(['output' => $this->outputExtend($options['selectItems'], ['itemid', 'interfaceid']), 'interfaceids' => $interfaceIds, 'nopermissions' => true, 'preservekeys' => true, 'filter' => ['flags' => null]]); $relationMap = $this->createRelationMap($items, 'interfaceid', 'itemid'); $items = $this->unsetExtraFields($items, ['interfaceid', 'itemid'], $options['selectItems']); $result = $relationMap->mapMany($result, $items, 'items', $options['limitSelects']); } else { $items = API::Item()->get(['interfaceids' => $interfaceIds, 'nopermissions' => true, 'filter' => ['flags' => null], 'countOutput' => true, 'groupCount' => true]); $items = zbx_toHash($items, 'interfaceid'); foreach ($result as $interfaceId => $interface) { $result[$interfaceId]['items'] = isset($items[$interfaceId]) ? $items[$interfaceId]['rowscount'] : 0; } } } return $result; }
protected function applyQueryFilterOptions($tableName, $tableAlias, array $options, array $sqlParts) { $sqlParts = parent::applyQueryFilterOptions($tableName, $tableAlias, $options, $sqlParts); // screen ids if ($options['screenids'] !== null) { zbx_value2array($options['screenids']); $sqlParts = $this->addQuerySelect($this->fieldId('screenid'), $sqlParts); $sqlParts['where'][] = dbConditionInt($this->fieldId('screenid'), $options['screenids']); } return $sqlParts; }
/** * {@inheritdoc} */ protected function applyQueryOutputOptions($tableName, $tableAlias, array $options, array $sqlParts) { $sqlParts = parent::applyQueryOutputOptions($tableName, $tableAlias, $options, $sqlParts); if ($options['countOutput'] === null) { // add filter fields if ($this->outputIsRequested('formula', $options['selectFilter']) || $this->outputIsRequested('eval_formula', $options['selectFilter']) || $this->outputIsRequested('conditions', $options['selectFilter'])) { $sqlParts = $this->addQuerySelect('a.formula', $sqlParts); $sqlParts = $this->addQuerySelect('a.evaltype', $sqlParts); } if ($this->outputIsRequested('evaltype', $options['selectFilter'])) { $sqlParts = $this->addQuerySelect('a.evaltype', $sqlParts); } } return $sqlParts; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $graphids = array_keys($result); // adding GraphItems if ($options['selectGraphItems'] !== null && $options['selectGraphItems'] !== API_OUTPUT_COUNT) { $gitems = API::GraphItem()->get(array('output' => $this->outputExtend($options['selectGraphItems'], array('graphid', 'gitemid')), 'graphids' => $graphids, 'nopermissions' => true, 'preservekeys' => true)); $relationMap = $this->createRelationMap($gitems, 'graphid', 'gitemid'); $gitems = $this->unsetExtraFields($gitems, array('graphid', 'gitemid'), $options['selectGraphItems']); $result = $relationMap->mapMany($result, $gitems, 'gitems'); } // adding HostGroups if ($options['selectGroups'] !== null && $options['selectGroups'] !== API_OUTPUT_COUNT) { $relationMap = new CRelationMap(); // discovered items $dbRules = DBselect('SELECT gi.graphid,hg.groupid' . ' FROM graphs_items gi,items i,hosts_groups hg' . ' WHERE ' . dbConditionInt('gi.graphid', $graphids) . ' AND gi.itemid=i.itemid' . ' AND i.hostid=hg.hostid'); while ($relation = DBfetch($dbRules)) { $relationMap->addRelation($relation['graphid'], $relation['groupid']); } $groups = API::HostGroup()->get(array('output' => $options['selectGroups'], 'groupids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true)); $result = $relationMap->mapMany($result, $groups, 'groups'); } // adding Hosts if ($options['selectHosts'] !== null && $options['selectHosts'] !== API_OUTPUT_COUNT) { $relationMap = new CRelationMap(); // discovered items $dbRules = DBselect('SELECT gi.graphid,i.hostid' . ' FROM graphs_items gi,items i' . ' WHERE ' . dbConditionInt('gi.graphid', $graphids) . ' AND gi.itemid=i.itemid'); while ($relation = DBfetch($dbRules)) { $relationMap->addRelation($relation['graphid'], $relation['hostid']); } $hosts = API::Host()->get(array('output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'templated_hosts' => true, 'nopermissions' => true, 'preservekeys' => true)); $result = $relationMap->mapMany($result, $hosts, 'hosts'); } // adding Templates if ($options['selectTemplates'] !== null && $options['selectTemplates'] !== API_OUTPUT_COUNT) { $relationMap = new CRelationMap(); // discovered items $dbRules = DBselect('SELECT gi.graphid,i.hostid' . ' FROM graphs_items gi,items i' . ' WHERE ' . dbConditionInt('gi.graphid', $graphids) . ' AND gi.itemid=i.itemid'); while ($relation = DBfetch($dbRules)) { $relationMap->addRelation($relation['graphid'], $relation['hostid']); } $templates = API::Template()->get(array('output' => $options['selectTemplates'], 'templateids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true)); $result = $relationMap->mapMany($result, $templates, 'templates'); } 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::getApiService()->select('screens_items', array('output' => $this->outputExtend($options['selectScreenItems'], array('screenid', 'screenitemid')), 'filter' => array('screenid' => $screenIds), 'preservekeys' => true)); $relationMap = $this->createRelationMap($screenItems, 'screenid', 'screenitemid'); $screenItems = $this->unsetExtraFields($screenItems, array('screenid', 'screenitemid'), $options['selectScreenItems']); $result = $relationMap->mapMany($result, $screenItems, 'screenitems'); } return $result; }
protected function applyQuerySortOptions($tableName, $tableAlias, array $options, array $sqlParts) { $isIdFieldUsed = false; if ($options['history'] == ITEM_VALUE_TYPE_LOG || $options['history'] == ITEM_VALUE_TYPE_TEXT) { $this->sortColumns['id'] = 'id'; $isIdFieldUsed = true; } $sqlParts = parent::applyQuerySortOptions($tableName, $tableAlias, $options, $sqlParts); if ($isIdFieldUsed) { unset($this->sortColumns['id']); } return $sqlParts; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $alertIds = array_keys($result); // adding hosts if ($options['selectHosts'] !== null && $options['selectHosts'] !== API_OUTPUT_COUNT) { // trigger events if ($options['eventobject'] == EVENT_OBJECT_TRIGGER) { $query = DBselect('SELECT a.alertid,i.hostid' . ' FROM alerts a,events e,functions f,items i' . ' WHERE ' . dbConditionInt('a.alertid', $alertIds) . ' AND a.eventid=e.eventid' . ' AND e.objectid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND e.object=' . zbx_dbstr($options['eventobject']) . ' AND e.source=' . zbx_dbstr($options['eventsource'])); } elseif ($options['eventobject'] == EVENT_OBJECT_ITEM || $options['eventobject'] == EVENT_OBJECT_LLDRULE) { $query = DBselect('SELECT a.alertid,i.hostid' . ' FROM alerts a,events e,items i' . ' WHERE ' . dbConditionInt('a.alertid', $alertIds) . ' AND a.eventid=e.eventid' . ' AND e.objectid=i.itemid' . ' AND e.object=' . zbx_dbstr($options['eventobject']) . ' AND e.source=' . zbx_dbstr($options['eventsource'])); } $relationMap = new CRelationMap(); while ($relation = DBfetch($query)) { $relationMap->addRelation($relation['alertid'], $relation['hostid']); } $hosts = API::Host()->get(['output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'preservekeys' => true]); $result = $relationMap->mapMany($result, $hosts, 'hosts'); } // adding users if ($options['selectUsers'] !== null && $options['selectUsers'] !== API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'alertid', 'userid'); $users = API::User()->get(['output' => $options['selectUsers'], 'userids' => $relationMap->getRelatedIds(), 'preservekeys' => true]); $result = $relationMap->mapMany($result, $users, 'users'); } // adding media types if ($options['selectMediatypes'] !== null && $options['selectMediatypes'] !== API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'alertid', 'mediatypeid'); $mediatypes = API::getApiService()->select('media_type', ['output' => $options['selectMediatypes'], 'filter' => ['mediatypeid' => $relationMap->getRelatedIds()], 'preservekeys' => true]); $result = $relationMap->mapMany($result, $mediatypes, 'mediatypes'); } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $druleids = array_keys($result); // Adding Discovery Checks if (!is_null($options['selectDChecks'])) { if ($options['selectDChecks'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'druleid', 'dcheckid', 'dchecks'); $dchecks = API::DCheck()->get(array('output' => $options['selectDChecks'], 'dcheckids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true)); if (!is_null($options['limitSelects'])) { order_result($dchecks, 'dcheckid'); } $result = $relationMap->mapMany($result, $dchecks, 'dchecks', $options['limitSelects']); } else { $dchecks = API::DCheck()->get(array('druleids' => $druleids, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true)); $dchecks = zbx_toHash($dchecks, 'druleid'); foreach ($result as $druleid => $drule) { if (isset($dchecks[$druleid])) { $result[$druleid]['dchecks'] = $dchecks[$druleid]['rowscount']; } else { $result[$druleid]['dchecks'] = 0; } } } } // Adding Discovery Hosts if (!is_null($options['selectDHosts'])) { if ($options['selectDHosts'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'druleid', 'dhostid', 'dhosts'); $dhosts = API::DHost()->get(array('output' => $options['selectDHosts'], 'dhostids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); if (!is_null($options['limitSelects'])) { order_result($dhosts, 'dhostid'); } $result = $relationMap->mapMany($result, $dhosts, 'dhosts', $options['limitSelects']); } else { $dhosts = API::DHost()->get(array('druleids' => $druleids, 'countOutput' => true, 'groupCount' => true)); $dhosts = zbx_toHash($dhosts, 'druleid'); foreach ($result as $druleid => $drule) { if (isset($dhosts[$druleid])) { $result[$druleid]['dhosts'] = $dhosts[$druleid]['rowscount']; } else { $result[$druleid]['dhosts'] = 0; } } } } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $dhostIds = array_keys($result); // select_drules if ($options['selectDRules'] !== null && $options['selectDRules'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'dhostid', 'druleid'); $drules = API::DRule()->get(array('output' => $options['selectDRules'], 'druleids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); if (!is_null($options['limitSelects'])) { order_result($drules, 'name'); } $result = $relationMap->mapMany($result, $drules, 'drules', $options['limitSelects']); } // selectDServices if (!is_null($options['selectDServices'])) { if ($options['selectDServices'] != API_OUTPUT_COUNT) { $dservices = API::DService()->get(array('output' => $this->outputExtend($options['selectDServices'], array('dserviceid', 'dhostid')), 'dhostids' => $dhostIds, 'preservekeys' => true)); $relationMap = $this->createRelationMap($dservices, 'dhostid', 'dserviceid'); $dservices = $this->unsetExtraFields($dservices, array('dserviceid', 'dhostid'), $options['selectDServices']); if (!is_null($options['limitSelects'])) { order_result($dservices, 'name'); } $result = $relationMap->mapMany($result, $dservices, 'dservices', $options['limitSelects']); } else { $dservices = API::DService()->get(array('output' => $options['selectDServices'], 'dhostids' => $dhostIds, 'countOutput' => true, 'groupCount' => true)); $dservices = zbx_toHash($dservices, 'dhostid'); foreach ($result as $dhostid => $dhost) { if (isset($dservices[$dhostid])) { $result[$dhostid]['dservices'] = $dservices[$dhostid]['rowscount']; } else { $result[$dhostid]['dservices'] = 0; } } } } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $proxyIds = array_keys($result); // selectHosts if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) { $hosts = API::Host()->get(array('output' => $this->outputExtend($options['selectHosts'], array('hostid', 'proxy_hostid')), 'proxyids' => $proxyIds, 'preservekeys' => true)); $relationMap = $this->createRelationMap($hosts, 'proxy_hostid', 'hostid'); $hosts = $this->unsetExtraFields($hosts, array('proxy_hostid', 'hostid'), $options['selectHosts']); $result = $relationMap->mapMany($result, $hosts, 'hosts'); } // adding host interface if ($options['selectInterface'] !== null && $options['selectInterface'] != API_OUTPUT_COUNT) { $interfaces = API::HostInterface()->get(array('output' => $this->outputExtend($options['selectInterface'], array('interfaceid', 'hostid')), 'hostids' => $proxyIds, 'nopermissions' => true, 'preservekeys' => true)); $relationMap = $this->createRelationMap($interfaces, 'hostid', 'interfaceid'); $interfaces = $this->unsetExtraFields($interfaces, array('hostid', 'interfaceid'), $options['selectInterface']); $result = $relationMap->mapOne($result, $interfaces, 'interface'); foreach ($result as $key => $proxy) { if (!empty($proxy['interface'])) { $result[$key]['interface'] = $proxy['interface']; } } } return $result; }
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'], '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('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'], '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('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'], 'itemids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); $result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule'); } // adding group discovery if ($options['selectGroupDiscovery'] !== null) { $groupDiscoveries = API::getApiService()->select('group_discovery', array('output' => $this->outputExtend($options['selectGroupDiscovery'], array('groupid')), 'filter' => array('groupid' => $groupIds), 'preservekeys' => 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 addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); // adding hosts if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'itemid', 'hostid'); $hosts = API::Host()->get(['hostids' => $relationMap->getRelatedIds(), 'templated_hosts' => true, 'output' => $options['selectHosts'], 'nopermissions' => true, 'preservekeys' => true]); $result = $relationMap->mapMany($result, $hosts, 'hosts'); } return $result; }
protected function applyQueryOutputOptions($tableName, $tableAlias, array $options, array $sqlParts) { $sqlParts = parent::applyQueryOutputOptions($tableName, $tableAlias, $options, $sqlParts); if ($options['countOutput'] === null) { if ($options['selectTrigger'] !== null) { $sqlParts = $this->addQuerySelect($this->fieldId('triggerid'), $sqlParts); } } return $sqlParts; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); // Select mappings for value map. if ($options['selectMappings'] !== null) { if ($options['selectMappings'] == API_OUTPUT_COUNT) { $db_mappings = DBselect('SELECT m.valuemapid,COUNT(*) AS cnt' . ' FROM mappings m' . ' WHERE ' . dbConditionInt('m.valuemapid', array_keys($result)) . ' GROUP BY m.valuemapid'); foreach ($result as &$valuemap) { $valuemap['mappings'] = 0; } unset($valuemap); while ($db_mapping = DBfetch($db_mappings)) { $result[$db_mapping['valuemapid']]['mappings'] = $db_mapping['cnt']; } } else { $db_mappings = API::getApiService()->select('mappings', ['output' => $this->outputExtend($options['selectMappings'], ['valuemapid']), 'filter' => ['valuemapid' => array_keys($result)]]); foreach ($result as &$valuemap) { $valuemap['mappings'] = []; } unset($valuemap); foreach ($db_mappings as $db_mapping) { $valuemapid = $db_mapping['valuemapid']; unset($db_mapping['mappingid'], $db_mapping['valuemapid']); $result[$valuemapid]['mappings'][] = $db_mapping; } } } return $result; }
/** * Unset "image" field from output. * * @param string $tableName * @param string $tableAlias * @param array $options * @param array $sqlParts * * @return array The resulting SQL parts array */ protected function applyQueryOutputOptions($tableName, $tableAlias, array $options, array $sqlParts) { if ($options['countOutput'] === null) { if ($options['output'] == API_OUTPUT_EXTEND) { $options['output'] = array('imageid', 'imagetype', 'name'); } elseif (is_array($options['output']) && in_array('image', $options['output'])) { foreach ($options['output'] as $idx => $field) { if ($field === 'image') { unset($options['output'][$idx]); } } } $sqlParts = parent::applyQueryOutputOptions($tableName, $tableAlias, $options, $sqlParts); } return $sqlParts; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); if ($options['globalmacro'] === null) { $hostMacroIds = array_keys($result); /* * Adding objects */ // adding groups if ($options['selectGroups'] !== null && $options['selectGroups'] != API_OUTPUT_COUNT) { $res = DBselect('SELECT hm.hostmacroid,hg.groupid' . ' FROM hostmacro hm,hosts_groups hg' . ' WHERE ' . dbConditionInt('hm.hostmacroid', $hostMacroIds) . ' AND hm.hostid=hg.hostid'); $relationMap = new CRelationMap(); while ($relation = DBfetch($res)) { $relationMap->addRelation($relation['hostmacroid'], $relation['groupid']); } $groups = API::HostGroup()->get(array('output' => $options['selectGroups'], 'groupids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); $result = $relationMap->mapMany($result, $groups, 'groups'); } // adding templates if ($options['selectTemplates'] !== null && $options['selectTemplates'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'hostmacroid', 'hostid'); $templates = API::Template()->get(array('output' => $options['selectTemplates'], 'templateids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); $result = $relationMap->mapMany($result, $templates, 'templates'); } // adding templates if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'hostmacroid', 'hostid'); $templates = API::Host()->get(array('output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); $result = $relationMap->mapMany($result, $templates, 'hosts'); } } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); // adding users if ($options['selectUsers'] !== null && $options['selectUsers'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'mediatypeid', 'userid', 'media'); $users = API::User()->get(array('output' => $options['selectUsers'], 'userids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); $result = $relationMap->mapMany($result, $users, 'users'); } return $result; }
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::getApiService()->select('httpstep', array('output' => $this->outputExtend($options['selectSteps'], array('httptestid', 'httpstepid')), 'filters' => array('httptestid' => $httpTestIds), 'preservekeys' => true)); $relationMap = $this->createRelationMap($httpSteps, 'httptestid', 'httpstepid'); $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; }
public function __construct() { parent::__construct(); $this->errorMessages = array_merge($this->errorMessages, array()); }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); // selectGroups if ($options['selectGroups'] !== null && $options['selectGroups'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'maintenanceid', 'groupid', 'maintenances_groups'); $groups = API::HostGroup()->get(['output' => $options['selectGroups'], 'hostgroupids' => $relationMap->getRelatedIds(), 'preservekeys' => true]); $result = $relationMap->mapMany($result, $groups, 'groups'); } // selectHosts if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'maintenanceid', 'hostid', 'maintenances_hosts'); $groups = API::Host()->get(['output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'preservekeys' => true]); $result = $relationMap->mapMany($result, $groups, 'hosts'); } // selectTimeperiods if ($options['selectTimeperiods'] !== null && $options['selectTimeperiods'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'maintenanceid', 'timeperiodid', 'maintenances_windows'); $timeperiods = API::getApiService()->select('timeperiods', ['output' => $options['selectTimeperiods'], 'filter' => ['timeperiodid' => $relationMap->getRelatedIds()], 'preservekeys' => true]); $result = $relationMap->mapMany($result, $timeperiods, 'timeperiods'); } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $dserviceIds = array_keys($result); // select_drules if ($options['selectDRules'] !== null && $options['selectDRules'] != API_OUTPUT_COUNT) { $relationMap = new CRelationMap(); // discovered items $dbRules = DBselect('SELECT ds.dserviceid,dh.druleid' . ' FROM dservices ds,dhosts dh' . ' WHERE ' . dbConditionInt('ds.dserviceid', $dserviceIds) . ' AND ds.dhostid=dh.dhostid'); while ($rule = DBfetch($dbRules)) { $relationMap->addRelation($rule['dserviceid'], $rule['druleid']); } $drules = API::DRule()->get(['output' => $options['selectDRules'], 'druleids' => $relationMap->getRelatedIds(), 'preservekeys' => true]); if (!is_null($options['limitSelects'])) { order_result($drules, 'name'); } $result = $relationMap->mapMany($result, $drules, 'drules'); } // selectDHosts if ($options['selectDHosts'] !== null && $options['selectDHosts'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'dserviceid', 'dhostid'); $dhosts = API::DHost()->get(['output' => $options['selectDHosts'], 'dhosts' => $relationMap->getRelatedIds(), 'preservekeys' => true]); if (!is_null($options['limitSelects'])) { order_result($dhosts, 'dhostid'); } $result = $relationMap->mapMany($result, $dhosts, 'dhosts', $options['limitSelects']); } // selectHosts if (!is_null($options['selectHosts'])) { if ($options['selectHosts'] != API_OUTPUT_COUNT) { $relationMap = new CRelationMap(); // discovered items $dbRules = DBselect('SELECT ds.dserviceid,i.hostid' . ' FROM dservices ds,interface i' . ' WHERE ' . dbConditionInt('ds.dserviceid', $dserviceIds) . ' AND ds.ip=i.ip'); while ($rule = DBfetch($dbRules)) { $relationMap->addRelation($rule['dserviceid'], $rule['hostid']); } $hosts = API::Host()->get(['output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'preservekeys' => true, 'sortfield' => 'status']); if (!is_null($options['limitSelects'])) { order_result($hosts, 'hostid'); } $result = $relationMap->mapMany($result, $hosts, 'hosts', $options['limitSelects']); } else { $hosts = API::Host()->get(['dserviceids' => $dserviceIds, 'countOutput' => true, 'groupCount' => true]); $hosts = zbx_toHash($hosts, 'hostid'); foreach ($result as $dserviceid => $dservice) { if (isset($hosts[$dserviceid])) { $result[$dserviceid]['hosts'] = $hosts[$dserviceid]['rowscount']; } else { $result[$dserviceid]['hosts'] = 0; } } } } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); // adding groups if ($options['selectGroups'] !== null && $options['selectGroups'] != API_OUTPUT_COUNT) { foreach ($result as $scriptId => $script) { $result[$scriptId]['groups'] = API::HostGroup()->get(array('output' => $options['selectGroups'], 'groupids' => $script['groupid'] ? $script['groupid'] : null, 'editable' => $script['host_access'] == PERM_READ_WRITE ? true : null)); } } // adding hosts if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) { $processedGroups = array(); foreach ($result as $scriptId => $script) { if (isset($processedGroups[$script['groupid'] . '_' . $script['host_access']])) { $result[$scriptId]['hosts'] = $result[$processedGroups[$script['groupid'] . '_' . $script['host_access']]]['hosts']; } else { $result[$scriptId]['hosts'] = API::Host()->get(array('output' => $options['selectHosts'], 'groupids' => $script['groupid'] ? $script['groupid'] : null, 'hostids' => $options['hostids'] ? $options['hostids'] : null, 'editable' => $script['host_access'] == PERM_READ_WRITE ? true : null)); $processedGroups[$script['groupid'] . '_' . $script['host_access']] = $scriptId; } } } return $result; }
protected function addRelatedObjects(array $options, array $result) { $result = parent::addRelatedObjects($options, $result); $userIds = zbx_objectValues($result, 'userid'); // adding usergroups if ($options['selectUsrgrps'] !== null && $options['selectUsrgrps'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'userid', 'usrgrpid', 'users_groups'); $dbUserGroups = API::UserGroup()->get(array('output' => $options['selectUsrgrps'], 'usrgrpids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); $result = $relationMap->mapMany($result, $dbUserGroups, 'usrgrps'); } // adding medias if ($options['selectMedias'] !== null && $options['selectMedias'] != API_OUTPUT_COUNT) { $userMedias = API::UserMedia()->get(array('output' => $this->outputExtend($options['selectMedias'], array('userid', 'mediaid')), 'userids' => $userIds, 'preservekeys' => true)); $relationMap = $this->createRelationMap($userMedias, 'userid', 'mediaid'); $userMedias = $this->unsetExtraFields($userMedias, array('userid', 'mediaid'), $options['selectMedias']); $result = $relationMap->mapMany($result, $userMedias, 'medias'); } // adding media types if ($options['selectMediatypes'] !== null && $options['selectMediatypes'] != API_OUTPUT_COUNT) { $relationMap = $this->createRelationMap($result, 'userid', 'mediatypeid', 'media'); $mediaTypes = API::Mediatype()->get(array('output' => $options['selectMediatypes'], 'mediatypeids' => $relationMap->getRelatedIds(), 'preservekeys' => true)); $result = $relationMap->mapMany($result, $mediaTypes, 'mediatypes'); } return $result; }