$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;
                }
                if (httpItemExists($graph['items'])) {
                    continue;
                }
                if (!copyGraphToHost($graph['graphid'], $hostId)) {
                    throw new Exception();
                }
            }
        }
        $result = DBend(true);
        show_messages($result, $msgOk, $msgFail);
        clearCookies($result);
        unset($_REQUEST['form'], $_REQUEST['hostid']);
    } catch (Exception $e) {
        DBend(false);
        show_messages(false, $msgOk, $msgFail);
    }
    unset($_REQUEST['save']);
} elseif (isset($_REQUEST['delete']) && isset($_REQUEST['hostid'])) {
    ###################################################################################################
Пример #2
0
        } else {
            zbx_value2array($_REQUEST['copy_targetid']);
            $dbGroups = API::HostGroup()->get(array('groupids' => $_REQUEST['copy_targetid'], 'nodes' => get_current_nodeid(true), 'editable' => true));
            $dbGroups = zbx_toHash($dbGroups, 'groupid');
            foreach ($_REQUEST['copy_targetid'] as $groupid) {
                if (!isset($dbGroups[$groupid])) {
                    access_deny();
                }
            }
            $options['groupids'] = $_REQUEST['copy_targetid'];
        }
        $dbHosts = API::Host()->get($options);
        DBstart();
        foreach ($_REQUEST['group_graphid'] as $graphid) {
            foreach ($dbHosts as $host) {
                $goResult &= (bool) copyGraphToHost($graphid, $host['hostid']);
            }
        }
        $goResult = DBend($goResult);
        show_messages($goResult, _('Graphs copied'), _('Cannot copy graphs'));
        clearCookies($goResult, empty($_REQUEST['parent_discoveryid']) ? $_REQUEST['hostid'] : $_REQUEST['parent_discoveryid']);
        $_REQUEST['go'] = 'none2';
    } else {
        error(_('No target selected.'));
    }
    show_messages();
}
/*
 * Display
 */
$pageFilter = new CPageFilter(array('groups' => array('not_proxy_hosts' => true, 'editable' => true), 'hosts' => array('editable' => true, 'templated_hosts' => true), 'groupid' => get_request('groupid', null), 'hostid' => get_request('hostid', null)));
Пример #3
0
 // 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();
     }
 }
 // copy template screens
 $dbTemplateScreens = API::TemplateScreen()->get(array('output' => array('screenid'), 'templateids' => $cloneTemplateId, 'preservekeys' => true, 'inherited' => false));
 if ($dbTemplateScreens) {
     $result &= API::TemplateScreen()->copy(array('screenIds' => zbx_objectValues($dbTemplateScreens, 'screenid'), 'templateIds' => $templateId));
     if (!$result) {
         throw new Exception();
Пример #4
0
 // copy web scenarios
 if (!copyHttpTests($cloneTemplateId, $templateId)) {
     throw new Exception();
 }
 // clone triggers
 $triggers = API::Trigger()->get(array('hostids' => $cloneTemplateId, 'output' => array('triggerid'), 'inherited' => false));
 if ($triggers) {
     if (!copyTriggersToHosts(zbx_objectValues($triggers, 'triggerid'), $templateId, $cloneTemplateId)) {
         throw new Exception();
     }
 }
 // host graphs
 $dbGraphs = API::Graph()->get(array('hostids' => $cloneTemplateId, 'inherited' => false, 'output' => API_OUTPUT_REFER));
 $result = true;
 foreach ($dbGraphs as $dbGraph) {
     $result &= (bool) copyGraphToHost($dbGraph['graphid'], $templateId);
 }
 if (!$result) {
     throw new Exception();
 }
 // clone discovery rules
 $discoveryRules = API::DiscoveryRule()->get(array('hostids' => $cloneTemplateId, 'inherited' => false));
 if ($discoveryRules) {
     $copyDiscoveryRules = API::DiscoveryRule()->copy(array('discoveryids' => zbx_objectValues($discoveryRules, 'itemid'), 'hostids' => array($templateId)));
     if (!$copyDiscoveryRules) {
         throw new Exception();
     }
 }
 // clone screens
 $screens = API::TemplateScreen()->get(array('templateids' => $cloneTemplateId, 'output' => array('screenid'), 'preservekeys' => true, 'inherited' => false));
 if ($screens) {