$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();
         }
     }
     $graphs = API::Graph()->get(array('hostids' => $srcHostId, 'selectItems' => array('type'), 'output' => API_OUTPUT_EXTEND, 'inherited' => false, 'selectHosts' => array('hostid'), 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL)));
     foreach ($graphs as $graph) {
         if (count($graph['hosts']) > 1) {
             continue;
Beispiel #2
0
 // 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
     $dbGraphs = API::Graph()->get(array('output' => array('graphid'), 'hostids' => $cloneTemplateId, 'inherited' => false));
     foreach ($dbGraphs as $dbGraph) {
         copyGraphToHost($dbGraph['graphid'], $templateId);
     }
     // copy discovery rules
     $dbDiscoveryRules = API::DiscoveryRule()->get(array('output' => array('itemid'), 'hostids' => $cloneTemplateId, 'inherited' => false));
     if ($dbDiscoveryRules) {
         $result &= API::DiscoveryRule()->copy(array('discoveryids' => zbx_objectValues($dbDiscoveryRules, 'itemid'), 'hostids' => array($templateId)));
         if (!$result) {
             throw new Exception();
Beispiel #3
0
} elseif ($_REQUEST['go'] == 'copy_to' && isset($_REQUEST['copy']) && isset($_REQUEST['g_triggerid'])) {
    if (isset($_REQUEST['copy_targetid']) && $_REQUEST['copy_targetid'] > 0 && isset($_REQUEST['copy_type'])) {
        if ($_REQUEST['copy_type'] == 0) {
            // hosts
            $hosts_ids = $_REQUEST['copy_targetid'];
        } else {
            // groups
            $hosts_ids = array();
            $group_ids = $_REQUEST['copy_targetid'];
            $db_hosts = DBselect('SELECT DISTINCT h.hostid' . ' FROM hosts h,hosts_groups hg' . ' WHERE h.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.groupid', $group_ids));
            while ($db_host = DBfetch($db_hosts)) {
                $hosts_ids[] = $db_host['hostid'];
            }
        }
        DBstart();
        $goResult = copyTriggersToHosts($_REQUEST['g_triggerid'], $hosts_ids, get_request('hostid'));
        $goResult = DBend($goResult);
        show_messages($goResult, _('Trigger added'), _('Cannot add trigger'));
        clearCookies($goResult, $_REQUEST['hostid']);
        $_REQUEST['go'] = 'none2';
    } else {
        show_error_message(_('No target selected'));
    }
} elseif ($_REQUEST['go'] == 'delete' && isset($_REQUEST['g_triggerid'])) {
    $goResult = API::Trigger()->delete($_REQUEST['g_triggerid']);
    show_messages($goResult, _('Triggers deleted'), _('Cannot delete triggers'));
    clearCookies($goResult, $_REQUEST['hostid']);
}
/*
 * Display
 */
     } 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);
     }
     if (!$result) {
         throw new Exception();
     }
     // clone discovery rules
     $discoveryRules = API::DiscoveryRule()->get(array('hostids' => $clone_templateid, 'inherited' => false));
     if ($discoveryRules) {
Beispiel #5
0
    show_messages($result, $messageSuccess, $messageFailed);
} elseif (hasRequest('action') && getRequest('action') == 'trigger.masscopyto' && hasRequest('copy') && hasRequest('g_triggerid')) {
    if (hasRequest('copy_targetid') && getRequest('copy_targetid') > 0 && hasRequest('copy_type')) {
        // hosts or templates
        if (getRequest('copy_type') == COPY_TYPE_TO_HOST || getRequest('copy_type') == COPY_TYPE_TO_TEMPLATE) {
            $hosts_ids = getRequest('copy_targetid');
        } else {
            $hosts_ids = array();
            $group_ids = getRequest('copy_targetid');
            $db_hosts = DBselect('SELECT DISTINCT h.hostid' . ' FROM hosts h,hosts_groups hg' . ' WHERE h.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.groupid', $group_ids));
            while ($db_host = DBfetch($db_hosts)) {
                $hosts_ids[] = $db_host['hostid'];
            }
        }
        DBstart();
        $result = copyTriggersToHosts(getRequest('g_triggerid'), $hosts_ids, getRequest('hostid'));
        $result = DBend($result);
        if ($result) {
            uncheckTableRows(getRequest('hostid'));
            unset($_REQUEST['g_triggerid']);
        }
        show_messages($result, _('Trigger added'), _('Cannot add trigger'));
    } else {
        show_error_message(_('No target selected'));
    }
} elseif (hasRequest('action') && getRequest('action') == 'trigger.massdelete' && hasRequest('g_triggerid')) {
    $result = API::Trigger()->delete(getRequest('g_triggerid'));
    if ($result) {
        uncheckTableRows(getRequest('hostid'));
    }
    show_messages($result, _('Triggers deleted'), _('Cannot delete triggers'));