Esempio n. 1
0
 /**
  * Validate graph prototype specific data on Update method.
  * Get allowed item ID's, check permissions, check if items have at least one prototype, do all general validation,
  * and check for numeric item types.
  *
  * @param array $graphs
  * @param array $dbGraphs
  */
 protected function validateUpdate(array $graphs, array $dbGraphs)
 {
     // check for "itemid" when updating graph prototype with only "gitemid" passed
     foreach ($graphs as &$graph) {
         if (isset($graph['gitems'])) {
             foreach ($graph['gitems'] as &$gitem) {
                 if (isset($gitem['gitemid']) && !isset($gitem['itemid'])) {
                     $dbGitems = zbx_toHash($dbGraphs[$graph['graphid']]['gitems'], 'gitemid');
                     $gitem['itemid'] = $dbGitems[$gitem['gitemid']]['itemid'];
                 }
             }
             unset($gitem);
         }
     }
     unset($graph);
     $itemIds = $this->validateItemsUpdate($graphs);
     $allowedItems = API::Item()->get(array('itemids' => $itemIds, 'webitems' => true, 'editable' => true, 'output' => array('itemid', 'name', 'value_type', 'flags'), 'selectItemDiscovery' => array('parent_itemid'), 'preservekeys' => true, 'filter' => array('flags' => array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_PROTOTYPE, ZBX_FLAG_DISCOVERY_CREATED))));
     foreach ($itemIds as $itemId) {
         if (!isset($allowedItems[$itemId])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!'));
         }
     }
     $this->checkDiscoveryRuleCount($graphs, $allowedItems);
     parent::validateUpdate($graphs, $dbGraphs);
     $allowedValueTypes = array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64);
     foreach ($allowedItems as $item) {
         if (!in_array($item['value_type'], $allowedValueTypes)) {
             foreach ($dbGraphs as $dbGraph) {
                 $itemIdsInGraphItems = zbx_objectValues($dbGraph['gitems'], 'itemid');
                 if (in_array($item['itemid'], $itemIdsInGraphItems)) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot add a non-numeric item "%1$s" to graph prototype "%2$s".', $item['name'], $dbGraph['name']));
                 }
             }
         }
     }
 }
 protected function createReal($graph)
 {
     // mark the graph as a graph prototype
     $graph['flags'] = ZBX_FLAG_DISCOVERY_CHILD;
     return parent::createReal($graph);
 }
 protected function applyQueryNodeOptions($tableName, $tableAlias, array $options, array $sqlParts)
 {
     // only apply the node option if no specific ids are given
     if ($options['graphids'] === null && $options['templateids'] === null && $options['hostids'] === null && $options['groupids'] === null && $options['itemids'] === null) {
         $sqlParts = parent::applyQueryNodeOptions($tableName, $tableAlias, $options, $sqlParts);
     }
     return $sqlParts;
 }
Esempio n. 4
0
 /**
  * Validate update.
  *
  * @param array $graphs
  * @param array $dbGraphs
  */
 protected function validateUpdate(array $graphs, array $dbGraphs)
 {
     // check for "itemid" when updating graph with only "gitemid" passed
     foreach ($graphs as &$graph) {
         if (isset($graph['gitems'])) {
             foreach ($graph['gitems'] as &$gitem) {
                 if (isset($gitem['gitemid']) && !isset($gitem['itemid'])) {
                     $dbGitems = zbx_toHash($dbGraphs[$graph['graphid']]['gitems'], 'gitemid');
                     $gitem['itemid'] = $dbGitems[$gitem['gitemid']]['itemid'];
                 }
             }
             unset($gitem);
         }
     }
     unset($graph);
     $itemIds = $this->validateItemsUpdate($graphs);
     $this->validateItems($itemIds, $graphs);
     parent::validateUpdate($graphs, $dbGraphs);
 }
Esempio n. 5
0
 /**
  * Validate graph specific data on Update method.
  * Get allowed item ID's, check permissions, do all general validation and check for numeric item types.
  *
  * @param array $graphs
  * @param array $dbGraphs
  *
  * @return void
  */
 protected function validateUpdate(array $graphs, array $dbGraphs)
 {
     $itemIds = $this->validateItemsUpdate($graphs);
     $this->validateItems($itemIds);
     parent::validateUpdate($graphs, $dbGraphs);
 }
Esempio n. 6
0
 /**
  * Validate graph prototype specific data on Update method.
  * Get allowed item ID's, check permissions, check if items have at least one prototype, do all general validation,
  * and check for numeric item types.
  *
  * @param array $graphs
  * @param array $dbGraphs
  *
  * @return void
  */
 protected function validateUpdate(array $graphs, array $dbGraphs)
 {
     $itemIds = $this->validateItemsUpdate($graphs);
     $allowedItems = API::Item()->get(array('nodeids' => get_current_nodeid(true), 'itemids' => $itemIds, 'webitems' => true, 'editable' => true, 'output' => array('name', 'value_type', 'flags'), 'preservekeys' => true, 'filter' => array('flags' => null)));
     foreach ($itemIds as $itemid) {
         if (!isset($allowedItems[$itemid])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!'));
         }
     }
     foreach ($graphs as $graph) {
         if (isset($graph['gitems'])) {
             $hasPrototype = false;
             if ($graph['gitems']) {
                 // check if the graph has at least one prototype
                 foreach ($graph['gitems'] as $gitem) {
                     // $allowedItems used because it is possible to make API call without full item data
                     if ($allowedItems[$gitem['itemid']]['flags'] == ZBX_FLAG_DISCOVERY_PROTOTYPE) {
                         $hasPrototype = true;
                         break;
                     }
                 }
             }
             if (!$graph['gitems'] || !$hasPrototype) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Graph prototype must have at least one prototype.'));
             }
         }
     }
     parent::validateUpdate($graphs, $dbGraphs);
     $allowedValueTypes = array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64);
     foreach ($allowedItems as $item) {
         if (!in_array($item['value_type'], $allowedValueTypes)) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot add a non-numeric item "%1$s" to graph prototype "%2$s".', $item['name'], $graph['name']));
         }
     }
 }