Create $num_graphs Graph" . (($num_graphs>1) ? "s" : "") . " from SNMP Query", "98%", $colors["header"], "3", "center", "");
print "| SNMP Query [" . $snmp_query["name"] . "] |
";
$fields = db_fetch_assoc("select
data_template.id as data_template_id,
data_template.name,
data_input_fields.name as field_name,
data_input_fields.id as data_input_field_id
from snmp_query_field,data_input_fields,data_template,snmp_query_graph,snmp_query_graph_rrd
where snmp_query_field.data_input_field_id=data_input_fields.id
and snmp_query_field.snmp_query_id=snmp_query_graph.snmp_query_id
and snmp_query_graph.id=snmp_query_graph_rrd.snmp_query_graph_id
and snmp_query_graph_rrd.data_template_id=data_template.id
and snmp_query_field.snmp_query_id=$snmp_query_id
and snmp_query_graph_rrd.snmp_query_graph_id=$snmp_query_graph_id
and snmp_query_field.action_id=1
group by snmp_query_graph_rrd.data_template_id");
if (sizeof($fields) > 0) {
foreach ($fields as $field) {
print "
" . $field["name"] . " -> " . $field["field_name"] . "
When these graphs are created, the following data input field will be filled with data from
the SNMP host.
| ";
$data = implode("",file(str_replace("", $paths["cacti"], $snmp_query["xml_path"])));
$snmp_queries = xml2array($data);
$xml_outputs = array();
/* list each of the input fields for this snmp query */
while (list($field_name, $field_array) = each($snmp_queries["fields"][0])) {
$field_array = $field_array[0];
if ($field_array["direction"] == "input") {
$xml_outputs[$field_name] = $field_name . " (" . $field_array["name"] . ")";
}
}
form_dropdown("sg_" . $snmp_query_id . "_" . $field["data_template_id"] . "_" . $field["data_input_field_id"],$xml_outputs,"","","","","");
print "
\n";
}
}
}
$data_templates = db_fetch_assoc("select
data_template.name as data_template_name,
data_template_rrd.data_source_name,
data_template_data.*
from data_template, data_template_rrd, data_template_data, graph_templates_item
where graph_templates_item.task_item_id=data_template_rrd.id
and data_template_rrd.data_template_id=data_template.id
and data_template_data.data_template_id=data_template.id
and data_template_rrd.local_data_id=0
and data_template_data.local_data_id=0
and graph_templates_item.local_graph_id=0
and graph_templates_item.graph_template_id=" . $graph_template_id . "
group by data_template.id
order by data_template.name");
$graph_template = db_fetch_row("select
graph_templates.name as graph_template_name,
graph_templates_graph.*
from graph_templates, graph_templates_graph
where graph_templates.id=graph_templates_graph.graph_template_id
and graph_templates.id=" . $graph_template_id . "
and graph_templates_graph.local_graph_id=0");
$graph_template_name = db_fetch_cell("select name from graph_templates where id=" . $graph_template_id);
$graph_inputs = db_fetch_assoc("select
*
from graph_template_input
where graph_template_id=" . $graph_template_id . "
and column_name != 'task_item_id'
order by name");
reset($struct_graph);
$drew_items = false;
while (list($field_name, $field_array) = each($struct_graph)) {
if ($graph_template{"t_" . $field_name} == "on") {
if ($drew_items == false) {
print "| Graph [Template: " . $graph_template["graph_template_name"] . "] |
";
}
$row_counter = 1; /* so we have an all 'light' background */
/* SUGGESTED VALUES: we must treat suggested values for snmp queries different because
one entry here might might 20 graphs... so we can't automatically fill in the values.
if it is not an snmp query, automatically fill in the values right here. */
if ((!empty($snmp_query_id)) && (sizeof(db_fetch_assoc("select id from snmp_query_graph_sv where snmp_query_graph_id=$snmp_query_graph_id and field_name='$field_name'")) > 0)) {
print "";
print "| " . $struct_graph[$field_name]["title"] . " | ";
print "Using Suggested Values (see SNMP Query) | ";
print "
\n";
}elseif ((empty($snmp_query_id)) && (sizeof(db_fetch_assoc("select text from host_template_graph_sv where host_template_id=$host_template_id and graph_template_id=$graph_template_id and field_name='$field_name'")) > 0)) {
$subs_string = db_fetch_cell("select text from host_template_graph_sv where host_template_id=$host_template_id and graph_template_id=$graph_template_id and field_name='$field_name'");
$subs_string = subsitute_host_data($subs_string, "|", "|", $host_id);
draw_templated_row($field_array, "g_" . $snmp_query_id . "_" . $graph_template_id . "_0_" . $field_name, $subs_string);
}else{
draw_templated_row($field_array, "g_" . $snmp_query_id . "_" . $graph_template_id . "_0_" . $field_name, (isset($data_template[$field_name]) ? $data_template[$field_name] : ""));
}
$drew_items = true;
}
}
/* DRAW: Graphs Inputs */
if (sizeof($graph_inputs) > 0) {
foreach ($graph_inputs as $graph_input) {
if ($drew_items == false) {
print "| Graph Items [Template: " . $graph_template_name . "] |
";
}
$row_counter = 1; /* so we have an all 'light' background */
$current_value = db_fetch_cell("select
graph_templates_item." . $graph_input["column_name"] . "
from graph_templates_item,graph_template_input_defs
where graph_template_input_defs.graph_template_item_id=graph_templates_item.local_graph_template_item_id
and graph_template_input_defs.graph_template_input_id=" . $graph_input["id"] . "
and graph_templates_item.graph_template_id=" . $graph_template_id . "
limit 0,1");
print "";
print "
" . $graph_input["name"] . "";
if (!empty($graph_input["description"])) { print " " . $graph_input["description"]; }
print " | \n";
draw_nontemplated_item($struct_graph_item{$graph_input["column_name"]}, "gi_" . $snmp_query_id . "_" . $graph_template_id . "_" . $graph_input["id"] . "_" . $graph_input["column_name"], $current_value);
print "
\n";
$drew_items = true;
}
}
/* DRAW: Data Sources */
if (sizeof($data_templates) > 0) {
foreach ($data_templates as $data_template) {
reset($struct_data_source);
$drew_items = false;
while (list($field_name, $field_array) = each($struct_data_source)) {
if (isset($data_template{"t_" . $field_name})) {
if ($data_template{"t_" . $field_name} == "on") {
if ($drew_items == false) {
print "| Data Source [Template: " . $data_template["data_template_name"] . "] |
";
}
$row_counter = 1; /* so we have an all 'light' background */
/* SUGGESTED VALUES: we must treat suggested values for snmp queries different because
one entry here might might 20 graphs... so we can't automatically fill in the values.
if it is not an snmp query, automatically fill in the values right here. */
if ((!empty($snmp_query_id)) && (sizeof(db_fetch_assoc("select id from snmp_query_graph_rrd_sv where snmp_query_graph_id=$snmp_query_graph_id and data_template_id=" . $data_template["data_template_id"] . " and field_name='$field_name'")) > 0)) {
print "";
print "| " . $struct_data_source[$field_name]["title"] . " | ";
print "Using Suggested Values (see SNMP Query) | ";
print "
\n";
}elseif ((empty($snmp_query_id)) && (sizeof(db_fetch_assoc("select text from host_template_data_sv where host_template_id=$host_template_id and data_template_id=" . $data_template["data_template_id"] . " and graph_template_id=$graph_template_id and field_name='$field_name'")) > 0)) {
$subs_string = db_fetch_cell("select text from host_template_data_sv where host_template_id=$host_template_id and data_template_id=" . $data_template["data_template_id"] . " and graph_template_id=$graph_template_id and field_name='$field_name'");
$subs_string = subsitute_host_data($subs_string, "|", "|", $host_id);
draw_templated_row($field_array, "d_" . $snmp_query_id . "_" . $graph_template_id . "_" . $data_template["data_template_id"] . "_0_" . $field_name, $subs_string);
}else{
draw_templated_row($field_array, "d_" . $snmp_query_id . "_" . $graph_template_id . "_" . $data_template["data_template_id"] . "_0_" . $field_name, $data_template[$field_name]);
}
$drew_items = true;
}
}
}
/* DRAW: Data Source Items */
$data_template_items = db_fetch_assoc("select
data_template_rrd.*
from data_template_rrd
where data_template_rrd.data_template_id=" . $data_template["data_template_id"] . "
and local_data_id=0");
if (sizeof($data_template_items) > 0) {
foreach ($data_template_items as $data_template_item) {
reset($struct_data_source_item);
$drew_items = false;
while (list($field_name, $field_array) = each($struct_data_source_item)) {
if ($data_template_item{"t_" . $field_name} == "on") {
$row_counter = 1; /* so we have an all 'light' background */
/* SUGGESTED VALUES: we must treat suggested values for snmp queries different because
one entry here might might 20 graphs... so we can't automatically fill in the values.
if it is not an snmp query, automatically fill in the values right here. */
if ((!empty($snmp_query_id)) && (sizeof(db_fetch_assoc("select id from snmp_query_graph_rrd_sv where snmp_query_graph_id=$snmp_query_graph_id and data_template_id=" . $data_template["data_template_id"] . " and field_name='$field_name'")) > 0)) {
print "";
print "| " . $struct_data_source_item[$field_name]["title"] . " | ";
print "Using Suggested Values (see SNMP Query) | ";
print "
\n";
}elseif ((empty($snmp_query_id)) && (sizeof(db_fetch_assoc("select text from host_template_data_sv where host_template_id=$host_template_id and data_template_id=" . $data_template["data_template_id"] . " and graph_template_id=$graph_template_id and field_name='$field_name'")) > 0)) {
$subs_string = db_fetch_cell("select text from host_template_data_sv where host_template_id=$host_template_id and data_template_id=" . $data_template["data_template_id"] . " and graph_template_id=$graph_template_id and field_name='$field_name'");
$subs_string = subsitute_host_data($subs_string, "|", "|", $host_id);
draw_templated_row($field_array, "di_" . $snmp_query_id . "_" . $graph_template_id . "_" . $data_template["data_template_id"] . "_" . $data_template_item["id"] . "_" . $field_name, $subs_string);
}else{
draw_templated_row($field_array, "di_" . $snmp_query_id . "_" . $graph_template_id . "_" . $data_template["data_template_id"] . "_" . $data_template_item["id"] . "_" . $field_name, $data_template_item[$field_name]);
}
$drew_items = true;
}
}
}
}
}
}
end_box();
}
}
form_hidden_id("host_template_id",$host_template_id);
form_hidden_id("host_id",$host_id);
form_hidden_box("save_component_new_graphs","1","");
print "\n";
form_save_button("host.php?action=edit&id=$host_id");
include_once ("include/bottom_footer.php");
}
function host_edit() {
include_once ("include/xml_functions.php");
global $colors, $snmp_versions, $paths;
display_output_messages();
if (!empty($_GET["id"])) {
$host = db_fetch_row("select * from host where id=" . $_GET["id"]);
$header_label = "[edit: " . $host["description"] . "]";
}else{
$header_label = "[new]";
}
start_box("Polling Hosts $header_label", "98%", $colors["header"], "3", "center", "");
?>