function data_query() { global $data_query_input_types; $menu_items = array("remove" => "Remove", "duplicate" => "Duplicate"); $data_queries = api_data_query_list(); form_start("data_queries.php"); $box_id = "1"; html_start_box("<strong>" . _("Data Queries") . "</strong>", "data_queries.php?action=edit"); html_header_checkbox(array(_("Name"), _("Input Type")), $box_id); if (sizeof($data_queries) > 0) { foreach ($data_queries as $data_query) { ?> <tr class="item" id="box-<?php echo $box_id; ?> -row-<?php echo $data_query["id"]; ?> " onClick="display_row_select('<?php echo $box_id; ?> ',document.forms[0],'box-<?php echo $box_id; ?> -row-<?php echo $data_query["id"]; ?> ', 'box-<?php echo $box_id; ?> -chk-<?php echo $data_query["id"]; ?> ')" onMouseOver="display_row_hover('box-<?php echo $box_id; ?> -row-<?php echo $data_query["id"]; ?> ')" onMouseOut="display_row_clear('box-<?php echo $box_id; ?> -row-<?php echo $data_query["id"]; ?> ')"> <td class="title"> <a class="linkEditMain" onClick="display_row_block('box-<?php echo $box_id; ?> -row-<?php echo $data_query["id"]; ?> ')" href="data_queries.php?action=edit&id=<?php echo $data_query["id"]; ?> "><span id="box-<?php echo $box_id; ?> -text-<?php echo $data_query["id"]; ?> "><?php echo $data_query["name"]; ?> </span></a> </td> <td> <?php echo $data_query_input_types[$data_query["input_type"]]; ?> </td> <td class="checkbox" width="1%" align="center"> <input type='checkbox' name='box-<?php echo $box_id; ?> -chk-<?php echo $data_query["id"]; ?> ' id='box-<?php echo $box_id; ?> -chk-<?php echo $data_query["id"]; ?> ' title="<?php echo $data_query["name"]; ?> "> </td> </tr> <?php } html_box_toolbar_draw($box_id, "0", "2"); } else { ?> <tr class="empty"> <td colspan="2"> No data queries found. </td> </tr> <?php } html_end_box(false); html_box_actions_menu_draw($box_id, "0", $menu_items); html_box_actions_area_create($box_id); form_end(); ?> <script language="JavaScript"> <!-- function action_area_handle_type(box_id, type, parent_div, parent_form) { if (type == 'remove') { parent_div.appendChild(document.createTextNode('Are you sure you want to remove these data queries?')); parent_div.appendChild(action_area_generate_selected_rows(box_id)); action_area_update_header_caption(box_id, 'Remove Data Queries'); action_area_update_submit_caption(box_id, 'Remove'); action_area_update_selected_rows(box_id, parent_form); }else if (type == 'duplicate') { parent_div.appendChild(document.createTextNode('Are you sure you want to duplicate these data queries?')); parent_div.appendChild(action_area_generate_selected_rows(box_id)); parent_div.appendChild(action_area_generate_input('text', 'box-' + box_id + '-action-area-txt1', '')); action_area_update_header_caption(box_id, 'Duplicate Data Queries'); action_area_update_submit_caption(box_id, 'Duplicate'); action_area_update_selected_rows(box_id, parent_form); } } --> </script> <?php require_once CACTI_BASE_PATH . "/include/bottom_footer.php"; }
function template_edit() { global $colors, $data_source_types; if (!empty($_GET["id"])) { $data_template = db_fetch_row("select * from data_template where id=" . $_GET["id"]); $data_template_items = db_fetch_assoc("select * from data_template_item where data_template_id=" . $_GET["id"]); $header_label = _("[edit: ") . $data_template["template_name"] . "]"; } else { $header_label = _("[new]"); } form_start("data_templates.php", "form_data_template"); /* ==================== Box: Data Template ==================== */ html_start_box("<strong>" . _("Data Template") . "</strong> {$header_label}"); _data_template_field__template_name("template_name", isset($data_template) ? $data_template["template_name"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); html_end_box(); /* ==================== Box: Data Input ==================== */ /* determine current value for 'data_input_type' */ if (isset($_GET["data_input_type"])) { $_data_input_type = $_GET["data_input_type"]; } else { if (isset($data_template["data_input_type"])) { $_data_input_type = $data_template["data_input_type"]; } else { $_data_input_type = DATA_INPUT_TYPE_SCRIPT; } } /* get a list of all data input type fields for this data template */ if (isset($data_template)) { $data_input_type_fields = array_rekey(db_fetch_assoc("select name,t_value,value from data_template_field where data_template_id = " . $data_template["id"]), "name", array("t_value", "value")); } else { $data_input_type_fields = array(); } html_start_box("<strong>" . _("Data Input") . "</strong>"); _data_source_input_field__data_input_type("data_input_type", true, $_data_input_type, empty($_GET["id"]) ? 0 : $_GET["id"]); /* grab the appropriate data input type form array */ if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) { $scripts = api_script_list(); if (sizeof($scripts) > 0) { /* determine current value for 'script_id' */ if (isset($_GET["script_id"]) && is_numeric($_GET["script_id"])) { $_script_id = $_GET["script_id"]; } else { if (isset($data_input_type_fields["script_id"])) { $_script_id = $data_input_type_fields["script_id"]["value"]; } else { /* default to the first item in the script list */ $_script_id = $scripts[0]["id"]; } } field_row_header(_("External Script")); _data_source_input_field__script_id("dif_script_id", "data_templates.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_input_type={$_data_input_type}&script_id=|dropdown_value|", $_script_id); /* get each INPUT field for this script */ $script_input_fields = db_fetch_assoc("select * from data_input_fields where data_input_id = {$_script_id} and input_output='in' order by name"); if (sizeof($script_input_fields) > 0) { field_row_header(_("Custom Input Fields")); foreach ($script_input_fields as $field) { _data_source_input_field__script("dif_" . $field["data_name"], $field["name"], true, isset($data_input_type_fields[$field["data_name"]]) ? $data_input_type_fields[$field["data_name"]]["value"] : "", "t_dif_" . $field["data_name"], isset($data_input_type_fields[$field["data_name"]]) ? $data_input_type_fields[$field["data_name"]]["t_value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0); } } } } else { if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) { /* since the "sql" key is not executed until draw_edit_form(), we have fetch the list of * data queries here as well */ $data_queries = api_data_query_list(); if (sizeof($data_queries) > 0) { /* determine current value for 'data_query_id' */ if (isset($_GET["data_query_id"]) && is_numeric($_GET["data_query_id"])) { $_data_query_id = $_GET["data_query_id"]; } else { if (isset($data_input_type_fields["data_query_id"])) { $_data_query_id = $data_input_type_fields["data_query_id"]["value"]; } else { /* default to the first item in the data query list */ $_data_query_id = $data_queries[0]["id"]; } } field_row_header(_("Data Query")); _data_source_input_field__data_query_id("dif_data_query_id", "data_templates.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_input_type={$_data_input_type}&data_query_id=|dropdown_value|", $_data_query_id); } } else { if ($_data_input_type == DATA_INPUT_TYPE_SNMP) { _data_source_input_field__device_hdr_generic(); _data_source_input_field__device_snmp_port("dif_snmp_port", true, isset($data_input_type_fields["snmp_port"]) ? $data_input_type_fields["snmp_port"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_port"]) ? $data_input_type_fields["snmp_port"]["t_value"] : "0", isset($data_input_type_fields["snmp_port"]) ? "on" : ""); _data_source_input_field__device_snmp_timeout("dif_snmp_timeout", true, isset($data_input_type_fields["snmp_timeout"]) ? $data_input_type_fields["snmp_timeout"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_timeout"]) ? $data_input_type_fields["snmp_timeout"]["t_value"] : "0", isset($data_input_type_fields["snmp_timeout"]) ? "on" : ""); _data_source_input_field__device_snmp_version("dif_snmp_version", true, isset($data_input_type_fields["snmp_version"]) ? $data_input_type_fields["snmp_version"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_version"]) ? $data_input_type_fields["snmp_version"]["t_value"] : "0", isset($data_input_type_fields["snmp_version"]) ? "on" : ""); _data_source_input_field__device_hdr_snmpv12(); _data_source_input_field__device_snmp_community("dif_snmp_community", true, isset($data_input_type_fields["snmp_community"]) ? $data_input_type_fields["snmp_community"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_community"]) ? $data_input_type_fields["snmp_community"]["t_value"] : "0", isset($data_input_type_fields["snmp_community"]) ? "on" : ""); _data_source_input_field__device_hdr_snmpv3(); _data_source_input_field__device_snmpv3_auth_username("dif_snmpv3_auth_username", true, isset($data_input_type_fields["snmpv3_auth_username"]) ? $data_input_type_fields["snmpv3_auth_username"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_username"]) ? $data_input_type_fields["snmpv3_auth_username"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_username"]) ? "on" : ""); _data_source_input_field__device_snmpv3_auth_password("dif_snmpv3_auth_password", true, isset($data_input_type_fields["snmpv3_auth_password"]) ? $data_input_type_fields["snmpv3_auth_password"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_password"]) ? $data_input_type_fields["snmpv3_auth_password"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_password"]) ? "on" : ""); _data_source_input_field__device_snmpv3_auth_protocol("dif_snmpv3_auth_protocol", true, isset($data_input_type_fields["snmpv3_auth_protocol"]) ? $data_input_type_fields["snmpv3_auth_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_protocol"]) ? $data_input_type_fields["snmpv3_auth_protocol"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_protocol"]) ? "on" : ""); _data_source_input_field__device_snmpv3_priv_passphrase("dif_snmpv3_priv_passphrase", true, isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? $data_input_type_fields["snmpv3_priv_passphrase"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? $data_input_type_fields["snmpv3_priv_passphrase"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? "on" : ""); _data_source_input_field__device_snmpv3_priv_protocol("dif_snmpv3_priv_protocol", true, isset($data_input_type_fields["snmpv3_priv_protocol"]) ? $data_input_type_fields["snmpv3_priv_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_priv_protocol"]) ? $data_input_type_fields["snmpv3_priv_protocol"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_priv_protocol"]) ? "on" : ""); } } } html_end_box(); /* ==================== Box: Data Source ==================== */ $rra_items = api_data_template_rra_item_list($data_template["id"]); /* the user clicked the "add item" link. we need to make sure they get redirected back to * this page if an error occurs */ if ($_GET["action"] == "sv_add") { form_hidden_box("redirect_sv_add", "x", ""); } html_start_box("<strong>" . _("Data Source") . "</strong>"); _data_source_field__name("name", true, empty($_GET["id"]) ? 0 : $_GET["id"], "t_name", isset($data_template["t_name"]) ? $data_template["t_name"] : ""); _data_source_field__rra("preset_rra_id", true, isset($data_template["preset_rra_id"]) ? $data_template["preset_rra_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _data_source_field__polling_interval("polling_interval", true, isset($data_template["polling_interval"]) ? $data_template["polling_interval"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_polling_interval", isset($data_template["t_polling_interval"]) ? $data_template["t_polling_interval"] : ""); _data_source_field__active("active", true, isset($data_template["active"]) ? $data_template["active"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_active", isset($data_template["t_active"]) ? $data_template["t_active"] : ""); html_end_box(); /* ==================== Box: Data Source Item ==================== */ html_start_box("<strong>" . _("Data Source Item") . "</strong>", empty($_GET["id"]) ? "" : "javascript:document.forms[0].action.value='item_add';submit_redirect(0, '" . htmlspecialchars("data_templates.php?action=item_add&id=" . $_GET["id"]) . "', '')"); /* the user clicked the "add item" link. we need to make sure they get redirected back to * this page if an error occurs */ if ($_GET["action"] == "item_add") { form_hidden_box("redirect_item_add", "x", ""); } /* this allows a "blank" data template item to be displayed when the user wants to create * a new one */ if (!isset($data_template_items) || sizeof($data_template_items) == 0 || $_GET["action"] == "item_add") { if (isset($data_template_items)) { $next_index = sizeof($data_template_items); } else { $next_index = 0; } $data_template_items[$next_index] = array(); } if (sizeof($data_template_items) > 0) { if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) { $script_output_fields = db_fetch_assoc("select * from data_input_fields where data_input_id = {$_script_id} and input_output='out' order by name"); $field_input_description = _("Script Output Field"); } else { if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) { $field_list = api_data_query_field_list($_data_query_id, DATA_QUERY_FIELD_TYPE_OUTPUT); $data_query_output_fields = array(); if (sizeof($field_list) > 0) { foreach ($field_list as $field) { $data_query_output_fields[$field["name"]] = $field["name"] . " (" . $field["name_desc"] . ")"; } } $field_input_description = _("Data Query Output Field"); } else { if ($_data_input_type == DATA_INPUT_TYPE_SNMP) { $field_input_description = _("SNMP OID"); } } } foreach ($data_template_items as $item) { if ($_data_input_type != DATA_INPUT_TYPE_NONE) { ?> <tr bgcolor="<?php print $colors["header_panel_background"]; ?> "> <td class='textSubHeaderDark' colspan="2"> <?php print isset($item["data_source_name"]) ? $item["data_source_name"] : "(" . _("New Data Template Item") . ")"; ?> </td> <td class='textSubHeaderDark' align='right'> <?php if (isset($item["id"]) && sizeof($data_template_items) > 1) { print "[<a href='data_templates.php?action=item_remove&id=" . $item["id"] . "&data_template_id=" . $item["data_template_id"] . "' class='linkOverDark'>remove</a>]\n"; } ?> </td> </tr> <tr bgcolor="#e1e1e1"> <td width="50%" style="border-bottom: 1px solid #a1a1a1;"> <font class='textEditTitle'>Field Input: <?php print $field_input_description; ?> </font><br> </td> <td style="border-bottom: 1px solid #a1a1a1;" colspan="2"> <?php if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) { form_dropdown("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), $script_output_fields, "name", "data_name", isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", ""); } else { if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) { form_dropdown("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), $data_query_output_fields, "", "", isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", ""); } else { if ($_data_input_type == DATA_INPUT_TYPE_SNMP) { form_text_box("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "100", 40, "text", 0); } } } ?> </td> </tr> <?php } $_field_id = isset($item["id"]) ? $item["id"] : 0; field_reset_row_color(); field_increment_row_color(); _data_source_item_field__data_source_name("dsi|data_source_name|{$_field_id}", true, isset($item["data_source_name"]) ? $item["data_source_name"] : "", $_field_id); _data_source_item_field__rrd_minimum("dsi|rrd_minimum|{$_field_id}", true, isset($item["rrd_minimum"]) ? $item["rrd_minimum"] : "", $_field_id, "dsi|t_rrd_minimum|{$_field_id}", isset($item["t_rrd_minimum"]) ? $item["t_rrd_minimum"] : ""); _data_source_item_field__rrd_maximum("dsi|rrd_maximum|{$_field_id}", true, isset($item["rrd_maximum"]) ? $item["rrd_maximum"] : "", $_field_id, "dsi|t_rrd_maximum|{$_field_id}", isset($item["t_rrd_maximum"]) ? $item["t_rrd_maximum"] : ""); _data_source_item_field__data_source_type("dsi|data_source_type|{$_field_id}", true, isset($item["data_source_type"]) ? $item["data_source_type"] : "", $_field_id, "dsi|t_data_source_type|{$_field_id}", isset($item["t_data_source_type"]) ? $item["t_data_source_type"] : ""); _data_source_item_field__rrd_heartbeat("dsi|rrd_heartbeat|{$_field_id}", true, isset($item["rrd_heartbeat"]) ? $item["rrd_heartbeat"] : "", $_field_id, "dsi|t_rrd_heartbeat|{$_field_id}", isset($item["t_rrd_heartbeat"]) ? $item["t_rrd_heartbeat"] : ""); } } html_end_box(); form_hidden_box("data_template_id", empty($_GET["id"]) ? 0 : $_GET["id"], ""); form_hidden_box("action_post", "data_template_edit"); form_save_button("data_templates.php"); }
function template_edit() { global $colors, $fields_host_template_edit; display_output_messages(); if (!empty($_GET["id"])) { $host_template = db_fetch_row("select * from host_template where id=" . $_GET["id"]); $header_label = "[edit: " . $host_template["name"] . "]"; } else { $header_label = "[new]"; $_GET["id"] = 0; } html_start_box("<strong>" . _("Device Templates") . "</strong> {$header_label}", "98%", $colors["header_background"], "3", "center", ""); draw_edit_form(array("config" => array(), "fields" => inject_form_variables($fields_host_template_edit, isset($host_template) ? $host_template : array()))); html_end_box(); if (!empty($_GET["id"])) { html_start_box("<strong>" . _("Associated Graph Templates") . "</strong>", "98%", $colors["header_background"], "3", "center", ""); $selected_graph_templates = db_fetch_assoc("select\n\t\t\tgraph_template.id,\n\t\t\tgraph_template.template_name\n\t\t\tfrom graph_template,host_template_graph\n\t\t\twhere graph_template.id=host_template_graph.graph_template_id\n\t\t\tand host_template_graph.host_template_id=" . $_GET["id"] . "\n\t\t\torder by graph_template.template_name"); $available_graph_templates = db_fetch_assoc("select\n\t\t\tgraph_template.id,\n\t\t\tgraph_template.template_name\n\t\t\tfrom graph_template left join host_template_graph\n\t\t\ton (host_template_graph.graph_template_id = graph_template.id)\n\t\t\twhere host_template_graph.graph_template_id is null\n\t\t\torder by graph_template.template_name"); $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { $i++; ?> <tr bgcolor="<?php print $colors["form_alternate2"]; ?> "> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print $item["template_name"]; ?> </td> <td align="right"> <a href='device_templates.php?action=item_remove_gt&id=<?php print $item["id"]; ?> &host_template_id=<?php print $_GET["id"]; ?> '><img src='<?php print html_get_theme_images_path("delete_icon.gif"); ?> ' width='10' height='10' border='0' alt='Delete'></a> </td> </tr> <?php } } else { print "<tr bgcolor='#" . $colors["form_alternate2"] . "'><td><em>" . _("No associated graph templates.") . "</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"]; ?> "> <td colspan="2"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap><?php echo _("Add Graph Template"); ?> : <?php form_dropdown("graph_template_id", $available_graph_templates, "template_name", "id", "", "", ""); ?> </td> <td align="right"> <input type="image" src="<?php print html_get_theme_images_path('button_add.gif'); ?> " alt="Add" name="add_gt" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); html_start_box("<strong>" . _("Associated Data Queries") . "</strong>", "98%", $colors["header_background"], "3", "center", ""); $selected_data_queries = db_fetch_assoc("select\n\t\t\tdata_query.id,\n\t\t\tdata_query.name\n\t\t\tfrom data_query,host_template_data_query\n\t\t\twhere data_query.id=host_template_data_query.data_query_id\n\t\t\tand host_template_data_query.host_template_id=" . $_GET["id"] . "\n\t\t\torder by data_query.name"); $i = 0; if (sizeof($selected_data_queries) > 0) { foreach ($selected_data_queries as $item) { $i++; ?> <tr bgcolor="<?php print $colors["form_alternate2"]; ?> "> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print $item["name"]; ?> </td> <td align='right'> <a href='device_templates.php?action=item_remove_dq&id=<?php print $item["id"]; ?> &host_template_id=<?php print $_GET["id"]; ?> '><img src='<?php print html_get_theme_images_path("delete_icon.gif"); ?> ' width='10' height='10' border='0' alt='Delete'></a> </td> </tr> <?php } } else { print "<tr bgcolor='#" . $colors["form_alternate2"] . "'><td><em>" . _("No associated data queries.") . "</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"]; ?> "> <td colspan="2"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap><?php echo _("Add Data Query"); ?> : <?php form_dropdown("snmp_query_id", api_data_query_list(), "name", "id", "", "", ""); ?> </td> <td align="right"> <input type="image" src="<?php print html_get_theme_images_path('button_add.gif'); ?> " alt="Add" name="add_dq" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); } form_save_button("device_templates.php"); }