function copy_template_elements($hostid, $templateid = null, $copy_mode = false) { $result = true; copy_template_applications($hostid, $templateid, $copy_mode); copy_template_items($hostid, $templateid, $copy_mode); copy_template_triggers($hostid, $templateid, $copy_mode); // razvilka $copy if ($copy_mode) { copy_template_graphs($hostid, $templateid, $copy_mode); } else { $result = CGraph::syncTemplates(array('hostids' => $hostid, 'templateids' => $templateid)); } return $result; }
function copy_template_graphs($hostid, $templateid = null, $copy_mode = false) { if ($templateid == null) { $templateid = get_templates_by_hostid($hostid); $templateid = array_keys($templateid); } if (is_array($templateid)) { foreach ($templateid as $key => $id) { copy_template_graphs($hostid, $id, $copy_mode); } // attention recursion return; } $db_graphs = get_graphs_by_hostid($templateid); if ($copy_mode) { while ($db_graph = DBfetch($db_graphs)) { copy_graph_to_host($db_graph["graphid"], $hostid, $copy_mode); } } else { while ($db_graph = DBfetch($db_graphs)) { $gitems = CGraphItem::get(array('graphids' => $db_graph['graphid'], 'output' => API_OUTPUT_EXTEND)); $filter = array('name' => $db_graph['name'], 'hostids' => $hostid); if (CGraph::exists($filter)) { $db_graph['gitems'] = $gitems; $res = CGraph::update($db_graph); } else { $db_graph['templateid'] = $db_graph['graphid']; $db_graph['gitems'] = get_same_graphitems_for_host($gitems, $hostid); $res = CGraph::create($db_graph); } if ($res === false) { return false; } } } return true; }
function copy_template_graphs($hostid, $templateid = null, $copy_mode = false) { if ($templateid == null) { $templateid = get_templates_by_hostid($hostid); $templateid = array_keys($templateid); } if (is_array($templateid)) { foreach ($templateid as $key => $id) { copy_template_graphs($hostid, $id, $copy_mode); } // attention recursion return; } $db_graphs = get_graphs_by_hostid($templateid); while ($db_graph = DBfetch($db_graphs)) { copy_graph_to_host($db_graph["graphid"], $hostid, $copy_mode); } }
function copy_template_elements($hostid, $templateid = null, $copy_mode = false) { copy_template_applications($hostid, $templateid, $copy_mode); copy_template_items($hostid, $templateid, $copy_mode); copy_template_triggers($hostid, $templateid, $copy_mode); copy_template_graphs($hostid, $templateid, $copy_mode); }