예제 #1
0
 /**
  * Check item data and set flags field.
  *
  * @param array $items
  * @param bool  $update
  *
  * @return void
  */
 protected function checkInput(array &$items, $update = false)
 {
     parent::checkInput($items, $update);
     self::validateInventoryLinks($items, $update);
     // set proper flags to divide normal and discovered items in future processing
     if ($update) {
         $dbItems = $this->get(array('itemids' => zbx_objectValues($items, 'itemid'), 'output' => array('itemid', 'flags'), 'editable' => true, 'preservekeys' => true));
         foreach ($items as &$item) {
             $item['flags'] = $dbItems[$item['itemid']]['flags'];
         }
         unset($item);
     } else {
         foreach ($items as &$item) {
             $item['flags'] = ZBX_FLAG_DISCOVERY_NORMAL;
             // set default formula value
             if (!isset($item['formula'])) {
                 $item['formula'] = '1';
             }
         }
         unset($item);
     }
 }
예제 #2
0
 /**
  * Check item prototype data and set flags field.
  *
  * @param array $items passed by reference
  * @param bool  $update
  *
  * @return void
  */
 protected function checkInput(array &$items, $update = false)
 {
     parent::checkInput($items, $update);
     // set proper flags to divide normal and discovered items in future processing
     foreach ($items as &$item) {
         $item['flags'] = ZBX_FLAG_DISCOVERY_PROTOTYPE;
         // set default formula value
         if (!$update && !isset($item['formula'])) {
             $item['formula'] = '1';
         }
     }
     unset($item);
 }
 /**
  * Check item prototype data and set flags field.
  *
  * @param array $items passed by reference
  * @param bool  $update
  *
  * @return void
  */
 protected function checkInput(array &$items, $update = false)
 {
     // add the values that cannot be changed, but are required for further processing
     foreach ($items as &$item) {
         $item['flags'] = ZBX_FLAG_DISCOVERY_CHILD;
     }
     unset($item);
     parent::checkInput($items, $update);
 }
예제 #4
0
 /**
  * Check item data and set flags field.
  *
  * @param array $items passed by reference
  * @param bool  $update
  *
  * @return void
  */
 protected function checkInput(array &$items, $update = false)
 {
     // add the values that cannot be changed, but are required for further processing
     foreach ($items as &$item) {
         $item['flags'] = ZBX_FLAG_DISCOVERY_NORMAL;
     }
     unset($item);
     // validate if everything is ok with 'item->inventory fields' linkage
     self::validateInventoryLinks($items, $update);
     parent::checkInput($items, $update);
 }
예제 #5
0
 /**
  * Check item data and set missing default values.
  *
  * @param array $items passed by reference
  * @param bool  $update
  * @param array $dbItems
  */
 protected function checkInput(array &$items, $update = false, array $dbItems = array())
 {
     // add the values that cannot be changed, but are required for further processing
     foreach ($items as &$item) {
         $item['flags'] = ZBX_FLAG_DISCOVERY_RULE;
         $item['value_type'] = ITEM_VALUE_TYPE_TEXT;
         // unset fields that are updated using the 'filter' parameter
         unset($item['evaltype']);
         unset($item['formula']);
     }
     unset($item);
     parent::checkInput($items, $update);
     $validateItems = $items;
     if ($update) {
         $validateItems = $this->extendFromObjects(zbx_toHash($validateItems, 'itemid'), $dbItems, array('name'));
     }
     // filter validator
     $filterValidator = new CSchemaValidator($this->getFilterSchema());
     // condition validation
     $conditionValidator = new CSchemaValidator($this->getFilterConditionSchema());
     foreach ($validateItems as $item) {
         // validate custom formula and conditions
         if (isset($item['filter'])) {
             $filterValidator->setObjectName($item['name']);
             $this->checkValidator($item['filter'], $filterValidator);
             foreach ($item['filter']['conditions'] as $condition) {
                 $conditionValidator->setObjectName($item['name']);
                 $this->checkValidator($condition, $conditionValidator);
             }
         }
     }
 }
예제 #6
0
 /**
  * Check item prototype data and set flags field.
  *
  * @param array  $items										an array of items passed by reference
  * @param array  $item['applicationPrototypes']				an array of application prototypes
  * @param string $item['applicationPrototypes'][]['name']	application prototype name
  * @param bool	 $update
  */
 protected function checkInput(array &$items, $update = false)
 {
     parent::checkInput($items, $update);
     // set proper flags to divide normal and discovered items in future processing
     foreach ($items as &$item) {
         $item['flags'] = ZBX_FLAG_DISCOVERY_PROTOTYPE;
         // set default formula value
         if (!$update && !isset($item['formula'])) {
             $item['formula'] = '1';
         }
         if (array_key_exists('applicationPrototypes', $item) && is_array($item['applicationPrototypes']) && $item['applicationPrototypes']) {
             // Check that "name" field exists for application prototypes.
             foreach ($item['applicationPrototypes'] as $application_prototype) {
                 if (!array_key_exists('name', $application_prototype)) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Missing "name" field for application prototype in item prototype "%1$s".', $item['name']));
                 }
                 if ($application_prototype['name'] === '') {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Empty application prototype name in item prototype "%1$s".', $item['name']));
                 }
                 if (array_key_exists('templateid', $application_prototype)) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot set "templateid" field for application prototype in item prototype "%1$s".', $item['name']));
                 }
             }
             // Check that "name" field has no duplicate values for application prototypes.
             $duplicate_name = CArrayHelper::findDuplicate($item['applicationPrototypes'], 'name');
             if ($duplicate_name) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Duplicate "name" value "%1$s" for application prototype in item prototype "%2$s".', $duplicate_name['name'], $item['name']));
             }
         }
     }
     unset($item);
 }
예제 #7
0
 /**
  * Update item.
  *
  * @param array $items
  *
  * @return boolean
  */
 public function update($items)
 {
     $items = zbx_toArray($items);
     $dbItems = $this->get(['output' => ['itemid', 'flags'], 'itemids' => zbx_objectValues($items, 'itemid'), 'editable' => true, 'preservekeys' => true]);
     parent::checkInput($items, true);
     self::validateInventoryLinks($items, true);
     foreach ($items as &$item) {
         $item['flags'] = $dbItems[$item['itemid']]['flags'];
     }
     unset($item);
     $this->updateReal($items);
     $this->inherit($items);
     return ['itemids' => zbx_objectValues($items, 'itemid')];
 }