public function __construct()
 {
     parent::__construct();
     // template - if templated item, value is taken from template item, cannot be changed on host
     // system - values should not be updated
     // host - value should be null for template items
     $this->fieldRules = array('type' => array('template' => 1), 'snmp_community' => array(), 'snmp_oid' => array('template' => 1), 'hostid' => array(), 'name' => array('template' => 1), 'description' => array(), 'key_' => array('template' => 1), 'delay' => array(), 'history' => array(), 'trends' => array(), 'lastvalue' => array('system' => 1), 'lastclock' => array('system' => 1), 'prevvalue' => array('system' => 1), 'status' => array(), 'value_type' => array('template' => 1), 'trapper_hosts' => array(), 'units' => array('template' => 1), 'multiplier' => array('template' => 1), 'delta' => array(), 'prevorgvalue' => array('system' => 1), 'snmpv3_securityname' => array(), 'snmpv3_securitylevel' => array(), 'snmpv3_authpassphrase' => array(), 'snmpv3_privpassphrase' => array(), 'formula' => array('template' => 1), 'error' => array('system' => 1), 'lastlogsize' => array('system' => 1), 'logtimefmt' => array(), 'templateid' => array('system' => 1), 'valuemapid' => array('template' => 1), 'delay_flex' => array(), 'params' => array(), 'ipmi_sensor' => array('template' => 1), 'data_type' => array('template' => 1), 'authtype' => array(), 'username' => array(), 'password' => array(), 'publickey' => array(), 'privatekey' => array(), 'mtime' => array('system' => 1), 'lastns' => array('system' => 1), 'flags' => array(), 'filter' => array(), 'interfaceid' => array('host' => 1), 'port' => array(), 'inventory_link' => array(), 'lifetime' => array());
 }
Exemple #2
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;
 }
Exemple #3
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;
 }
Exemple #4
0
 protected function applyQueryFilterOptions($tableName, $tableAlias, array $options, array $sqlParts)
 {
     $sqlParts = parent::applyQueryFilterOptions($tableName, $tableAlias, $options, $sqlParts);
     // screens
     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;
 }
Exemple #5
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;
 }
 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;
 }
 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;
 }
Exemple #8
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;
 }
Exemple #9
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;
 }
Exemple #10
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;
 }
Exemple #11
0
 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;
 }
Exemple #12
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;
 }
Exemple #13
0
 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 applyQueryNodeOptions($tableName, $tableAlias, array $options, array $sqlParts)
 {
     // only apply the node option if no specific ids are given
     if ($options['screenids'] === null && $options['screenitemids'] === null) {
         $sqlParts = parent::applyQueryNodeOptions($tableName, $tableAlias, $options, $sqlParts);
     }
     return $sqlParts;
 }
function show_messages($bool = TRUE, $okmsg = NULL, $errmsg = NULL)
{
    global $page, $ZBX_MESSAGES;
    if (!defined('PAGE_HEADER_LOADED')) {
        return;
    }
    if (defined('ZBX_API_REQUEST')) {
        return;
    }
    if (!isset($page['type'])) {
        $page['type'] = PAGE_TYPE_HTML;
    }
    $message = array();
    $width = 0;
    $height = 0;
    $img_space = null;
    if (!$bool && !is_null($errmsg)) {
        $msg = S_CONFIG_ERROR_HEAD . ': ' . $errmsg;
    } else {
        if ($bool && !is_null($okmsg)) {
            $msg = $okmsg;
        }
    }
    $api_errors = CZBXAPI::resetErrors();
    if (!empty($api_errors)) {
        error($api_errors);
    }
    if (isset($msg)) {
        switch ($page['type']) {
            case PAGE_TYPE_IMAGE:
                array_push($message, array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68), 'font' => 2));
                $width = max($width, ImageFontWidth(2) * zbx_strlen($msg) + 1);
                $height += imagefontheight(2) + 1;
                break;
            case PAGE_TYPE_XML:
                echo htmlspecialchars($msg) . "\n";
                break;
                //				case PAGE_TYPE_JS: break;
            //				case PAGE_TYPE_JS: break;
            case PAGE_TYPE_HTML:
            default:
                $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr');
                $msg_tab->setCellPadding(0);
                $msg_tab->setCellSpacing(0);
                $row = array();
                $msg_col = new CCol(bold($msg), 'msg_main msg');
                $msg_col->setAttribute('id', 'page_msg');
                $row[] = $msg_col;
                if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
                    $msg_details = new CDiv(S_DETAILS, 'blacklink');
                    $msg_details->setAttribute('onclick', "javascript: ShowHide('msg_messages', IE?'block':'table');");
                    $msg_details->setAttribute('title', S_MAXIMIZE . '/' . S_MINIMIZE);
                    array_unshift($row, new CCol($msg_details, 'clr'));
                }
                $msg_tab->addRow($row);
                $msg_tab->show();
                $img_space = new CImg('images/general/tree/zero.gif', 'space', '100', '2');
                break;
        }
    }
    if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
        if ($page['type'] == PAGE_TYPE_IMAGE) {
            $msg_font = 2;
            foreach ($ZBX_MESSAGES as $msg) {
                if ($msg['type'] == 'error') {
                    array_push($message, array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55), 'font' => $msg_font));
                } else {
                    array_push($message, array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55), 'font' => $msg_font));
                }
                $width = max($width, imagefontwidth($msg_font) * zbx_strlen($msg['message']) + 1);
                $height += imagefontheight($msg_font) + 1;
            }
        } else {
            if ($page['type'] == PAGE_TYPE_XML) {
                foreach ($ZBX_MESSAGES as $msg) {
                    echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n";
                }
            } else {
                $lst_error = new CList(null, 'messages');
                foreach ($ZBX_MESSAGES as $msg) {
                    $lst_error->addItem($msg['message'], $msg['type']);
                    $bool = $bool && 'error' != zbx_strtolower($msg['type']);
                }
                //message scroll if needed
                $msg_show = 6;
                $msg_count = count($ZBX_MESSAGES);
                if ($msg_count > $msg_show) {
                    $msg_count = $msg_show;
                    $msg_count = $msg_count * 16;
                    $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;');
                }
                $tab = new CTable(null, $bool ? 'msgok' : 'msgerr');
                $tab->setCellPadding(0);
                $tab->setCellSpacing(0);
                $tab->setAttribute('id', 'msg_messages');
                $tab->setAttribute('style', 'width: 100%;');
                if (isset($msg_tab) && $bool) {
                    $tab->setAttribute('style', 'display: none;');
                }
                $tab->addRow(new CCol($lst_error, 'msg'));
                $tab->Show();
                //---
            }
        }
        $ZBX_MESSAGES = null;
    }
    if (!is_null($img_space)) {
        print unpack_object($img_space);
    }
    if ($page['type'] == PAGE_TYPE_IMAGE && count($message) > 0) {
        $width += 2;
        $height += 2;
        $canvas = imagecreate($width, $height);
        imagefilledrectangle($canvas, 0, 0, $width, $height, imagecolorallocate($canvas, 255, 255, 255));
        foreach ($message as $id => $msg) {
            $message[$id]['y'] = 1 + (isset($previd) ? $message[$previd]['y'] + $message[$previd]['h'] : 0);
            $message[$id]['h'] = imagefontheight($msg['font']);
            imagestring($canvas, $msg['font'], 1, $message[$id]['y'], $msg['text'], imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']));
            $previd = $id;
        }
        imageOut($canvas);
        imagedestroy($canvas);
    }
}
Exemple #16
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 applyQueryNodeOptions($tableName, $tableAlias, array $options, array $sqlParts)
 {
     // only apply the node option if no specific ids are given
     if ($options['groupids'] === null && $options['hostids'] === null && $options['templateids'] === null && $options['graphids'] === null && $options['triggerids'] === null) {
         $sqlParts = parent::applyQueryNodeOptions($tableName, $tableAlias, $options, $sqlParts);
     }
     return $sqlParts;
 }
Exemple #18
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;
 }
 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;
 }
Exemple #20
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;
 }
Exemple #21
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;
 }
Exemple #22
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;
 }
Exemple #23
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;
 }
Exemple #24
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;
 }
Exemple #25
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;
 }
Exemple #26
0
 /**
  * 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;
 }
Exemple #27
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;
 }
Exemple #28
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;
 }
Exemple #29
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;
 }
 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;
 }