function device_template_to_xml($device_template_id) { require_once(CACTI_BASE_PATH . "/lib/device_template/device_template_info.php"); $hash = get_hash_version("device_template") . get_hash_device_template($device_template_id); $xml_text = ""; $device_template = db_fetch_row("select * from device_template where id=$device_template_id"); $device_template_graph = db_fetch_assoc("select * from device_template_graph where device_template_id=$device_template_id"); $device_template_snmp_query = db_fetch_assoc("select * from device_template_snmp_query where device_template_id=$device_template_id"); if (empty($device_template["id"])) { $err_msg = "Invalid Device Template."; return $err_msg; } $xml_text .= "<hash_$hash>\n"; /* XML Branch: <> */ $fields_device_template_edit = device_template_form_list(); reset($fields_device_template_edit); while (list($field_name, $field_array) = each($fields_device_template_edit)) { if (($field_array["method"] != "hidden_zero") && ($field_array["method"] != "hidden") && ($field_array["method"] != "spacer")) { $xml_text .= "\t<$field_name>" . xml_character_encode($device_template{$field_name}) . "</$field_name>\n"; } } /* XML Branch: <graph_templates> */ $xml_text .= "\t<graph_templates>"; $j = 0; if (sizeof($device_template_graph) > 0) { foreach ($device_template_graph as $item) { $xml_text .= "hash_" . get_hash_version("graph_template") . get_hash_graph_template($item["graph_template_id"]); if (($j+1) < sizeof($device_template_graph)) { $xml_text .= "|"; } $j++; } } $xml_text .= "</graph_templates>\n"; /* XML Branch: <data_queries> */ $xml_text .= "\t<data_queries>"; $j = 0; if (sizeof($device_template_snmp_query) > 0) { foreach ($device_template_snmp_query as $item) { $xml_text .= "hash_" . get_hash_version("data_query") . get_hash_data_query($item["snmp_query_id"]); if (($j+1) < sizeof($device_template_snmp_query)) { $xml_text .= "|"; } $j++; } } $xml_text .= "</data_queries>\n"; $xml_text .= "</hash_$hash>"; return $xml_text; }
function duplicate_device_template($_device_template_id, $device_template_title) { require_once(CACTI_BASE_PATH . "/lib/device_template/device_template_info.php"); $device_template = db_fetch_row("select * from device_template where id=$_device_template_id"); $device_template_graphs = db_fetch_assoc("select * from device_template_graph where device_template_id=$_device_template_id"); $device_template_data_queries = db_fetch_assoc("select * from device_template_snmp_query where device_template_id=$_device_template_id"); /* substitute the title variable */ $device_template["name"] = str_replace(__("<template_title>"), $device_template["name"], $device_template_title); /* create new entry: device_template */ $save["id"] = 0; $save["hash"] = get_hash_device_template(0); $fields_device_template_edit = device_template_form_list(); reset($fields_device_template_edit); while (list($field, $array) = each($fields_device_template_edit)) { if (!preg_match("/^hidden/", $array["method"])) { $save[$field] = $device_template[$field]; } } $device_template_id = sql_save($save, "device_template"); /* create new entry(s): device_template_graph */ if (sizeof($device_template_graphs) > 0) { foreach ($device_template_graphs as $device_template_graph) { db_execute("insert into device_template_graph (device_template_id,graph_template_id) values ($device_template_id," . $device_template_graph["graph_template_id"] . ")"); } } /* create new entry(s): device_template_snmp_query */ if (sizeof($device_template_data_queries) > 0) { foreach ($device_template_data_queries as $device_template_data_query) { db_execute("insert into device_template_snmp_query (device_template_id,snmp_query_id) values ($device_template_id," . $device_template_data_query["snmp_query_id"] . ")"); } } }
function device_template_display_general($device_template, $header_label) { global $colors; require(CACTI_BASE_PATH . "/include/data_query/data_query_arrays.php"); require_once(CACTI_BASE_PATH . "/lib/device_template/device_template_info.php"); print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='device_template_edit'>\n"; html_start_box("<strong>" . __("Device Templates") . "</strong> $header_label", "100", $colors["header"], "0", "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'device_template'); draw_edit_form(array( "config" => array("no_form_tag" => true), "fields" => inject_form_variables(device_template_form_list(), (isset($device_template) ? $device_template : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); form_hidden_box("id", (isset($device_template["id"]) ? $device_template["id"] : "0"), ""); form_hidden_box("save_component_template", "1", ""); ?> <script type="text/javascript"> <!-- // default snmp information var snmp_community = document.getElementById('snmp_community').value; var snmp_username = document.getElementById('snmp_username').value; var snmp_password = document.getElementById('snmp_password').value; var snmp_auth_protocol = document.getElementById('snmp_auth_protocol').value; var snmp_priv_passphrase = document.getElementById('snmp_priv_passphrase').value; var snmp_priv_protocol = document.getElementById('snmp_priv_protocol').value; var snmp_context = document.getElementById('snmp_context').value; var snmp_port = document.getElementById('snmp_port').value; var snmp_timeout = document.getElementById('snmp_timeout').value; var max_oids = document.getElementById('max_oids').value; var device_threads = document.getElementById('device_threads').value; // default ping methods var ping_method = document.getElementById('ping_method').value; var ping_port = document.getElementById('ping_port').value; var ping_timeout = document.getElementById('ping_timeout').value; var ping_retries = document.getElementById('ping_retries').value; // default availability methods var availability_methods = document.getElementById('availability_method').options; var num_methods = document.getElementById('availability_method').length; var selectedIndex = document.getElementById('availability_method').selectedIndex; var agent = navigator.userAgent; agent = agent.match("MSIE"); function setPingVisibility() { availability_method = document.getElementById('availability_method').value; ping_method = document.getElementById('ping_method').value; /* debugging, uncomment as required */ //alert("The availability method is '" + availability_method + "'"); //alert("The ping method is '" + ping_method + "'"); switch(availability_method) { case "0": // none document.getElementById('row_ping_method').style.display = "none"; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = "none"; document.getElementById('row_ping_retries').style.display = "none"; break; case "2": // snmp document.getElementById('row_ping_method').style.display = "none"; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; default: // ping ok switch(ping_method) { case "1": // ping icmp document.getElementById('row_ping_method').style.display = ""; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; case "2": // ping udp case "3": // ping tcp document.getElementById('row_ping_method').style.display = ""; document.getElementById('row_ping_port').style.display = ""; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; } break; } } function addSelectItem(item, formObj) { if (agent != "MSIE") { formObj.add(item,null); // standards compliant }else{ formObj.add(item); // IE only } } function setAvailability(type) { /* get the availability structure */ var am=document.getElementById('availability_method'); /* get current selectedIndex */ selectedIndex = document.getElementById('availability_method').selectedIndex; /* debugging uncomment as required */ //alert("The selectedIndex is '" + selectedIndex + "'"); //alert("The array length is '" + am.length + "'"); switch(type) { case "NoSNMP": /* remove snmp options */ if (am.length == 4) { am.remove(1); am.remove(1); } /* set the index to something valid, like "ping" */ if (selectedIndex > 1) { am.selectedIndex=1; } break; case "All": /* restore all options */ if (am.length == 2) { am.remove(0); am.remove(0); var a=document.createElement('option'); var b=document.createElement('option'); var c=document.createElement('option'); var d=document.createElement('option'); a.value="0"; a.text="<?php print __("None");?>"; addSelectItem(a,am); b.value="1"; b.text="<?php print __("Ping and SNMP");?>"; addSelectItem(b,am); c.value="2"; c.text="<?php print __("SNMP");?>"; addSelectItem(c,am); d.value="3"; d.text="<?php print __("Ping");?>"; addSelectItem(d,am); /* restore the correct index number */ if (selectedIndex == 0) { am.selectedIndex = 0; }else{ am.selectedIndex = 3; } } break; } setAvailabilityVisibility(type, am.selectedIndex); setPingVisibility(); } function setAvailabilityVisibility(type, selectedIndex) { switch(type) { case "NoSNMP": switch(selectedIndex) { case "0": // availability none document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value=0; break; case "1": // ping document.getElementById('row_ping_method').style.display=""; document.getElementById('ping_method').value=ping_method; break; } case "All": switch(selectedIndex) { case "0": // availability none document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value=0; break; case "1": // ping and snmp case "3": // ping if ((document.getElementById('row_ping_method').style.display == "none") || (document.getElementById('row_ping_method').style.display == undefined)) { document.getElementById('ping_method').value=ping_method; document.getElementById('row_ping_method').style.display=""; } break; case "2": // snmp document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value="0"; break; } } } function changeHostForm() { snmp_version = document.getElementById('snmp_version').value; switch(snmp_version) { case "0": setAvailability("NoSNMP"); setSNMP("None"); break; case "1": case "2": setAvailability("All"); setSNMP("v1v2"); break; case "3": setAvailability("All"); setSNMP("v3"); break; } } function setSNMP(snmp_type) { switch(snmp_type) { case "None": document.getElementById('row_snmp_username').style.display = "none"; document.getElementById('row_snmp_password').style.display = "none"; document.getElementById('row_snmp_community').style.display = "none"; document.getElementById('row_snmp_auth_protocol').style.display = "none"; document.getElementById('row_snmp_priv_passphrase').style.display = "none"; document.getElementById('row_snmp_priv_protocol').style.display = "none"; document.getElementById('row_snmp_context').style.display = "none"; document.getElementById('row_snmp_port').style.display = "none"; document.getElementById('row_snmp_timeout').style.display = "none"; document.getElementById('row_max_oids').style.display = "none"; break; case "v1v2": document.getElementById('row_snmp_username').style.display = "none"; document.getElementById('row_snmp_password').style.display = "none"; document.getElementById('row_snmp_community').style.display = ""; document.getElementById('row_snmp_auth_protocol').style.display = "none"; document.getElementById('row_snmp_priv_passphrase').style.display = "none"; document.getElementById('row_snmp_priv_protocol').style.display = "none"; document.getElementById('row_snmp_context').style.display = "none"; document.getElementById('row_snmp_port').style.display = ""; document.getElementById('row_snmp_timeout').style.display = ""; document.getElementById('row_max_oids').style.display = ""; break; case "v3": document.getElementById('row_snmp_username').style.display = ""; document.getElementById('row_snmp_password').style.display = ""; document.getElementById('row_snmp_community').style.display = "none"; document.getElementById('row_snmp_auth_protocol').style.display = ""; document.getElementById('row_snmp_priv_passphrase').style.display = ""; document.getElementById('row_snmp_priv_protocol').style.display = ""; document.getElementById('row_snmp_context').style.display = ""; document.getElementById('row_snmp_port').style.display = ""; document.getElementById('row_snmp_timeout').style.display = ""; document.getElementById('row_max_oids').style.display = ""; break; } } function toggleAvailabilityAndSnmp(show) { if (show) { $('#row_override_permitted').show(); $('#row_availability_header').show(); $('#row_availability_method').show(); $('#row_ping_method').show(); $('#row_ping_port').show(); $('#row_ping_timeout').show(); $('#row_ping_retries').show(); $('#row_snmp_spacer').show(); $('#row_snmp_version').show(); $('#row_snmp_username').show(); $('#row_snmp_password').show(); $('#row_snmp_community').show(); $('#row_snmp_auth_protocol').show(); $('#row_snmp_priv_passphrase').show(); $('#row_snmp_priv_protocol').show(); $('#row_snmp_context').show(); $('#row_snmp_port').show(); $('#row_snmp_timeout').show(); $('#row_max_oids').show(); $('#row_device_threads').show(); changeHostForm(); }else{ $('#row_override_permitted').hide(); $('#row_availability_header').hide(); $('#row_availability_method').hide(); $('#row_ping_method').hide(); $('#row_ping_port').hide(); $('#row_ping_timeout').hide(); $('#row_ping_retries').hide(); $('#row_snmp_spacer').hide(); $('#row_snmp_version').hide(); $('#row_snmp_username').hide(); $('#row_snmp_password').hide(); $('#row_snmp_community').hide(); $('#row_snmp_auth_protocol').hide(); $('#row_snmp_priv_passphrase').hide(); $('#row_snmp_priv_protocol').hide(); $('#row_snmp_context').hide(); $('#row_snmp_port').hide(); $('#row_snmp_timeout').hide() $('#row_max_oids').hide(); $('#row_device_threads').hide(); } } /* jQuery stuff */ $().ready(function() { toggleAvailabilityAndSnmp(document.getElementById('override_defaults').checked); /* Hide options when override is turned off */ $("#override_defaults").change(function () { toggleAvailabilityAndSnmp(this.checked); }); /* Hide "Uptime Goes Backwards" if snmp_version has been set to "None" */ $("#snmp_version").change(function () { /* get PHP constants into javascript namespace */ var reindex_none = <?php print DATA_QUERY_AUTOINDEX_NONE;?>; var reindex_reboot = <?php print DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME;?>; /* we require numeric values for comparison */ var current_reindex = parseInt($(this).val()); switch (current_reindex) { case reindex_none: /* now that SNMP is disabled, select reindex method "None" */ $("#reindex_method option[value=" + reindex_none + "]").attr('selected', 'true'); /* disable SNMP options: "Uptime Goes Backwards" never works with pure Script Data Queries */ $("#reindex_method option[value=" + reindex_reboot + "]").attr('disabled', 'true'); $("#reindex_method option[value=" + reindex_reboot + "]").attr('title', '<?php print __("Disabled due to SNMP settings");?>'); break; default: /* "Uptime Goes Backwards" is allowed again */ $("#reindex_method option[value=" + reindex_reboot + "]").removeAttr("disabled"); $("#reindex_method option[value=" + reindex_reboot + "]").attr('title', ''); /* select this again as default reindex method */ /* TODO: this ignores the default reindex method of the associated Device Template to get it, an AJAX call is required */ $("#reindex_method option[value=" + reindex_reboot + "]").attr('selected', 'true'); } }); }); //--> </script> <?php form_save_button_alt("url!device_templates.php"); }