Exemplo n.º 1
0
 protected function link(array $templateIds, array $targetIds)
 {
     $hostsLinkageInserts = parent::link($templateIds, $targetIds);
     foreach ($hostsLinkageInserts as $hostTplIds) {
         Manager::Application()->link($hostTplIds['templateid'], $hostTplIds['hostid']);
         API::DiscoveryRule()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::Itemprototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::HostPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::Item()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         Manager::HttpTest()->link($hostTplIds['templateid'], $hostTplIds['hostid']);
     }
     // we do linkage in two separate loops because for triggers you need all items already created on host
     foreach ($hostsLinkageInserts as $hostTplIds) {
         API::Trigger()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::TriggerPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::GraphPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::Graph()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
     }
     foreach ($hostsLinkageInserts as $hostTplIds) {
         API::Trigger()->syncTemplateDependencies(array('templateids' => $hostTplIds['templateid'], 'hostids' => $hostTplIds['hostid']));
     }
     return $hostsLinkageInserts;
 }
Exemplo n.º 2
0
 protected function link(array $templateIds, array $targetIds)
 {
     if (!$this->isWritable($targetIds)) {
         self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
     }
     return parent::link($templateIds, $targetIds);
 }
Exemplo n.º 3
0
 protected function link(array $templateids, array $targetids)
 {
     if (!$this->isWritable($targetids)) {
         self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
     }
     $links = parent::link($templateids, $targetids);
     foreach ($targetids as $targetid) {
         $linked_templates = API::Template()->get(['output' => [], 'hostids' => [$targetid], 'nopermissions' => true]);
         $result = DBselect('SELECT i.key_,count(*)' . ' FROM items i' . ' WHERE ' . dbConditionInt('i.hostid', array_merge($templateids, array_keys($linked_templates))) . ' GROUP BY i.key_' . ' HAVING count(*)>1', 1);
         if ($row = DBfetch($result)) {
             $target_templates = API::HostPrototype()->get(['output' => ['name'], 'hostids' => [$targetid], 'nopermissions' => true]);
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Item "%1$s" already exists on "%2$s", inherited from another template.', $row['key_'], $target_templates[0]['name']));
         }
     }
     return $links;
 }
Exemplo n.º 4
0
 protected function link(array $templateIds, array $targetIds)
 {
     if (!API::Host()->isWritable($targetIds)) {
         self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
     }
     $hostsLinkageInserts = parent::link($templateIds, $targetIds);
     foreach ($hostsLinkageInserts as $hostTplIds) {
         Manager::Application()->link($hostTplIds['templateid'], $hostTplIds['hostid']);
         API::DiscoveryRule()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::Itemprototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::HostPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::Item()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         Manager::HttpTest()->link($hostTplIds['templateid'], $hostTplIds['hostid']);
     }
     // we do linkage in two separate loops because for triggers you need all items already created on host
     foreach ($hostsLinkageInserts as $hostTplIds) {
         API::Trigger()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::TriggerPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::GraphPrototype()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
         API::Graph()->syncTemplates(array('hostids' => $hostTplIds['hostid'], 'templateids' => $hostTplIds['templateid']));
     }
     foreach ($hostsLinkageInserts as $hostTplIds) {
         API::Trigger()->syncTemplateDependencies(array('templateids' => $hostTplIds['templateid'], 'hostids' => $hostTplIds['hostid']));
     }
     return $hostsLinkageInserts;
 }