Ejemplo n.º 1
0
 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(array('output' => $options['selectDRules'], 'nodeids' => $options['nodeids'], '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(array('output' => $options['selectDHosts'], 'nodeids' => $options['nodeids'], '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(array('output' => $options['selectHosts'], 'nodeids' => $options['nodeids'], '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(array('nodeids' => $options['nodeids'], '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;
 }
Ejemplo n.º 2
0
 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(array('nodeids' => $options['nodeids'], 'hostids' => $relationMap->getRelatedIds(), 'templated_hosts' => true, 'output' => $options['selectHosts'], 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $hosts, 'hosts');
     }
     return $result;
 }
Ejemplo n.º 3
0
 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, 'nodeids' => id2nodeid($script['scriptid'])));
                 $processedGroups[$script['groupid'] . '_' . $script['host_access']] = $scriptId;
             }
         }
     }
     return $result;
 }
Ejemplo n.º 4
0
 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(array('output' => $options['selectHosts'], 'nodeids' => $options['nodeids'], '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(array('output' => $this->outputExtend('items', array('itemid', 'interfaceid'), $options['selectItems']), 'nodeids' => $options['nodeids'], 'interfaceids' => $interfaceIds, 'nopermissions' => true, 'preservekeys' => true, 'filter' => array('flags' => null)));
             $relationMap = $this->createRelationMap($items, 'interfaceid', 'itemid');
             $items = $this->unsetExtraFields($items, array('interfaceid', 'itemid'), $options['selectItems']);
             $result = $relationMap->mapMany($result, $items, 'items', $options['limitSelects']);
         } else {
             $items = API::Item()->get(array('nodeids' => $options['nodeids'], 'interfaceids' => $interfaceIds, 'nopermissions' => true, 'filter' => array('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;
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 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'], 'nodeids' => $options['nodeids'], '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('nodeids' => $options['nodeids'], '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'], 'nodeids' => $options['nodeids'], '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('nodeids' => $options['nodeids'], '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;
 }
Ejemplo n.º 9
0
 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('nodeids' => $options['nodeids'], 'output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $hosts, 'hosts');
     }
     // adding triggers
     if ($options['selectTriggers'] !== null && $options['selectTriggers'] != API_OUTPUT_COUNT) {
         $relationMap = new CRelationMap();
         foreach ($result as $event) {
             if ($event['object'] == EVENT_OBJECT_TRIGGER) {
                 $relationMap->addRelation($event['eventid'], $event['objectid']);
             }
         }
         $triggers = API::Trigger()->get(array('nodeids' => $options['nodeids'], 'output' => $options['selectTriggers'], 'triggerids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $triggers, 'triggers');
     }
     // adding items
     if ($options['selectItems'] !== null && $options['selectItems'] != API_OUTPUT_COUNT) {
         $relationMap = new CRelationMap();
         // discovered items
         $dbRules = DBselect('SELECT e.eventid,f.itemid' . ' FROM events e,functions f' . ' WHERE ' . dbConditionInt('e.eventid', $eventIds) . ' AND e.objectid=f.triggerid' . ' AND e.object=' . EVENT_OBJECT_TRIGGER);
         while ($relation = DBfetch($dbRules)) {
             $relationMap->addRelation($relation['eventid'], $relation['itemid']);
         }
         $items = API::Item()->get(array('nodeids' => $options['nodeids'], 'output' => $options['selectItems'], 'itemids' => $relationMap->getRelatedIds(), 'webitems' => true, 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $items, 'items');
     }
     // 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('nodeids' => $options['nodeids'], '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, 'nodeids' => $options['nodeids'], '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::getApi()->createSelectQueryParts('acknowledges', 'a', array('output' => $this->outputExtend('acknowledges', array('acknowledgeid', 'eventid', 'clock'), $options['select_acknowledges']), 'filter' => array('eventid' => $eventIds), 'nodeids' => get_current_nodeid(true)));
             $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;
 }
Ejemplo n.º 10
0
 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $userids = zbx_objectValues($result, 'userid');
     // adding usergroups
     if (!is_null($options['selectUsrgrps']) && str_in_array($options['selectUsrgrps'], array(API_OUTPUT_REFER, API_OUTPUT_EXTEND))) {
         foreach ($result as &$user) {
             $user['usrgrps'] = array();
         }
         unset($user);
         $usrgrps = API::UserGroup()->get(array('output' => $options['selectUsrgrps'], 'userids' => $userids, 'preservekeys' => true));
         foreach ($usrgrps as $usrgrp) {
             $uusers = $usrgrp['users'];
             unset($usrgrp['users']);
             $usrgrps = $this->unsetExtraFields('usrgrp', $usrgrps, $options['selectUsrgrps']);
             foreach ($uusers as $user) {
                 $result[$user['userid']]['usrgrps'][] = $usrgrp;
             }
         }
     }
     // adding medias
     if (!is_null($options['selectMedias']) && str_in_array($options['selectMedias'], array(API_OUTPUT_REFER, API_OUTPUT_EXTEND))) {
         foreach ($result as &$user) {
             $user['medias'] = array();
         }
         unset($user);
         $userMedias = API::UserMedia()->get(array('output' => $options['selectMedias'], 'userids' => $userids, 'preservekeys' => true));
         $userMedias = $this->unsetExtraFields('media', $userMedias, $options['selectMedias']);
         foreach ($userMedias as $mediaid => $media) {
             $result[$media['userid']]['medias'][] = $media;
         }
     }
     // adding media types
     if (!is_null($options['selectMediatypes'])) {
         foreach ($result as &$user) {
             $user['mediatypes'] = array();
         }
         unset($user);
         $mediatypes = API::Mediatype()->get(array('output' => $options['selectMediatypes'], 'userids' => $userids, 'selectUsers' => API_OUTPUT_REFER, 'preservekeys' => true));
         foreach ($mediatypes as $mediatype) {
             $users = $mediatype['users'];
             unset($mediatype['users']);
             $mediatype = $this->unsetExtraFields('media_type', $mediatype, $options['selectMediatypes']);
             foreach ($users as $user) {
                 if (!empty($result[$user['userid']])) {
                     $result[$user['userid']]['mediatypes'][] = $mediatype;
                 }
             }
         }
     }
     return $result;
 }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
 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
     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' => 1, 'templated_hosts' => true, 'preservekeys' => 1));
         $result = $relationMap->mapMany($result, $hosts, 'hosts');
     }
     // 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;
 }
Ejemplo n.º 13
0
 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(), 'nodeids' => $options['nodeids'], 'preservekeys' => 1));
         if (!is_null($options['limitSelects'])) {
             order_result($drules, 'name');
         }
         $result = $relationMap->mapMany($result, $drules, 'drules', $options['limitSelects']);
     }
     return $result;
 }
Ejemplo n.º 14
0
 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(array('nodeids' => $options['nodeids'], 'output' => $options['selectGraphs'], 'gitemids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $graphs, 'graphs');
     }
     return $result;
 }
Ejemplo n.º 15
0
 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;
 }
Ejemplo n.º 16
0
 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;
 }
Ejemplo n.º 17
0
 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;
 }
Ejemplo n.º 18
0
 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'], 'nodeids' => $options['nodeids'], '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('dservices', array('dserviceid', 'dhostid'), $options['selectDServices']), 'nodeids' => $options['nodeids'], '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'], 'nodeids' => $options['nodeids'], '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;
 }
Ejemplo n.º 19
0
 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;
 }
Ejemplo n.º 20
0
 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('media', array('userid', 'mediaid'), $options['selectMedias']), '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;
 }
 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $maintenanceIds = array_keys($result);
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     // selectGroups
     if (is_array($options['selectGroups']) || str_in_array($options['selectGroups'], $subselectsAllowedOutputs)) {
         $objParams = array('output' => $options['selectGroups'], 'maintenanceids' => $maintenanceIds, 'preservekeys' => true);
         $groups = API::HostGroup()->get($objParams);
         foreach ($groups as $group) {
             $gmaintenances = $group['maintenances'];
             unset($group['maintenances']);
             foreach ($gmaintenances as $maintenance) {
                 $result[$maintenance['maintenanceid']]['groups'][] = $group;
             }
         }
     }
     // selectHosts
     if (is_array($options['selectHosts']) || str_in_array($options['selectHosts'], $subselectsAllowedOutputs)) {
         $objParams = array('output' => $options['selectHosts'], 'maintenanceids' => $maintenanceIds, 'preservekeys' => true);
         $hosts = API::Host()->get($objParams);
         foreach ($hosts as $host) {
             $hmaintenances = $host['maintenances'];
             unset($host['maintenances']);
             foreach ($hmaintenances as $maintenance) {
                 $result[$maintenance['maintenanceid']]['hosts'][] = $host;
             }
         }
     }
     // selectTimeperiods
     if ($options['selectTimeperiods'] !== null) {
         foreach ($result as &$maintenance) {
             $maintenance['timeperiods'] = array();
         }
         unset($maintenance);
         // create the SELECT part of the query
         $sqlParts = $this->applyQueryOutputOptions('timeperiods', 'tp', array('output' => $options['selectTimeperiods']), array('select' => array('tp.timeperiodid')));
         $query = DBSelect('SELECT ' . implode($sqlParts['select'], ',') . ',mw.maintenanceid' . ' FROM timeperiods tp,maintenances_windows mw' . ' WHERE ' . dbConditionInt('mw.maintenanceid', $maintenanceIds) . ' AND tp.timeperiodid=mw.timeperiodid');
         while ($tp = DBfetch($query)) {
             $refId = $tp['maintenanceid'];
             $tp = $this->unsetExtraFields('timeperiods', $tp, $options['selectTimeperiods']);
             $result[$refId]['timeperiods'][] = $tp;
         }
     }
     return $result;
 }
Ejemplo n.º 22
0
 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;
 }
Ejemplo n.º 23
0
 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');
         $users = API::User()->get(array('output' => $options['selectUsers'], 'userids' => $relationMap->getRelatedIds(), 'getAccess' => $options['selectUsers'] == API_OUTPUT_EXTEND ? true : null, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $users, 'users');
     }
     return $result;
 }
Ejemplo n.º 24
0
 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('nodeids' => $options['nodeids'], 'output' => $this->outputExtend('graphs_items', array('graphid', 'gitemid'), $options['selectGraphItems']), '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('nodeids' => $options['nodeids'], '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('nodeids' => $options['nodeids'], '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('nodeids' => $options['nodeids'], 'output' => $options['selectTemplates'], 'templateids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $templates, 'templates');
     }
     return $result;
 }
Ejemplo n.º 25
0
 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;
 }
Ejemplo n.º 26
0
 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;
 }
Ejemplo n.º 27
0
 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('hosts', array('hostid', 'proxy_hostid'), $options['selectHosts']), 'nodeids' => $options['nodeids'], '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('interface', array('interfaceid', 'hostid'), $options['selectInterface']), 'nodeids' => $options['nodeids'], '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'];
             }
         }
     }
     // adding host interfaces (deprecated)
     if ($options['selectInterfaces'] !== null && $options['selectInterfaces'] != API_OUTPUT_COUNT) {
         $interfaces = API::HostInterface()->get(array('output' => $this->outputExtend('interface', array('interfaceid', 'hostid'), $options['selectInterfaces']), 'nodeids' => $options['nodeids'], 'hostids' => $proxyIds, 'nopermissions' => true, 'preservekeys' => true));
         $relationMap = $this->createRelationMap($interfaces, 'hostid', 'interfaceid');
         $interfaces = $this->unsetExtraFields($interfaces, array('hostid', 'interfaceid'), $options['selectInterfaces']);
         $result = $relationMap->mapOne($result, $interfaces, 'interfaces');
         foreach ($result as $key => $proxy) {
             if (!empty($proxy['interfaces'])) {
                 $result[$key]['interfaces'] = array($proxy['interfaces']);
             }
         }
     }
     return $result;
 }
Ejemplo n.º 28
0
 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     // adding groups
     if (!is_null($options['selectGroups']) && str_in_array($options['selectGroups'], $subselectsAllowedOutputs)) {
         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 (!is_null($options['selectHosts']) && str_in_array($options['selectHosts'], $subselectsAllowedOutputs)) {
         $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, 'nodeids' => id2nodeid($script['scriptid'])));
                 $processedGroups[$script['groupid'] . '_' . $script['host_access']] = $scriptid;
             }
         }
     }
     return $result;
 }