// 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)) { throw new Exception(); } } } // }}} FULL CLONE
// 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) { add_audit_ext(AUDIT_ACTION_ADD, AUDIT_RESOURCE_TEMPLATE, $templateid, $template_name, 'hosts', NULL, NULL); } unset($_REQUEST['form']);