function copy_template_triggers($hostid, $templateid = null, $copy_mode = false) { if (null == $templateid) { $templateid = array_keys(get_templates_by_hostid($hostid)); } if (is_array($templateid)) { foreach ($templateid as $id) { copy_template_triggers($hostid, $id, $copy_mode); } // attention recursion return; } $triggers = get_triggers_by_hostid($templateid); while ($trigger = DBfetch($triggers)) { copy_trigger_to_host($trigger["triggerid"], $hostid, $copy_mode); } update_template_dependencies_for_host($hostid); }
$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); } $_REQUEST['hostid'] = $clone_hostid; } $result = DBend($result); if ($result) { update_profile('HOST_PORT', $_REQUEST['port'], PROFILE_TYPE_INT); DBstart(); delete_host_profile($hostid);
/* 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['g_triggerid'] as $trigger_id) { foreach ($hosts_ids as $host_id) { $result |= copy_trigger_to_host($trigger_id, $host_id, true); } } $result = DBend($result); unset($_REQUEST['form_copy_to']); } else { error('No target selection.'); } show_messages($result, S_TRIGGER_ADDED, S_CANNOT_ADD_TRIGGER); } else { if (isset($_REQUEST['add_dependence']) && isset($_REQUEST['new_dependence'])) { if (!isset($_REQUEST['dependencies'])) { $_REQUEST['dependencies'] = array(); } foreach ($_REQUEST['new_dependence'] as $triggerid) { if (!uint_in_array($triggerid, $_REQUEST['dependencies'])) {
} else { // groups $hosts_ids = array(); $group_ids = $_REQUEST['copy_targetid']; $sql = 'SELECT DISTINCT h.hostid ' . ' FROM hosts h, hosts_groups hg' . ' WHERE h.hostid=hg.hostid ' . ' AND ' . DBcondition('hg.groupid', $group_ids); $db_hosts = DBselect($sql); while ($db_host = DBfetch($db_hosts)) { array_push($hosts_ids, $db_host['hostid']); } } $go_result = false; $new_triggerids = array(); DBstart(); foreach ($hosts_ids as $num => $host_id) { foreach ($_REQUEST['g_triggerid'] as $tnum => $trigger_id) { $newtrigid = copy_trigger_to_host($trigger_id, $host_id, true); $new_triggerids[$trigger_id] = $newtrigid; $go_result |= (bool) $newtrigid; } // replace_triggers_depenedencies($new_triggerids); } $go_result = DBend($go_result); $_REQUEST['go'] = 'none2'; } else { error('No target selection.'); } show_messages($go_result, S_TRIGGER_ADDED, S_CANNOT_ADD_TRIGGER); } else { if ($_REQUEST['go'] == 'delete' && isset($_REQUEST['g_triggerid'])) { DBstart(); $triggerids = array();
$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 &= copy_item_to_host($db_item['itemid'], $templateid, true); } // Host triggers $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array($clone_templateid), PERM_RES_IDS_ARRAY); $sql = 'SELECT DISTINCT t.triggerid, t.description ' . ' FROM triggers t, items i, functions f' . ' WHERE i.hostid=' . $clone_templateid . ' 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'], $templateid, true); } // Host graphs $available_graphs = get_accessible_graphs(PERM_READ_ONLY, array($clone_templateid), 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_templateid . ' ORDER BY g.name'; $res = DBselect($sql); while ($db_graph = DBfetch($res)) { $result &= copy_graph_to_host($db_graph['graphid'], $templateid, true); } } // --->>> <<<--- // <<<--- LINK/UNLINK HOSTS --->>> if ($result) { $hosts = array_intersect($hosts, $available_hosts); //-- unlink -- $linked_hosts = array();