Beispiel #1
0
     $messageSuccess = _('Template added');
     $messageFailed = _('Cannot add template');
     $auditAction = AUDIT_ACTION_ADD;
     $result = API::Template()->create($template);
     if ($result) {
         $templateId = reset($result['templateids']);
     } else {
         throw new Exception();
     }
 }
 // full clone
 if ($templateId && $cloneTemplateId && getRequest('form') === 'full_clone') {
     if (!copyApplications($cloneTemplateId, $templateId)) {
         throw new Exception();
     }
     if (!copyItems($cloneTemplateId, $templateId)) {
         throw new Exception();
     }
     // copy web scenarios
     if (!copyHttpTests($cloneTemplateId, $templateId)) {
         throw new Exception();
     }
     // copy triggers
     $dbTriggers = API::Trigger()->get(array('output' => array('triggerid'), 'hostids' => $cloneTemplateId, 'inherited' => false));
     if ($dbTriggers) {
         $result &= copyTriggersToHosts(zbx_objectValues($dbTriggers, 'triggerid'), $templateId, $cloneTemplateId);
         if (!$result) {
             throw new Exception();
         }
     }
     // copy graphs
     add_audit_ext(AUDIT_ACTION_ADD, AUDIT_RESOURCE_HOST, $hostId, $host['host'], null, null, null);
 } else {
     $hostId = $host['hostid'] = $_REQUEST['hostid'];
     if (!API::Host()->update($host)) {
         throw new Exception();
     }
     $hostNew = API::Host()->get(array('hostids' => $hostId, 'editable' => true, 'output' => API_OUTPUT_EXTEND));
     $hostNew = reset($hostNew);
     add_audit_ext(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_HOST, $hostNew['hostid'], $hostNew['host'], 'hosts', $hostOld, $hostNew);
 }
 if ($_REQUEST['form'] == 'full_clone') {
     $srcHostId = get_request('hostid');
     if (!copyApplications($srcHostId, $hostId)) {
         throw new Exception();
     }
     if (!copyItems($srcHostId, $hostId)) {
         throw new Exception();
     }
     // clone triggers
     $triggers = API::Trigger()->get(array('output' => array('triggerid'), 'hostids' => $srcHostId, 'inherited' => false));
     if ($triggers) {
         if (!copyTriggersToHosts(zbx_objectValues($triggers, 'triggerid'), $hostId, $srcHostId)) {
             throw new Exception();
         }
     }
     // clone discovery rules
     $discoveryRules = API::DiscoveryRule()->get(array('output' => array('itemid'), 'hostids' => $srcHostId, 'inherited' => false));
     if ($discoveryRules) {
         $copyDiscoveryRules = API::DiscoveryRule()->copy(array('discoveryids' => zbx_objectValues($discoveryRules, 'itemid'), 'hostids' => array($hostId)));
         if (!$copyDiscoveryRules) {
             throw new Exception();
     }
 } else {
     $created = true;
     $result = API::Template()->create($template);
     if ($result) {
         $templateid = reset($result['templateids']);
     } else {
         throw new Exception();
     }
 }
 // Full clone
 if (!zbx_empty($templateid) && $templateid && $clone_templateid && $_REQUEST['form'] == 'full_clone') {
     if (!copyApplications($clone_templateid, $templateid)) {
         throw new Exception();
     }
     if (!copyItems($clone_templateid, $templateid)) {
         throw new Exception();
     }
     // clone triggers
     $triggers = API::Trigger()->get(array('output' => API_OUTPUT_SHORTEN, 'hostids' => $clone_templateid, 'inherited' => false));
     if ($triggers) {
         if (!copyTriggersToHosts(zbx_objectValues($triggers, 'triggerid'), $templateid, $clone_templateid)) {
             throw new Exception();
         }
     }
     // Host graphs
     $db_graphs = API::Graph()->get(array('hostids' => $clone_templateid, 'inherited' => false, 'output' => API_OUTPUT_REFER));
     $result = true;
     foreach ($db_graphs as $db_graph) {
         $result &= (bool) copy_graph_to_host($db_graph['graphid'], $templateid);
     }