Example #1
0
 /**
  * Validate create.
  *
  * @param array $graphs
  */
 protected function validateCreate(array $graphs)
 {
     $itemIds = $this->validateItemsCreate($graphs);
     $this->validateItems($itemIds, $graphs);
     parent::validateCreate($graphs);
 }
Example #2
0
 /**
  * Validate graph prototype specific data on Create 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
  */
 protected function validateCreate(array $graphs)
 {
     $itemIds = $this->validateItemsCreate($graphs);
     $allowedItems = API::Item()->get(array('itemids' => $itemIds, 'webitems' => true, 'editable' => true, 'output' => array('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::validateCreate($graphs);
     $allowedValueTypes = array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64);
     foreach ($graphs as $graph) {
         foreach ($graph['gitems'] as $gitem) {
             if (!in_array($allowedItems[$gitem['itemid']]['value_type'], $allowedValueTypes)) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot add a non-numeric item "%1$s" to graph prototype "%2$s".', $allowedItems[$gitem['itemid']]['name'], $graph['name']));
             }
         }
     }
 }
 /**
  * Validate graph prototype specific data on Create 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
  *
  * @return void
  */
 protected function validateCreate(array $graphs)
 {
     $itemIds = $this->validateItemsCreate($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) {
         $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::validateCreate($graphs);
     $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']));
         }
     }
 }