Ejemplo n.º 1
0
     $msg_ok = S_HOST_ADDED;
     $msg_fail = S_CANNOT_ADD_HOST;
     /*			$audit_action 	= AUDIT_ACTION_ADD;*/
 }
 if (!zbx_empty($hostid) && $hostid && $clone_hostid && $_REQUEST['form'] == 'full_clone') {
     // Host applications
     $sql = 'SELECT * FROM applications WHERE hostid=' . $clone_hostid . ' AND templateid=0';
     $res = DBselect($sql);
     while ($db_app = DBfetch($res)) {
         add_application($db_app['name'], $hostid, 0);
     }
     // Host items
     $sql = 'SELECT DISTINCT i.itemid, i.description ' . ' FROM items i ' . ' WHERE i.hostid=' . $clone_hostid . ' AND i.templateid=0 ' . ' ORDER BY i.description';
     $res = DBselect($sql);
     while ($db_item = DBfetch($res)) {
         $result &= copy_item_to_host($db_item['itemid'], $hostid, true);
     }
     // Host triggers
     $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array($clone_hostid), PERM_RES_IDS_ARRAY);
     $sql = 'SELECT DISTINCT t.triggerid, t.description ' . ' FROM triggers t, items i, functions f' . ' WHERE i.hostid=' . $clone_hostid . ' AND f.itemid=i.itemid ' . ' AND t.triggerid=f.triggerid ' . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' AND t.templateid=0 ' . ' ORDER BY t.description';
     $res = DBselect($sql);
     while ($db_trig = DBfetch($res)) {
         $result &= copy_trigger_to_host($db_trig['triggerid'], $hostid, true);
     }
     // Host graphs
     $available_graphs = get_accessible_graphs(PERM_READ_ONLY, array($clone_hostid), PERM_RES_IDS_ARRAY);
     $sql = 'SELECT DISTINCT g.graphid, g.name ' . ' FROM graphs g, graphs_items gi,items i ' . ' WHERE ' . DBcondition('g.graphid', $available_graphs) . ' AND gi.graphid=g.graphid ' . ' AND g.templateid=0 ' . ' AND i.itemid=gi.itemid ' . ' AND i.hostid=' . $clone_hostid . ' ORDER BY g.name';
     $res = DBselect($sql);
     while ($db_graph = DBfetch($res)) {
         $result &= copy_graph_to_host($db_graph['graphid'], $hostid, true);
     }
Ejemplo n.º 2
0
     $host_new = reset($host_new);
     add_audit_ext(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_HOST, $host['hostid'], $host['host'], 'hosts', $host_old, $host_new);
 }
 // FULL CLONE {{{
 if ($clone_hostid && $_REQUEST['form'] == 'full_clone') {
     // Host applications
     $sql = 'SELECT * FROM applications WHERE hostid=' . $clone_hostid . ' AND templateid=0';
     $res = DBselect($sql);
     while ($db_app = DBfetch($res)) {
         add_application($db_app['name'], $hostid, 0);
     }
     // Host items
     $sql = 'SELECT DISTINCT i.itemid, i.description ' . ' FROM items i ' . ' WHERE i.hostid=' . $clone_hostid . ' AND i.templateid=0 ' . ' ORDER BY i.description';
     $res = DBselect($sql);
     while ($db_item = DBfetch($res)) {
         if (!copy_item_to_host($db_item['itemid'], $hostid, true)) {
             throw new Exception();
         }
     }
     // Host triggers
     if (!copy_triggers($clone_hostid, $hostid)) {
         throw new Exception();
     }
     // Host graphs
     $options = array('inherited' => 0, 'hostids' => $clone_hostid, 'select_hosts' => API_OUTPUT_REFER, 'output' => API_OUTPUT_EXTEND);
     $graphs = CGraph::get($options);
     foreach ($graphs as $gnum => $graph) {
         if (count($graph['hosts']) > 1) {
             continue;
         }
         if (!copy_graph_to_host($graph['graphid'], $hostid, true)) {
Ejemplo n.º 3
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 ' . DBcondition('hg.groupid', $group_ids));
             while ($db_host = DBfetch($db_hosts)) {
                 array_push($hosts_ids, $db_host['hostid']);
             }
         }
         $result = false;
         DBstart();
         foreach ($_REQUEST['group_itemid'] as $item_id) {
             foreach ($hosts_ids as $host_id) {
                 $result |= copy_item_to_host($item_id, $host_id, true);
             }
         }
         $result = DBend($result);
         show_messages($result, S_ITEMS_COPIED, S_CANNOT_COPY_ITEMS);
         $_REQUEST['go'] = 'none';
     } else {
         error('No target selection.');
     }
     show_messages();
 } else {
     if ($_REQUEST['go'] == 'clean_history' && isset($_REQUEST['group_itemid'])) {
         $result = false;
         $group_itemid = $_REQUEST['group_itemid'];
         DBstart();
         foreach ($group_itemid as $id) {
Ejemplo n.º 4
0
     $msg_fail = S_CANNOT_ADD_TEMPLATE;
 }
 // }}} CREATE/UPDATE TEMPLATE
 // FULL_CLONE {
 if (!zbx_empty($templateid) && $templateid && $clone_templateid && $_REQUEST['form'] == 'full_clone') {
     // Host applications
     $sql = 'SELECT * FROM applications WHERE hostid=' . $clone_templateid . ' AND templateid=0';
     $res = DBselect($sql);
     while ($db_app = DBfetch($res)) {
         add_application($db_app['name'], $templateid, 0);
     }
     // Host items
     $sql = 'SELECT DISTINCT i.itemid, i.description ' . ' FROM items i ' . ' WHERE i.hostid=' . $clone_templateid . ' AND i.templateid=0 ' . ' ORDER BY i.description';
     $res = DBselect($sql);
     while ($db_item = DBfetch($res)) {
         $result &= (bool) copy_item_to_host($db_item['itemid'], $templateid, true);
     }
     // Host triggers
     $result &= copy_triggers($clone_templateid, $templateid);
     // Host graphs
     $options = array('hostids' => $clone_templateid, 'inherited' => 0, 'output' => API_OUTPUT_REFER);
     $db_graphs = CGraph::get($options);
     foreach ($db_graphs as $gnum => $db_graph) {
         $result &= (bool) copy_graph_to_host($db_graph['graphid'], $templateid, true);
     }
 }
 // }
 $result = DBend($result);
 show_messages($result, $msg_ok, $msg_fail);
 if ($result) {
     if ($created) {