/** * Additionally allows to create new interfaces on hosts. * * Checks write permissions for hosts. * * Additional supported $data parameters are: * - interfaces - an array of interfaces to create on the hosts * - templates - an array of templates to link to the hosts, overrides the CHostGeneral::massAdd() * 'templates' parameter * * @param array $data * * @return array */ public function massAdd(array $data) { $hosts = isset($data['hosts']) ? zbx_toArray($data['hosts']) : []; $hostIds = zbx_objectValues($hosts, 'hostid'); // check permissions if (!$this->isWritable($hostIds)) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.')); } // add new interfaces if (!empty($data['interfaces'])) { API::HostInterface()->massAdd(['hosts' => $data['hosts'], 'interfaces' => zbx_toArray($data['interfaces'])]); } // rename the "templates" parameter to the common "templates_link" if (isset($data['templates'])) { $data['templates_link'] = $data['templates']; unset($data['templates']); } $data['templates'] = []; return parent::massAdd($data); }
/** * Additionally allows to link templates to hosts and other templates. * * Checks write permissions for templates. * * Additional supported $data parameters are: * - hosts - an array of hosts or templates to link the given templates to * * @param array $data * * @return array */ public function massAdd(array $data) { $templates = isset($data['templates']) ? zbx_toArray($data['templates']) : array(); $templateids = zbx_objectValues($templates, 'templateid'); // check permissions if (!$this->isWritable($templateids)) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.')); } // link hosts to the given templates if (isset($data['hosts']) && !empty($data['hosts'])) { $hostIds = zbx_objectValues($data['hosts'], 'hostid'); // check if any of the hosts are discovered $this->checkValidator($hostIds, new CHostNormalValidator(array('message' => _('Cannot update templates on discovered host "%1$s".')))); $this->link($templateids, $hostIds); } $data['hosts'] = array(); return parent::massAdd($data); }
/** * Additionally allows to link templates to hosts and other templates. * * Checks write permissions for templates. * * Additional supported $data parameters are: * - hosts - an array of hosts or templates to link the given templates to * * @param array $data * * @return array */ public function massAdd(array $data) { $templates = isset($data['templates']) ? zbx_toArray($data['templates']) : array(); $templateids = zbx_objectValues($templates, 'templateid'); // check permissions if (!$this->isWritable($templateids)) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.')); } // link hosts to the given templates if (isset($data['hosts']) && !empty($data['hosts'])) { $this->link($templateids, zbx_objectValues($data['hosts'], 'hostid')); } $data['hosts'] = array(); return parent::massAdd($data); }
/** * Additionally allows to link templates to hosts and other templates. * * Checks write permissions for templates. * * Additional supported $data parameters are: * - hosts - an array of hosts or templates to link the given templates to * * @param array $data * * @return array */ public function massAdd(array $data) { $templates = isset($data['templates']) ? zbx_toArray($data['templates']) : []; $templateIds = zbx_objectValues($templates, 'templateid'); // check permissions if (!$this->isWritable($templateIds)) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!')); } // link hosts to the given templates if (isset($data['hosts']) && !empty($data['hosts'])) { $hostIds = zbx_objectValues($data['hosts'], 'hostid'); if (!API::Host()->isWritable($hostIds)) { self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!')); } // check if any of the hosts are discovered $this->checkValidator($hostIds, new CHostNormalValidator(['message' => _('Cannot update templates on discovered host "%1$s".')])); $this->link($templateIds, $hostIds); } $data['hosts'] = []; return parent::massAdd($data); }