예제 #1
0
function graphs()
{
    global $colors;
    /* use the first host in the list as the default */
    if (!isset($_SESSION["sess_graphs_new_host_id"]) && empty($_REQUEST["host_id"])) {
        $_REQUEST["host_id"] = db_fetch_cell("select id from host order by description,hostname limit 1");
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    if (isset($_REQUEST["host_id"])) {
        $_SESSION["sess_graphs_new_host_id"] = $_REQUEST["host_id"];
    } else {
        $_REQUEST["host_id"] = $_SESSION["sess_graphs_new_host_id"];
    }
    $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]);
    ?>

	<table width="98%" align="center">
		<form name="form_graph_id">
		<tr>
			<td class="textInfo" colspan="2">
				<?php 
    print $host["description"];
    ?>
 (<?php 
    print $host["hostname"];
    ?>
)
			</td>
			<td align="right" class="textInfo" style="color: #aaaaaa;">
				<?php 
    if (!empty($host["host_template_id"])) {
        print db_fetch_cell("select name from host_template where id=" . $host["host_template_id"]);
    }
    ?>
			</td>
		</tr>
		<tr>
			<td>
			</td>
		</tr>

		<tr>
			<td class="textArea" style="padding: 3px;" width="300" nowrap>
				<?php 
    echo _("Create new graphs for the following host:");
    ?>
			</td>
			<td class="textInfo" rowspan="2" valign="top">
				<span style="color: #c16921;">*</span><a href="devices.php?action=edit&id=<?php 
    print $_REQUEST["host_id"];
    ?>
"><?php 
    echo _("Edit this Host");
    ?>
</a><br>
				<span style="color: #c16921;">*</span><a href="devices.php?action=edit"><?php 
    echo _("Create New Host");
    ?>
</a>
			</td>
		</tr>
			<td>
				<select name="cbo_graph_id" onChange="window.location=document.form_graph_id.cbo_graph_id.options[document.form_graph_id.cbo_graph_id.selectedIndex].value">
					<?php 
    $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname");
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $item) {
            print "<option value='graphs_new.php?host_id=" . $item["id"] . "'";
            if ($_REQUEST["host_id"] == $item["id"]) {
                print " selected";
            }
            print ">" . $item["name"] . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
		</tr>
		</form>
	</table>

	<br>

	<form name="chk" method="post" action="graphs_new.php">
	<?php 
    $total_rows = sizeof(db_fetch_assoc("select graph_template_id from host_graph where host_id=" . $_REQUEST["host_id"]));
    /* we give users the option to turn off the javascript features for data queries with lots of rows */
    if (read_config_option("max_data_query_javascript_rows") >= $total_rows) {
        $use_javascript = true;
    } else {
        $use_javascript = false;
    }
    /* ==================== Box: Graph Templates ==================== */
    html_start_box("<strong>" . _("Graph Templates") . "</strong>", "98%", $colors["header_background"], "3", "center", "");
    print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\n\t\t\t<td class='textSubHeaderDark'>" . _("Name") . "</td>\n\t\t\t<td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='" . _("Select All") . "' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n\n\t\t</tr>\n";
    $ht_graph_templates = db_fetch_assoc("select\n\t\tgraph_template.id,\n\t\tgraph_template.template_name\n\t\tfrom host_graph,graph_template\n\t\twhere host_graph.graph_template_id=graph_template.id\n\t\tand host_graph.host_id = " . $_REQUEST["host_id"] . "\n\t\torder by graph_template.template_name");
    $ht_created_graph_templates = db_fetch_assoc("select\n\t\tgraph.graph_template_id\n\t\tfrom graph,host_graph\n\t\twhere graph.graph_template_id=host_graph.graph_template_id\n\t\tand graph.host_id = " . $host["id"] . "\n\t\tgroup by graph.graph_template_id");
    print "<script type='text/javascript'>\nvar gt_created_graphs = new Array()\n</script>\n";
    if (sizeof($ht_created_graph_templates) > 0 && $use_javascript == true) {
        print "<script type='text/javascript'>\n<!--\n";
        print "var gt_created_graphs = new Array(";
        $cg_ctr = 0;
        foreach ($ht_created_graph_templates as $item) {
            print ($cg_ctr > 0 ? "," : "") . "'" . $item["graph_template_id"] . "'";
            $cg_ctr++;
        }
        print ")\n";
        print "//-->\n</script>\n";
    }
    /* create a row for each graph template associated with the host template */
    $i = 0;
    if (sizeof($ht_graph_templates) > 0) {
        foreach ($ht_graph_templates as $item) {
            $query_row = $item["id"];
            print "<tr id='gt_line{$query_row}' bgcolor='#" . ($i % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>";
            $i++;
            print "\t\t<td" . ($use_javascript == true ? " onClick='gt_select_line(" . $item["id"] . ");'" : "") . "><span id='gt_text{$query_row}" . "_0'>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>" . _("Create:") . "</strong> " . $item["template_name"] . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}'" . ($use_javascript == true ? " onClick='gt_update_selection_indicators();'" : "") . ">\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
        }
    } else {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "' colspan=7><em>" . _("No graph templates specified for this host template.") . "</em></td></tr>";
    }
    if ($use_javascript == true) {
        print "<script type='text/javascript'>gt_update_deps(1);</script>\n";
    }
    $available_graph_templates = db_fetch_assoc("SELECT\n\t\tgraph_template.id,\n\t\tgraph_template.template_name as name\n\t\tFROM snmp_query_graph RIGHT JOIN graph_template\n\t\tON (snmp_query_graph.graph_template_id = graph_template.id)\n\t\tWHERE (((snmp_query_graph.name) Is Null))\n\t\tORDER BY graph_template.template_name");
    /* create a row at the bottom that lets the user create any graph they choose */
    print "\t<tr bgcolor='#" . ($i % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>\n\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t<strong>Create:</strong>&nbsp;";
    form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(" . _("Select a graph type to create") . ")", "", "font-size: 10px;");
    print "\t\t</td>\n\t\t</tr>";
    html_end_box();
    /* get a list of all data queries that are assigned to this device */
    $data_queries = api_data_query_device_assigned_list($host["id"]);
    echo "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n";
    if (sizeof($data_queries) > 0) {
        foreach ($data_queries as $data_query) {
            /* we give users the option to turn off the javascript features for data queries with lots of rows */
            if (read_config_option("max_data_query_javascript_rows") >= api_data_query_cache_num_rows_get($data_query["id"], $host["id"])) {
                $use_javascript = true;
            } else {
                $use_javascript = false;
            }
            /* get a list of all graph templates that reference this data query */
            $attached_graph_templates = api_data_query_attached_graphs_list($data_query["id"]);
            /* build a javascript array that keeps tracks of which graphs have already been created */
            if (sizeof($attached_graph_templates) > 0 && $use_javascript == true) {
                echo "<script type='text/javascript'>\n<!--\n";
                foreach ($attached_graph_templates as $graph_template) {
                    /* get a list of all data query indexes that have been created as graphs using this graph template */
                    $created_graphs = api_data_query_graphed_indexes_list($graph_template["id"], $host["id"]);
                    echo "created_graphs[" . $graph_template["id"] . "] = new Array(";
                    $cg_ctr = 0;
                    if (sizeof($created_graphs) > 0) {
                        foreach ($created_graphs as $created_graph) {
                            echo ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["data_query_index"]) . "'";
                            $cg_ctr++;
                        }
                    }
                    echo ")\n";
                }
                echo "//-->\n</script>\n";
            }
            $data_query_indexes = array();
            $data_query_field_names = array();
            $data_query_field_desc = array();
            $num_visible_columns = 0;
            $data_query_fields = api_data_query_field_list($data_query["id"], DATA_QUERY_FIELD_TYPE_INPUT);
            /* retrieve a list of values for each data query field from the cache */
            if (sizeof($data_query_fields) > 0) {
                foreach ($data_query_fields as $field) {
                    $cache_data = api_data_query_cache_field_get($data_query["id"], $host["id"], $field["name"]);
                    /* be sure to ignore the fields which contain no data */
                    if (sizeof($cache_data) > 0) {
                        foreach ($cache_data as $row) {
                            $data_query_data[$row["index_value"]][$field["name"]] = $row["field_value"];
                            if (!in_array($row["index_value"], $data_query_indexes, true)) {
                                $data_query_indexes[] = $row["index_value"];
                            }
                        }
                        /* always make sure that the index field is the first column */
                        if ($data_query["index_field_id"] == $field["id"] && sizeof($data_query_field_names) > 0) {
                            $data_query_field_names[] = $data_query_field_names[0];
                            $data_query_field_names[0] = $field["name"];
                        } else {
                            $data_query_field_names[] = $field["name"];
                        }
                        /* keep a hash of field name->desc mappings for the row headings */
                        $data_query_field_desc[$field["name"]] = $field["name_desc"];
                        $num_visible_columns++;
                    }
                }
            }
            /* if the user specified a prefered sort order; sort the list of indexes before displaying them */
            if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_ALPHABETIC) {
                usort($data_query_indexes, "usort_alphabetic");
            } else {
                if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_NATURAL) {
                    usort($data_query_indexes, "usort_natural");
                } else {
                    if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_NUMERIC) {
                        usort($data_query_indexes, "usort_numeric");
                    }
                }
            }
            ?>
			<table width='98%' style='background-color: #<?php 
            echo $colors["form_alternate2"];
            ?>
; border: 1px solid #<?php 
            echo $colors["header_background"];
            ?>
;' align='center' cellpadding='3' cellspacing='0'>
				<tr>
					<td bgcolor='#<?php 
            echo $colors["header_background"];
            ?>
' colspan='<?php 
            echo sizeof($data_query_field_names) + 1;
            ?>
'>
						<table  cellspacing='0' cellpadding='0' width='100%' >
							<tr>
								<td class='textHeaderDark'>
									<strong><?php 
            echo _("Data Query");
            ?>
</strong> [<?php 
            echo $data_query["name"];
            ?>
]
								</td>
								<td align='right' nowrap>
									<a href='graphs_new.php?action=query_reload&id=<?php 
            echo $data_query["id"];
            ?>
&host_id=<?php 
            echo $host["id"];
            ?>
'><img src='<?php 
            echo html_get_theme_images_path("reload_icon_small.gif");
            ?>
' alt='<?php 
            echo _("Reload Associated Query");
            ?>
' border='0' align='absmiddle'></a>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<?php 
            if (sizeof($attached_graph_templates) == 0) {
                echo "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>" . _("This data query is not being used by any graph templates. You must create at least one graph template that references to a data template using this data query.") . "</td></tr>\n";
            } else {
                if (sizeof($data_query_field_names) == 0) {
                    echo "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>" . _("This data query returned 0 rows, perhaps there was a problem executing this data query. You can") . " <a href='devices.php?action=query_verbose&id=" . $data_query["id"] . "&host_id=" . $host["id"] . "'>" . _("run this data query in debug mode</a> to get more information.") . "</td></tr>\n";
                } else {
                    echo "<tr bgcolor='#" . $colors["header_panel_background"] . "'>\n";
                    foreach ($data_query_field_names as $field_name) {
                        echo "<td height='1'><strong><font color='#" . $colors["header_text"] . "'>" . $data_query_field_desc[$field_name] . "</font></strong></td>\n";
                    }
                    echo "<td width='1%' align='center' bgcolor='#" . $colors["header_panel_background"] . "' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $data_query["id"] . "' title='Select All' onClick='" . _("SelectAll") . "(\"sg_" . $data_query["id"] . "\",this.checked);" . ($use_javascript == true ? "dq_update_selection_indicators();" : "") . "'></td>\n</tr>\n";
                }
            }
            $row_counter = 0;
            foreach ($data_query_indexes as $index_value) {
                $query_row = $data_query["id"] . "_" . encode_data_query_index($index_value);
                echo "<tr id='line{$query_row}' bgcolor='#" . ($row_counter % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>";
                $i++;
                $column_counter = 0;
                foreach ($data_query_field_names as $field_name) {
                    echo "<td " . ($use_javascript == true ? "onClick='dq_select_line(" . $data_query["id"] . ",\"" . encode_data_query_index($index_value) . "\");'" : "") . "><span id='text{$query_row}" . "_" . $column_counter . "'>" . (isset($data_query_data[$index_value][$field_name]) ? $data_query_data[$index_value][$field_name] : "") . "</span></td>";
                    $column_counter++;
                }
                echo "<td align='right'>";
                echo "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' " . ($use_javascript == true ? "onClick='dq_update_selection_indicators();'" : "") . ">";
                echo "</td>";
                echo "</tr>\n";
                $row_counter++;
            }
            echo "</table>";
            if (sizeof($attached_graph_templates) == 1) {
                form_hidden_box("sgg_" . $data_query["id"] . "' id='sgg_" . $data_query["id"], $attached_graph_templates[0]["id"], "");
            } elseif (sizeof($attached_graph_templates) > 1) {
                print "\t<table align='center' width='98%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='1' valign='top'>\n\t\t\t\t\t\t\t\t<img src='" . html_get_theme_images_path("arrow.gif") . "' alt='' align='absmiddle'>&nbsp;\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<span style='font-size: 12px; font-style: italic;'>" . _("Select a graph type:") . "</span>&nbsp;\n\t\t\t\t\t\t\t\t<select name='sgg_" . $data_query["id"] . "' id='sgg_" . $data_query["id"] . "' " . ($use_javascript == true ? "onChange='dq_update_deps(" . $data_query["id"] . "," . $num_visible_columns . ");'" : "") . ">\n\t\t\t\t\t\t\t\t\t";
                html_create_list($attached_graph_templates, "template_name", "id", "0");
                print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>";
            }
            print "<br>";
            if ($use_javascript == true) {
                print "<script type='text/javascript'>dq_update_deps(" . $data_query["id"] . "," . $num_visible_columns . ");</script>\n";
            }
        }
    }
    form_hidden_box("save_component_graph", "1", "");
    form_hidden_box("host_id", $host["id"], "0");
    form_save_button("graphs_new.php");
    print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n";
    print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n";
}
예제 #2
0
function api_data_query_snmp_execute($host_id, $data_query_id) {
	require_once(CACTI_BASE_PATH . "/include/data_query/data_query_constants.php");
	require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_info.php");
	require_once(CACTI_BASE_PATH . "/lib/device/device_info.php");

	/* get information about the data query */
	$data_query = api_data_query_get($data_query_id);

	/* get a list of all input fields defined for this data query */
	$data_query_fields = api_data_query_field_list($data_query_id, DATA_QUERY_FIELD_TYPE_INPUT);

	/* fetch a list of indexes for this data query */
	$field_values{$data_query["index_field_id"]} = api_data_query_snmp_execute_field($host_id, $data_query["index_field_id"]);

	if (($field_values{$data_query["index_field_id"]} === false) || (sizeof($field_values{$data_query["index_field_id"]}) == 0)) {
		debug_log_insert("data_query", _("No indexes returned, cannot continue."));
		return false;
	}

	/* reindex the parsed index values as a hash (value->oid) for quicker access. DUPLICATE INDEX VALUES
	 * WILL CAUSE PROBLEMS HERE */
	foreach ($field_values{$data_query["index_field_id"]} as $result) {
		$index_field_values{$result["value_parsed"]} = true;
	}

	/* clear old data from the data query cache */
	db_execute("delete from host_data_query_cache where host_id = " . sql_sanitize($host_id) . " and data_query_id = " . sql_sanitize($data_query_id));

	if (is_array($data_query_fields)) {
		foreach ($data_query_fields as $field) {
			/* fetch a list of values for this field (assuming that we haven't already seen it */
			if (!isset($field_values{$field["id"]})) {
				$field_values{$field["id"]} = api_data_query_snmp_execute_field($host_id, $field["id"]);
			}else{
				debug_log_insert("data_query", "Walking OID '" . $field["source"] . "' (cached)");
			}

			/* see if we have some output to play with */
			if (($field_values{$field["id"]} !== false) && (sizeof($field_values{$field["id"]}) > 0)) {
				foreach ($field_values{$field["id"]} as $oid => $result) {
					/* stick with the 0.8.x behavior: use the value for the index when the actual value is
					 * derived from the oid */
					if (($field["method_type"] == DATA_QUERY_FIELD_METHOD_OID_OCTET) || ($field["method_type"] == DATA_QUERY_FIELD_METHOD_OID_PARSE)) {
						$expected_index = $result["value"];
					/* find the index at the end of the oid */
					}else{
						$expected_index = substr($oid, strlen($field["source"])+1);
					}

					/* a match for this index has been located */
					if (isset($index_field_values[$expected_index])) {
						debug_log_insert("data_query", sprintf(_("Found value [%s = '%s'] for index [%s]"), $field["name"], $result["value_parsed"], $expected_index));

						db_insert("host_data_query_cache",
							array(
								"host_id" => array("type" => DB_TYPE_INTEGER, "value" => $host_id),
								"data_query_id" => array("type" => DB_TYPE_INTEGER, "value" => $data_query_id),
								"field_name" => array("type" => DB_TYPE_STRING, "value" => $field["name"]),
								"field_value" => array("type" => DB_TYPE_STRING, "value" => $result["value_parsed"]),
								"index_value" => array("type" => DB_TYPE_STRING, "value" => $expected_index),
								"oid" => array("type" => DB_TYPE_STRING, "value" => $oid)
								),
							array("host_id", "data_query_id", "field_name", "index_value"));
					/* a match for this index has not been located */
					}else{
						debug_log_insert("data_query", _("Ignoring unknown index '$expected_index'."));
					}
				}
			}else{
				debug_log_insert("data_query", _("No values returned from the field '" . $field["name"] . "', ignoring."));
			}
		}
	}

	return true;
}
예제 #3
0
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");
}
예제 #4
0
function data_query_edit()
{
    $_data_query_id = get_get_var_number("id");
    if (empty($_data_query_id)) {
        $header_label = "[new]";
    } else {
        $data_query = api_data_query_get($_data_query_id);
        $header_label = "[edit: " . $data_query["name"] . "]";
    }
    form_start("data_queries.php", "form_data_query");
    html_start_box("<strong>" . _("Data Queries") . "</strong> {$header_label}");
    _data_query_field__name("name", isset($data_query["name"]) ? $data_query["name"] : "", isset($data_query["id"]) ? $data_query["id"] : "0");
    _data_query_field__input_type("input_type", isset($data_query["input_type"]) ? $data_query["input_type"] : "", isset($data_query["id"]) ? $data_query["id"] : "0");
    _data_query_field__index_order_type("index_order_type", isset($data_query["index_order_type"]) ? $data_query["index_order_type"] : "", isset($data_query["id"]) ? $data_query["id"] : "0");
    _data_query_field__index_title_format("index_title_format", isset($data_query["index_title_format"]) ? $data_query["index_title_format"] : "|chosen_order_field|", isset($data_query["id"]) ? $data_query["id"] : "0");
    if (!empty($_data_query_id)) {
        _data_query_field__field_specific_hdr();
        _data_query_field__index_order("index_order", isset($data_query["index_order"]) ? $data_query["index_order"] : "", isset($data_query["id"]) ? $data_query["id"] : "0");
        _data_query_field__index_field_id("index_field_id", $_data_query_id, isset($data_query["index_field_id"]) ? $data_query["index_field_id"] : "", isset($data_query["id"]) ? $data_query["id"] : "0");
    }
    /* input type specific fields */
    _data_query_field__snmp_specific_hdr();
    _data_query_field__snmp_oid_num_rows("snmp_oid_num_rows", isset($data_query["snmp_oid_num_rows"]) ? $data_query["snmp_oid_num_rows"] : "", isset($data_query["id"]) ? $data_query["id"] : "0");
    _data_query_field__script_specific_hdr();
    _data_query_field__script_path("script_path", isset($data_query["script_path"]) ? $data_query["script_path"] : "", isset($data_query["id"]) ? $data_query["id"] : "0");
    _data_query_field__script_server_specific_hdr();
    _data_query_field__script_server_function("script_server_function", isset($data_query["script_server_function"]) ? $data_query["script_server_function"] : "", isset($data_query["id"]) ? $data_query["id"] : "0");
    /* be sure that we have the correct input type value show we display the correct form rows */
    if (isset_post_cache_field("input_type")) {
        $_input_type = get_post_cache_field("input_type");
    } else {
        $_input_type = isset($data_query["input_type"]) ? $data_query["input_type"] : "";
    }
    echo "<script language=\"JavaScript\">\n<!--\nupdate_data_query_type_fields('{$_input_type}');\n-->\n</script>\n";
    html_end_box();
    if (!empty($_data_query_id)) {
        html_start_box("<strong>" . _("Data Query Fields") . "</strong>");
        ?>
		<tr class="heading">
			<td colspan="2">
				Input Fields
			</td>
			<td align="right">
				<a href="data_queries.php?action=field_edit&field_type=<?php 
        echo DATA_QUERY_FIELD_TYPE_INPUT;
        ?>
&data_query_id=<?php 
        echo $_data_query_id;
        ?>
">Add</a>
			</td>
		</tr>
		<?php 
        $input_fields = api_data_query_field_list($_data_query_id, DATA_QUERY_FIELD_TYPE_INPUT);
        if (sizeof($input_fields) > 0) {
            foreach ($input_fields as $field) {
                ?>
				<tr class="item" id="row_<?php 
                echo $field["id"];
                ?>
" onClick="display_row_select('row_<?php 
                echo $field["id"];
                ?>
', 'chk_<?php 
                echo $field["id"];
                ?>
')" onMouseOver="display_row_hover('row_<?php 
                echo $field["id"];
                ?>
')" onMouseOut="display_row_clear('row_<?php 
                echo $field["id"];
                ?>
')">
					<td class="title">
						<a class="linkEditMain" onClick="display_row_block('row_<?php 
                echo $field["id"];
                ?>
')" href="data_queries.php?action=field_edit&id=<?php 
                echo $field["id"];
                ?>
&data_query_id=<?php 
                echo $field["data_query_id"];
                ?>
"><?php 
                echo $field["name"];
                ?>
</a>
					</td>
					<td>
						<?php 
                echo $field["name_desc"];
                ?>
					</td>
					<td align="right">
						<input type='checkbox' id='chk_<?php 
                echo $field["id"];
                ?>
' name='chk_<?php 
                echo $field["id"];
                ?>
' title="<?php 
                echo $field["name"];
                ?>
">
					</td>
				</tr>
				<?php 
            }
        } else {
            ?>
			<tr>
				<td class="empty" colspan="2">
					No input fields found. Remember that <strong>at least one index field</strong> must be defined!
				</td>
			</tr>
			<?php 
        }
        ?>
		<tr class="heading">
			<td colspan="2">
				Output Fields
			</td>
			<td align="right">
				<a href="data_queries.php?action=field_edit&field_type=<?php 
        echo DATA_QUERY_FIELD_TYPE_OUTPUT;
        ?>
&data_query_id=<?php 
        echo $_data_query_id;
        ?>
">Add</a>
			</td>
		</tr>
		<?php 
        $output_fields = api_data_query_field_list($_data_query_id, DATA_QUERY_FIELD_TYPE_OUTPUT);
        if (sizeof($output_fields) > 0) {
            foreach ($output_fields as $field) {
                ?>
				<tr class="item" id="row_<?php 
                echo $field["id"];
                ?>
" onClick="display_row_select('row_<?php 
                echo $field["id"];
                ?>
', 'chk_<?php 
                echo $field["id"];
                ?>
')" onMouseOver="display_row_hover('row_<?php 
                echo $field["id"];
                ?>
')" onMouseOut="display_row_clear('row_<?php 
                echo $field["id"];
                ?>
')">
					<td class="item">
						<a class="linkEditMain" onClick="display_row_block('row_<?php 
                echo $field["id"];
                ?>
')" href="data_queries.php?action=field_edit&id=<?php 
                echo $field["id"];
                ?>
&data_query_id=<?php 
                echo $field["data_query_id"];
                ?>
"><?php 
                echo $field["name"];
                ?>
</a>
					</td>
					<td>
						<?php 
                echo $field["name_desc"];
                ?>
					</td>
					<td align="right">
						<input type='checkbox' id='chk_<?php 
                echo $field["id"];
                ?>
' name='chk_<?php 
                echo $field["id"];
                ?>
' title="<?php 
                echo $field["name"];
                ?>
">
					</td>
				</tr>
				<?php 
            }
        } else {
            ?>
			<tr class="empty">
				<td colspan="2">
					No output fields found.
				</td>
			</tr>
			<?php 
        }
        html_end_box();
    }
    form_hidden_box("data_query_id", $_data_query_id);
    form_save_button("data_queries.php", "save_data_query");
}
예제 #5
0
function get_ordered_index_type_list($data_query_id, $host_id) {
	require_once(CACTI_BASE_PATH . "/include/data_query/data_query_constants.php");

	/* sanity checks */
	validate_id_die($data_query_id, "data_query_id");
	validate_id_die($host_id, "host_id");

	/* retrieve information about this data query */
	$data_query = api_data_query_get($data_query_id);

	/* get a list of all input fields for this data query */
	$data_query_fields = array_rekey(api_data_query_field_list($data_query_id, DATA_QUERY_FIELD_TYPE_INPUT), "name", "name_desc");

	$valid_index_fields = array();
	if (sizeof($data_query_fields) > 0) {
		foreach ($data_query_fields as $data_query_field_name => $data_query_field_description) {
			/* create a list of all values for this index */
			$field_values = db_fetch_assoc("select field_value from host_data_query_cache where host_id = " . sql_sanitize($host_id) . " and data_query_id = " . sql_sanitize($data_query_id) . " and field_name = '" . sql_sanitize($data_query_field_name) . "'");

			/* aggregate the above list so there are no duplicates */
			$field_values_nodups = array_rekey($field_values, "field_value", "field_value");

			/* fields that contain duplicate or empty values are not suitable to index off of */
			if (!((sizeof($field_values_nodups) < sizeof($field_values)) || (in_array("", $field_values_nodups) == true) || (sizeof($field_values_nodups) == 0))) {
				array_push($valid_index_fields, $data_query_field_name);
			}
		}
	}

	$return_array = array();

	/* the xml file contains an ordered list of "indexable" fields */
	if (ereg("^([a-zA-Z0-9_-]:?)+$", $data_query["index_order"])) {
		$index_order_array = explode(":", $data_query["index_order"]);

		for ($i=0; $i<count($index_order_array); $i++) {
			if (in_array($index_order_array[$i], $valid_index_fields)) {
				$return_array{$index_order_array[$i]} = $index_order_array[$i] . " (" . $data_query_fields{$index_order_array[$i]} . ")";
			}
		}
	/* the xml file does not contain a field list, ignore the order */
	}else{
		for ($i=0; $i<count($valid_index_fields); $i++) {
			$return_array{$valid_index_fields[$i]} = $valid_index_fields[$i] . " (" . $data_query_fields{$index_order_array[$i]} . ")";
		}
	}

	return $return_array;
}
예제 #6
0
function &package_data_query_export($data_query_id, $indent = 3) {
	require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_info.php");

	$xml = "";

	/*
	 * XML Tag: <data_query>
	 */

	/* obtain a list of all data query specific fields */
	$data_query_fields = api_data_query_form_list();
	/* obtain a copy of this specfic data query */
	$data_query = api_data_query_get($data_query_id);

	$_xml = "";
	foreach (array_keys($data_query_fields) as $field_name) {
		/* create an XML key for each data query field */
		$_xml .= package_xml_tag_get($field_name, xml_character_encode($data_query[$field_name]), $indent + 2);
	}

	/* append the result onto the final XML string */
	$xml .= package_xml_tag_get("data_query", $_xml, $indent + 1, true);

	/*
	 * XML Tag: <fields>
	 */

	/* obtain a list of all data query field specific fields */
	$data_query_field_fields = api_data_query_field_form_list();
	/* obtain a list of all data query fields associated with this data query */
	$data_query_fields = api_data_query_field_list($data_query_id);

	$_xml = "";
	if (sizeof($data_query_fields) > 0) {
		$i = 0;
		foreach ($data_query_fields as $data_query_field) {
			$__xml = "";
			foreach (array_keys($data_query_field_fields) as $field_name) {
				/* create an XML key for each data query item field */
				$__xml .= package_xml_tag_get($field_name, xml_character_encode($data_query_field[$field_name]), $indent + 3);
			}

			/* append the result onto a temporary XML string */
			$_xml .= package_xml_tag_get("item_" . str_pad($i, 5, "0", STR_PAD_LEFT), $__xml, $indent + 2, true);

			$i++;
		}
	}

	/* append the result onto the final XML string */
	$xml .= package_xml_tag_get("fields", $_xml, $indent + 1, true);

	/* wrap the whole XML string into a 'data_query' tag and return it */
	$xml = package_xml_tag_get(package_hash_get($data_query_id, "data_query"), $xml, $indent, true);

	return $xml;
}
예제 #7
0
function _data_query_field__index_field_id($field_name, $data_query_id, $field_value = "", $field_id = 0) {
	require_once(CACTI_BASE_PATH . "/lib/sys/html_form.php");

	?>
	<tr class="<?php echo field_get_row_style();?>">
		<td width="50%" class="field-row">
			<span class="textEditTitle"><?php echo _("Index Field");?></span><br>
			<?php echo _("Select if the values from this input field are to be used as unique indexes for this data query.");?>
		</td>
		<td class="field-row">
			<?php form_dropdown($field_name, api_data_query_field_list($data_query_id, DATA_QUERY_FIELD_TYPE_INPUT), "name", "id", $field_value, "(None Selected)", "");?>
		</td>
		<td class="field-row" align="right">
			<span class="field-required">(required)</span>
		</td>
	</tr>
	<?php
}
예제 #8
0
function ds_edit()
{
    global $colors, $data_source_types;
    $host_id = 0;
    if (!empty($_GET["id"])) {
        $data_source = db_fetch_row("select * from data_source where id = " . $_GET["id"]);
        $data_source_items = db_fetch_assoc("select * from data_source_item where data_source_id = " . $_GET["id"]);
        if (!empty($data_source["data_template_id"])) {
            $data_template = db_fetch_row("select id,name from data_template where id='" . $data_source["data_template_id"] . "'");
        }
        $header_label = _("[edit: ") . api_data_source_title_get($_GET["id"]) . "]";
        /* get a list of all data input type fields for this data template */
        $data_input_type_fields = array_rekey(db_fetch_assoc("select name,value from data_source_field where data_source_id = " . $data_source["id"]), "name", array("value"));
    } else {
        $header_label = _("[new]");
        $data_input_type_fields = array();
    }
    /* handle debug mode */
    if (isset($_GET["debug"])) {
        if ($_GET["debug"] == "0") {
            kill_session_var("ds_debug_mode");
        } elseif ($_GET["debug"] == "1") {
            $_SESSION["ds_debug_mode"] = true;
        }
    }
    if (!empty($_GET["id"])) {
        ?>
		<table width="98%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        print api_data_source_title_get($_GET["id"]);
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
					<span style="color: #c16921;">*<a href='data_sources.php?action=edit&id=<?php 
        print isset($_GET["id"]) ? $_GET["id"] : 0;
        ?>
&debug=<?php 
        print isset($_SESSION["ds_debug_mode"]) ? "0" : "1";
        ?>
'>Turn <strong><?php 
        print isset($_SESSION["ds_debug_mode"]) ? "Off" : "On";
        ?>
</strong> Data Source Debug Mode.</a>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    form_start("data_sources.php", "form_data_source");
    /* ==================== Box: Device/Template Selection ==================== */
    html_start_box("<strong>" . _("Device/Template Selection") . "</strong> {$header_label}");
    _data_source_field__data_template_id("data_template_id", isset($data_source) ? $data_source["data_template_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _data_source_field__host_id("host_id", isset($data_source) ? $data_source["host_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    html_end_box();
    /* ==================== Box: Supplemental Template Data ==================== */
    /* only display the "inputs" area if we are using a data template for this data source */
    if (!empty($data_source["data_template_id"])) {
        ob_start();
        html_start_box("<strong>" . _("Supplemental Template Data") . "</strong>");
        $num_output_fields = draw_nontemplated_fields_data_input($data_source["data_template_id"], $data_input_type_fields, "dif_|field|", "<strong>" . _("Data Input") . "</strong>", true);
        if ($data_source["data_input_type"] == DATA_INPUT_TYPE_DATA_QUERY) {
            _data_source_input_field__data_query_hdr();
            _data_source_input_field__data_query_field_name("dif_data_query_field_name", $data_input_type_fields["data_query_id"]["value"], isset($data_input_type_fields["data_query_field_name"]["value"]) ? $data_input_type_fields["data_query_field_name"]["value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
            _data_source_input_field__data_query_field_value("dif_data_query_field_value", isset($data_input_type_fields["data_query_field_name"]["value"]) ? $data_input_type_fields["data_query_field_value"]["value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
            $num_output_fields += 2;
        }
        $num_output_fields += draw_nontemplated_fields_data_source($data_source["data_template_id"], $data_source, "ds||field|", "<strong>" . _("Data Source Fields") . "</strong>", true, true);
        $num_output_fields += draw_nontemplated_fields_data_source_item($data_source["data_template_id"], db_fetch_assoc("select * from data_source_item where data_source_id = " . $data_source["id"] . " order by data_source_name"), "dsi||field|||id|", "<strong>" . _("Data Source Item Fields") . "</strong>", true, true);
        html_end_box();
        if ($num_output_fields == 0) {
            ob_end_clean();
        } else {
            ob_end_flush();
        }
    }
    if (empty($data_source["data_template_id"]) && (isset($_GET["id"]) && is_numeric($_GET["id"]) || isset($_GET["host_id"]) && isset($_GET["data_template_id"]))) {
        /* determine current value for 'data_input_type' */
        if (isset($_GET["data_input_type"])) {
            $_data_input_type = $_GET["data_input_type"];
        } else {
            if (isset($data_source["data_input_type"])) {
                $_data_input_type = $data_source["data_input_type"];
            } else {
                $_data_input_type = DATA_INPUT_TYPE_SCRIPT;
            }
        }
        /* ==================== Box: Data Input ==================== */
        html_start_box("<strong>" . _("Data Input") . "</strong>");
        _data_source_input_field__data_input_type("data_input_type", false, $_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_sources.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_template_id=" . (isset($_GET["data_template_id"]) ? $_GET["data_template_id"] : (isset($data_source) ? $data_source["data_template_id"] : 0)) . "&host_id=" . (isset($_GET["host_id"]) ? $_GET["host_id"] : (isset($data_source) ? $data_source["host_id"] : 0)) . "&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"], false, isset($data_input_type_fields[$field["data_name"]]) ? $data_input_type_fields[$field["data_name"]]["value"] : "", "", "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    }
                }
            }
        } else {
            if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
                /* 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_sources.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_template_id=" . (isset($_GET["data_template_id"]) ? $_GET["data_template_id"] : (isset($data_source) ? $data_source["data_template_id"] : 0)) . "&host_id=" . (isset($_GET["host_id"]) ? $_GET["host_id"] : (isset($data_source) ? $data_source["host_id"] : 0)) . "&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", false, isset($data_input_type_fields["snmp_port"]) ? $data_input_type_fields["snmp_port"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmp_timeout("dif_snmp_timeout", false, isset($data_input_type_fields["snmp_timeout"]) ? $data_input_type_fields["snmp_timeout"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmp_version("dif_snmp_version", false, isset($data_input_type_fields["snmp_version"]) ? $data_input_type_fields["snmp_version"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_hdr_snmpv12();
                    _data_source_input_field__device_snmp_community("dif_snmp_community", false, isset($data_input_type_fields["snmp_community"]) ? $data_input_type_fields["snmp_community"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_hdr_snmpv3();
                    _data_source_input_field__device_snmpv3_auth_username("dif_snmpv3_auth_username", false, isset($data_input_type_fields["snmpv3_auth_username"]) ? $data_input_type_fields["snmpv3_auth_username"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmpv3_auth_password("dif_snmpv3_auth_password", false, isset($data_input_type_fields["snmpv3_auth_password"]) ? $data_input_type_fields["snmpv3_auth_password"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmpv3_auth_protocol("dif_snmpv3_auth_protocol", false, isset($data_input_type_fields["snmpv3_auth_protocol"]) ? $data_input_type_fields["snmpv3_auth_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmpv3_priv_passphrase("dif_snmpv3_priv_passphrase", false, isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? $data_input_type_fields["snmpv3_priv_passphrase"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                    _data_source_input_field__device_snmpv3_priv_protocol("dif_snmpv3_priv_protocol", false, isset($data_input_type_fields["snmpv3_priv_protocol"]) ? $data_input_type_fields["snmpv3_priv_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                }
            }
        }
        html_end_box();
        /* ==================== Box: Data Source ==================== */
        if (empty($_GET["id"])) {
            $rra_items = array();
        } else {
            $rra_items = api_data_source_rra_item_list($data_source["id"]);
        }
        html_start_box("<strong>" . _("Data Source") . "</strong>");
        _data_source_field__name("ds|name", false, empty($_GET["id"]) ? 0 : $_GET["id"]);
        _data_source_field__rra("preset_rra_id", false, isset($data_source["preset_rra_id"]) ? $data_source["preset_rra_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _data_source_field__polling_interval("ds|polling_interval", false, isset($data_source["polling_interval"]) ? $data_source["polling_interval"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _data_source_field__active("ds|active", false, isset($data_source["active"]) ? $data_source["active"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        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_sources.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_source_items) || sizeof($data_source_items) == 0 || $_GET["action"] == "item_add") {
            if (isset($data_source_items)) {
                $next_index = sizeof($data_source_items);
            } else {
                $next_index = 0;
            }
            $data_source_items[$next_index] = array();
        }
        if (sizeof($data_source_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_source_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 Source Item") . ")";
                    ?>
						</td>
						<td class='textSubHeaderDark' align='right'>
							<?php 
                    if (isset($item["id"]) && sizeof($data_source_items) > 1) {
                        print "[<a href='data_sources.php?action=item_remove&id=" . $item["id"] . "&data_source_id=" . $item["data_source_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}", false, isset($item["data_source_name"]) ? $item["data_source_name"] : "", $_field_id);
                _data_source_item_field__rrd_minimum("dsi|rrd_minimum|{$_field_id}", false, isset($item["rrd_minimum"]) ? $item["rrd_minimum"] : "", $_field_id, "dsi|t_rrd_minimum|{$_field_id}");
                _data_source_item_field__rrd_maximum("dsi|rrd_maximum|{$_field_id}", false, isset($item["rrd_maximum"]) ? $item["rrd_maximum"] : "", $_field_id, "dsi|t_rrd_maximum|{$_field_id}");
                _data_source_item_field__data_source_type("dsi|data_source_type|{$_field_id}", false, isset($item["data_source_type"]) ? $item["data_source_type"] : "", $_field_id, "dsi|t_data_source_type|{$_field_id}");
                _data_source_item_field__rrd_heartbeat("dsi|rrd_heartbeat|{$_field_id}", false, isset($item["rrd_heartbeat"]) ? $item["rrd_heartbeat"] : "", $_field_id, "dsi|t_rrd_heartbeat|{$_field_id}");
            }
        }
        html_end_box();
    }
    /* display the debug mode box if the user wants it */
    if (isset($_SESSION["ds_debug_mode"]) && isset($_GET["id"])) {
        html_start_box("<strong>Data Source Debug</strong>", "98%", $colors["header_background"], "3", "center", "");
        print "<tr><td bgcolor=#'" . $colors["messagebar_background"] . "' <pre>" . rrdtool_function_create($_GET["id"], true, array()) . "</pre></td></tr>";
        html_end_box();
    }
    if (isset($_GET["id"]) || isset($_GET["host_id"]) && isset($_GET["data_template_id"])) {
        form_hidden_box("action_post", "data_source_edit");
    } else {
        form_hidden_box("action_post", "data_source_add");
    }
    form_hidden_box("data_source_id", get_get_var_number("id"));
    form_save_button("data_sources.php");
}