本文整理汇总了PHP中update_graph_data_query_cache函数的典型用法代码示例。如果您正苦于以下问题:PHP update_graph_data_query_cache函数的具体用法?PHP update_graph_data_query_cache怎么用?PHP update_graph_data_query_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_graph_data_query_cache函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: update_data_query_cache
function update_data_query_cache($host_id, $data_query_id) {
$graphs = db_fetch_assoc("select id from graph_local where host_id = '$host_id' and snmp_query_id = '$data_query_id'");
if (sizeof($graphs) > 0) {
foreach ($graphs as $graph) {
update_graph_data_query_cache($graph["id"]);
}
}
$data_sources = db_fetch_assoc("select id from data_local where host_id = '$host_id' and snmp_query_id = '$data_query_id'");
if (sizeof($data_sources) > 0) {
foreach ($data_sources as $data_source) {
update_data_source_data_query_cache($data_source["id"]);
}
}
}
开发者ID:songchin,项目名称:Cacti,代码行数:17,代码来源:data_query.php
示例2: template
//.........这里部分代码省略.........
AND snmp_index='" . $snmp_query_array["snmp_index"] . "'");
/* save the value to index on (ie. ifindex, ifip, etc) */
db_execute("REPLACE INTO data_input_data
(data_input_field_id, data_template_data_id, t_value, value)
VALUES (" . $data_input_field["index_type"] . ", $data_template_data_id, '', '" . $snmp_query_array["snmp_index_on"] . "')");
/* save the actual value (ie. 3, 192.168.1.101, etc) */
db_execute("REPLACE INTO data_input_data
(data_input_field_id,data_template_data_id,t_value,value)
VALUES (" . $data_input_field["index_value"] . ",$data_template_data_id,'','" . addslashes($snmp_cache_value) . "')");
/* set the expected output type (ie. bytes, errors, packets) */
db_execute("REPLACE INTO data_input_data
(data_input_field_id,data_template_data_id,t_value,value)
VALUES (" . $data_input_field["output_type"] . ",$data_template_data_id,'','" . $snmp_query_array["snmp_query_graph_id"] . "')");
/* now that we have put data into the 'data_input_data' table, update the snmp cache for ds's */
update_data_source_data_query_cache($cache_array["local_data_id"]{$data_template["id"]});
}
/* suggested values: data source */
if (isset($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]})) {
reset($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]});
while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]})) {
db_execute("UPDATE data_template_data
SET $field_name='$field_value'
WHERE local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
}
}
/* suggested values: data source item */
if (isset($suggested_values_array[$graph_template_id]["data_template_item"])) {
reset($suggested_values_array[$graph_template_id]["data_template_item"]);
while (list($data_template_item_id, $field_array) = each($suggested_values_array[$graph_template_id]["data_template_item"])) {
while (list($field_name, $field_value) = each($field_array)) {
$data_source_item_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id=$data_template_item_id and local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
db_execute("UPDATE data_template_rrd
SET $field_name='$field_value'
WHERE id=$data_source_item_id");
}
}
}
/* suggested values: custom data */
if (isset($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]})) {
reset($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]});
while (list($data_input_field_id, $field_value) = each($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]})) {
db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values ($data_input_field_id,$data_template_data_id,'','$field_value')");
}
}
update_data_source_title_cache($cache_array["local_data_id"]{$data_template["id"]});
}
}
/* connect the dots: graph -> data source(s) */
$template_item_list = db_fetch_assoc("select
graph_templates_item.id,
data_template_rrd.id as data_template_rrd_id,
data_template_rrd.data_template_id
from (graph_templates_item,data_template_rrd)
where graph_templates_item.task_item_id=data_template_rrd.id
and graph_templates_item.graph_template_id=$graph_template_id
and local_graph_id=0
and task_item_id>0");
/* loop through each item affected and update column data */
if (sizeof($template_item_list) > 0) {
foreach ($template_item_list as $template_item) {
$local_data_id = $cache_array["local_data_id"]{$template_item["data_template_id"]};
$graph_template_item_id = db_fetch_cell("select id from graph_templates_item where local_graph_template_item_id=" . $template_item["id"] . " and local_graph_id=" . $cache_array["local_graph_id"]);
$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id=" . $template_item["data_template_rrd_id"] . " and local_data_id=$local_data_id");
if (!empty($data_template_rrd_id)) {
db_execute("update graph_templates_item set task_item_id='$data_template_rrd_id' where id=$graph_template_item_id");
}
}
}
/* this will not work until the ds->graph dots are connected */
if (is_array($snmp_query_array)) {
update_graph_data_query_cache($cache_array["local_graph_id"]);
}
# now that we have the id of the new host, we may plugin postprocessing code
$save["id"] = $cache_array["local_graph_id"];
$save["graph_template_id"] = $graph_template_id; // attention: unset!
if (is_array($snmp_query_array)) {
$save["snmp_query_id"] = $snmp_query_array["snmp_query_id"];
$save["snmp_index"] = $snmp_query_array["snmp_index"];
} else {
$save["snmp_query_id"] = 0;
$save["snmp_index"] = 0;
}
api_plugin_hook_function('create_complete_graph_from_template', $save);
return $cache_array;
}
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:template.php
示例3: form_save
function form_save() {
if ((isset($_POST["save_component_graph_new"])) && (!empty($_POST["graph_template_id"]))) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post("graph_template_id"));
/* ==================================================== */
$save["id"] = $_POST["local_graph_id"];
$save["graph_template_id"] = $_POST["graph_template_id"];
$save["host_id"] = $_POST["host_id"];
$local_graph_id = sql_save($save, "graph_local");
change_graph_template($local_graph_id, $_POST["graph_template_id"], true);
/* update the title cache */
update_graph_title_cache($local_graph_id);
}
if (isset($_POST["save_component_graph"])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post("graph_template_id"));
input_validate_input_number(get_request_var_post("_graph_template_id"));
/* ==================================================== */
$save1["id"] = $_POST["local_graph_id"];
$save1["host_id"] = $_POST["host_id"];
$save1["graph_template_id"] = $_POST["graph_template_id"];
$save2["id"] = $_POST["graph_template_graph_id"];
$save2["local_graph_template_graph_id"] = $_POST["local_graph_template_graph_id"];
$save2["graph_template_id"] = $_POST["graph_template_id"];
$save2["image_format_id"] = form_input_validate($_POST["image_format_id"], "image_format_id", "", true, 3);
$save2["title"] = form_input_validate($_POST["title"], "title", "", false, 3);
$save2["height"] = form_input_validate($_POST["height"], "height", "^[0-9]+$", false, 3);
$save2["width"] = form_input_validate($_POST["width"], "width", "^[0-9]+$", false, 3);
$save2["upper_limit"] = form_input_validate($_POST["upper_limit"], "upper_limit", "^(-?([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)([eE][+\-]?[0-9]+)?)|U$", false, 3);
$save2["lower_limit"] = form_input_validate($_POST["lower_limit"], "lower_limit", "^(-?([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)([eE][+\-]?[0-9]+)?)|U$", false, 3);
$save2["vertical_label"] = form_input_validate($_POST["vertical_label"], "vertical_label", "", true, 3);
$save2["slope_mode"] = form_input_validate((isset($_POST["slope_mode"]) ? $_POST["slope_mode"] : ""), "slope_mode", "", true, 3);
$save2["auto_scale"] = form_input_validate((isset($_POST["auto_scale"]) ? $_POST["auto_scale"] : ""), "auto_scale", "", true, 3);
$save2["auto_scale_opts"] = form_input_validate($_POST["auto_scale_opts"], "auto_scale_opts", "", true, 3);
$save2["auto_scale_log"] = form_input_validate((isset($_POST["auto_scale_log"]) ? $_POST["auto_scale_log"] : ""), "auto_scale_log", "", true, 3);
$save2["scale_log_units"] = form_input_validate((isset($_POST["scale_log_units"]) ? $_POST["scale_log_units"] : ""), "scale_log_units", "", true, 3);
$save2["auto_scale_rigid"] = form_input_validate((isset($_POST["auto_scale_rigid"]) ? $_POST["auto_scale_rigid"] : ""), "auto_scale_rigid", "", true, 3);
$save2["auto_padding"] = form_input_validate((isset($_POST["auto_padding"]) ? $_POST["auto_padding"] : ""), "auto_padding", "", true, 3);
$save2["base_value"] = form_input_validate($_POST["base_value"], "base_value", "^[0-9]+$", false, 3);
$save2["export"] = form_input_validate((isset($_POST["export"]) ? $_POST["export"] : ""), "export", "", true, 3);
$save2["unit_value"] = form_input_validate($_POST["unit_value"], "unit_value", "", true, 3);
$save2["unit_exponent_value"] = form_input_validate($_POST["unit_exponent_value"], "unit_exponent_value", "^-?[0-9]+$", true, 3);
if (!is_error_message()) {
$local_graph_id = sql_save($save1, "graph_local");
}
if (!is_error_message()) {
$save2["local_graph_id"] = $local_graph_id;
$graph_templates_graph_id = sql_save($save2, "graph_templates_graph");
if ($graph_templates_graph_id) {
raise_message(1);
/* if template information chanegd, update all necessary template information */
if ($_POST["graph_template_id"] != $_POST["_graph_template_id"]) {
/* check to see if the number of graph items differs, if it does; we need user input */
if ((!empty($_POST["graph_template_id"])) && (!empty($_POST["local_graph_id"])) && (sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=$local_graph_id")) != sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=0 and graph_template_id=" . $_POST["graph_template_id"])))) {
/* set the template back, since the user may choose not to go through with the change
at this point */
db_execute("update graph_local set graph_template_id=" . $_POST["_graph_template_id"] . " where id=$local_graph_id");
db_execute("update graph_templates_graph set graph_template_id=" . $_POST["_graph_template_id"] . " where local_graph_id=$local_graph_id");
header("Location: graphs.php?action=graph_diff&id=$local_graph_id&graph_template_id=" . $_POST["graph_template_id"]);
exit;
}
}
}else{
raise_message(2);
}
/* update the title cache */
update_graph_title_cache($local_graph_id);
}
if ((!is_error_message()) && ($_POST["graph_template_id"] != $_POST["_graph_template_id"])) {
change_graph_template($local_graph_id, $_POST["graph_template_id"], true);
}elseif (!empty($_POST["graph_template_id"])) {
update_graph_data_query_cache($local_graph_id);
}
}
if (isset($_POST["save_component_input"])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post("local_graph_id"));
/* ==================================================== */
/* first; get the current graph template id */
$graph_template_id = db_fetch_cell("select graph_template_id from graph_local where id=" . $_POST["local_graph_id"]);
/* get all inputs that go along with this graph template */
$input_list = db_fetch_assoc("select id,column_name from graph_template_input where graph_template_id=$graph_template_id");
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:graphs.php
示例4: form_save
function form_save()
{
/* modify for multi user start */
if (!empty($_POST["host_id"])) {
if (!check_host($_POST["host_id"])) {
access_denied();
}
}
/* modify for multi user end */
if (isset($_POST["save_component_graph_new"]) && !empty($_POST["graph_template_id"])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post("graph_template_id"));
/* ==================================================== */
/* modify for multi user start */
if (!check_resource_count(RESOURCE_GRAPH)) {
access_denied();
}
/* modify for multi user end */
$save["id"] = $_POST["local_graph_id"];
$save["graph_template_id"] = $_POST["graph_template_id"];
$save["host_id"] = $_POST["host_id"];
$local_graph_id = sql_save($save, "graph_local");
change_graph_template($local_graph_id, $_POST["graph_template_id"], true);
/* update the title cache */
update_graph_title_cache($local_graph_id);
}
if (isset($_POST["save_component_graph"])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post("graph_template_id"));
input_validate_input_number(get_request_var_post("_graph_template_id"));
/* ==================================================== */
$save1["id"] = $_POST["local_graph_id"];
$save1["host_id"] = $_POST["host_id"];
$save1["graph_template_id"] = $_POST["graph_template_id"];
$save2["id"] = $_POST["graph_template_graph_id"];
$save2["local_graph_template_graph_id"] = $_POST["local_graph_template_graph_id"];
$save2["graph_template_id"] = $_POST["graph_template_id"];
$save2["image_format_id"] = form_input_validate($_POST["image_format_id"], "image_format_id", "", true, 3);
$save2["title"] = form_input_validate($_POST["title"], "title", "", false, 3);
$save2["height"] = form_input_validate($_POST["height"], "height", "^[0-9]+\$", false, 3);
$save2["width"] = form_input_validate($_POST["width"], "width", "^[0-9]+\$", false, 3);
$save2["upper_limit"] = form_input_validate($_POST["upper_limit"], "upper_limit", "^(-?([0-9]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U\$", strlen($_POST["upper_limit"]) === 0 ? true : false, 3);
$save2["lower_limit"] = form_input_validate($_POST["lower_limit"], "lower_limit", "^(-?([0-9]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U\$", strlen($_POST["lower_limit"]) === 0 ? true : false, 3);
$save2["vertical_label"] = form_input_validate($_POST["vertical_label"], "vertical_label", "", true, 3);
$save2["slope_mode"] = form_input_validate(isset($_POST["slope_mode"]) ? $_POST["slope_mode"] : "", "slope_mode", "", true, 3);
$save2["auto_scale"] = form_input_validate(isset($_POST["auto_scale"]) ? $_POST["auto_scale"] : "", "auto_scale", "", true, 3);
$save2["auto_scale_opts"] = form_input_validate($_POST["auto_scale_opts"], "auto_scale_opts", "", true, 3);
$save2["auto_scale_log"] = form_input_validate(isset($_POST["auto_scale_log"]) ? $_POST["auto_scale_log"] : "", "auto_scale_log", "", true, 3);
$save2["scale_log_units"] = form_input_validate(isset($_POST["scale_log_units"]) ? $_POST["scale_log_units"] : "", "scale_log_units", "", true, 3);
$save2["auto_scale_rigid"] = form_input_validate(isset($_POST["auto_scale_rigid"]) ? $_POST["auto_scale_rigid"] : "", "auto_scale_rigid", "", true, 3);
$save2["auto_padding"] = form_input_validate(isset($_POST["auto_padding"]) ? $_POST["auto_padding"] : "", "auto_padding", "", true, 3);
$save2["base_value"] = form_input_validate($_POST["base_value"], "base_value", "^[0-9]+\$", false, 3);
$save2["export"] = form_input_validate(isset($_POST["export"]) ? $_POST["export"] : "", "export", "", true, 3);
$save2["unit_value"] = form_input_validate($_POST["unit_value"], "unit_value", "", true, 3);
$save2["unit_exponent_value"] = form_input_validate($_POST["unit_exponent_value"], "unit_exponent_value", "^-?[0-9]+\$", true, 3);
if (!is_error_message()) {
$local_graph_id = sql_save($save1, "graph_local");
}
if (!is_error_message()) {
$save2["local_graph_id"] = $local_graph_id;
$graph_templates_graph_id = sql_save($save2, "graph_templates_graph");
if ($graph_templates_graph_id) {
raise_message(1);
/* if template information chanegd, update all necessary template information */
if ($_POST["graph_template_id"] != $_POST["_graph_template_id"]) {
/* check to see if the number of graph items differs, if it does; we need user input */
if (!empty($_POST["graph_template_id"]) && !empty($_POST["local_graph_id"]) && sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id={$local_graph_id}")) != sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=0 and graph_template_id=" . $_POST["graph_template_id"]))) {
/* set the template back, since the user may choose not to go through with the change
at this point */
db_execute("update graph_local set graph_template_id=" . $_POST["_graph_template_id"] . " where id={$local_graph_id}");
db_execute("update graph_templates_graph set graph_template_id=" . $_POST["_graph_template_id"] . " where local_graph_id={$local_graph_id}");
header("Location: graphs.php?action=graph_diff&id={$local_graph_id}&graph_template_id=" . $_POST["graph_template_id"]);
exit;
}
}
} else {
raise_message(2);
}
/* update the title cache */
update_graph_title_cache($local_graph_id);
}
if (!is_error_message() && $_POST["graph_template_id"] != $_POST["_graph_template_id"]) {
change_graph_template($local_graph_id, $_POST["graph_template_id"], true);
} elseif (!empty($_POST["graph_template_id"])) {
update_graph_data_query_cache($local_graph_id);
}
}
if (isset($_POST["save_component_input"])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post("local_graph_id"));
/* ==================================================== */
/* first; get the current graph template id */
$graph_template_id = db_fetch_cell("select graph_template_id from graph_local where id=" . $_POST["local_graph_id"]);
/* get all inputs that go along with this graph template */
$input_list = db_fetch_assoc("select id,column_name from graph_template_input where graph_template_id={$graph_template_id}");
if (sizeof($input_list) > 0) {
/* modify for multi user start */
$sql_join = "";
if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
$sql_join = "\r\n INNER JOIN graph_local ON graph_templates_item.local_graph_id = graph_local.id \r\n INNER JOIN host ON graph_local.host_id = host.id\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'";
//.........这里部分代码省略.........
开发者ID:resmon,项目名称:resmon-cacti,代码行数:101,代码来源:graphs.php
示例5: create_complete_graph_from_template
//.........这里部分代码省略.........
while (list($graph_template_item_id, $field_array) = each($suggested_values_array[$graph_template_id]["graph_template_item"])) {
while (list($field_name, $field_value) = each($field_array)) {
$graph_item_id = db_fetch_cell("select id from graph_templates_item where local_graph_template_item_id={$graph_template_item_id} and local_graph_id=" . $cache_array["local_graph_id"]);
db_execute("update graph_templates_item set {$field_name}='{$field_value}' where id={$graph_item_id}");
}
}
}
update_graph_title_cache($cache_array["local_graph_id"]);
/* create each data source */
$data_templates = db_fetch_assoc("select\n\t\tdata_template.id,\n\t\tdata_template.name,\n\t\tdata_template_rrd.data_source_name\n\t\tfrom (data_template, data_template_rrd, graph_templates_item)\n\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\tand data_template_rrd.data_template_id=data_template.id\n\t\tand data_template_rrd.local_data_id=0\n\t\tand graph_templates_item.local_graph_id=0\n\t\tand graph_templates_item.graph_template_id=" . $graph_template_id . "\n\t\tgroup by data_template.id\n\t\torder by data_template.name");
if (sizeof($data_templates) > 0) {
foreach ($data_templates as $data_template) {
unset($save);
$save["id"] = 0;
$save["data_template_id"] = $data_template["id"];
$save["host_id"] = $host_id;
$cache_array["local_data_id"][$data_template["id"]] = sql_save($save, "data_local");
change_data_template($cache_array["local_data_id"][$data_template["id"]], $data_template["id"]);
$data_template_data_id = db_fetch_cell("select id from data_template_data where local_data_id=" . $cache_array["local_data_id"][$data_template["id"]]);
if (is_array($snmp_query_array)) {
/* suggested values for snmp query code */
$suggested_values = db_fetch_assoc("select text,field_name from snmp_query_graph_rrd_sv where snmp_query_graph_id=" . $snmp_query_array["snmp_query_graph_id"] . " and data_template_id=" . $data_template["id"] . " order by sequence");
if (sizeof($suggested_values) > 0) {
foreach ($suggested_values as $suggested_value) {
/* once we find a match; don't try to find more */
if (!isset($suggested_values_ds[$data_template["id"]][$suggested_value["field_name"]])) {
$subs_string = substitute_snmp_query_data($suggested_value["text"], $host_id, $snmp_query_array["snmp_query_id"], $snmp_query_array["snmp_index"], read_config_option("max_data_query_field_length"));
/* if there are no '|' characters, all of the substitutions were successful */
if (!strstr($subs_string, "|query")) {
if (sizeof(db_fetch_row("show columns from data_template_data like '" . $suggested_value["field_name"] . "'"))) {
db_execute("update data_template_data set " . $suggested_value["field_name"] . "='" . addslashes($suggested_value["text"]) . "' where local_data_id=" . $cache_array["local_data_id"][$data_template["id"]]);
}
/* once we find a working value, stop */
$suggested_values_ds[$data_template["id"]][$suggested_value["field_name"]] = true;
if (sizeof(db_fetch_row("show columns from data_template_rrd like '" . $suggested_value["field_name"] . "'")) && !substr_count($subs_string, "|")) {
db_execute("update data_template_rrd set " . $suggested_value["field_name"] . "='" . $subs_string . "' where local_data_id=" . $cache_array["local_data_id"][$data_template["id"]]);
}
}
}
}
}
}
if (is_array($snmp_query_array)) {
$data_input_field = array_rekey(db_fetch_assoc("select\n\t\t\t\tdata_input_fields.id,\n\t\t\t\tdata_input_fields.type_code\n\t\t\t\tfrom (snmp_query,data_input,data_input_fields)\n\t\t\t\twhere snmp_query.data_input_id=data_input.id\n\t\t\t\tand data_input.id=data_input_fields.data_input_id\n\t\t\t\tand (data_input_fields.type_code='index_type' or data_input_fields.type_code='index_value' or data_input_fields.type_code='output_type')\n\t\t\t\tand snmp_query.id=" . $snmp_query_array["snmp_query_id"]), "type_code", "id");
$snmp_cache_value = db_fetch_cell("select field_value from host_snmp_cache where host_id='{$host_id}' and snmp_query_id='" . $snmp_query_array["snmp_query_id"] . "' and field_name='" . $snmp_query_array["snmp_index_on"] . "' and snmp_index='" . $snmp_query_array["snmp_index"] . "'");
/* save the value to index on (ie. ifindex, ifip, etc) */
db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values (" . $data_input_field["index_type"] . ",{$data_template_data_id},'','" . $snmp_query_array["snmp_index_on"] . "')");
/* save the actual value (ie. 3, 192.168.1.101, etc) */
db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values (" . $data_input_field["index_value"] . ",{$data_template_data_id},'','" . addslashes($snmp_cache_value) . "')");
/* set the expected output type (ie. bytes, errors, packets) */
db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values (" . $data_input_field["output_type"] . ",{$data_template_data_id},'','" . $snmp_query_array["snmp_query_graph_id"] . "')");
/* now that we have put data into the 'data_input_data' table, update the snmp cache for ds's */
update_data_source_data_query_cache($cache_array["local_data_id"][$data_template["id"]]);
}
/* suggested values: data source */
if (isset($suggested_values_array[$graph_template_id]["data_template"][$data_template["id"]])) {
reset($suggested_values_array[$graph_template_id]["data_template"][$data_template["id"]]);
while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["data_template"][$data_template["id"]])) {
db_execute("update data_template_data set {$field_name}='{$field_value}' where local_data_id=" . $cache_array["local_data_id"][$data_template["id"]]);
}
}
/* suggested values: data source item */
if (isset($suggested_values_array[$graph_template_id]["data_template_item"])) {
reset($suggested_values_array[$graph_template_id]["data_template_item"]);
while (list($data_template_item_id, $field_array) = each($suggested_values_array[$graph_template_id]["data_template_item"])) {
while (list($field_name, $field_value) = each($field_array)) {
$data_source_item_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id={$data_template_item_id} and local_data_id=" . $cache_array["local_data_id"][$data_template["id"]]);
db_execute("update data_template_rrd set {$field_name}='{$field_value}' where id={$data_source_item_id}");
}
}
}
/* suggested values: custom data */
if (isset($suggested_values_array[$graph_template_id]["custom_data"][$data_template["id"]])) {
reset($suggested_values_array[$graph_template_id]["custom_data"][$data_template["id"]]);
while (list($data_input_field_id, $field_value) = each($suggested_values_array[$graph_template_id]["custom_data"][$data_template["id"]])) {
db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values ({$data_input_field_id},{$data_template_data_id},'','{$field_value}')");
}
}
update_data_source_title_cache($cache_array["local_data_id"][$data_template["id"]]);
}
}
/* connect the dots: graph -> data source(s) */
$template_item_list = db_fetch_assoc("select\n\t\tgraph_templates_item.id,\n\t\tdata_template_rrd.id as data_template_rrd_id,\n\t\tdata_template_rrd.data_template_id\n\t\tfrom (graph_templates_item,data_template_rrd)\n\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\tand graph_templates_item.graph_template_id={$graph_template_id}\n\t\tand local_graph_id=0\n\t\tand task_item_id>0");
/* loop through each item affected and update column data */
if (sizeof($template_item_list) > 0) {
foreach ($template_item_list as $template_item) {
$local_data_id = $cache_array["local_data_id"][$template_item["data_template_id"]];
$graph_template_item_id = db_fetch_cell("select id from graph_templates_item where local_graph_template_item_id=" . $template_item["id"] . " and local_graph_id=" . $cache_array["local_graph_id"]);
$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id=" . $template_item["data_template_rrd_id"] . " and local_data_id={$local_data_id}");
if (!empty($data_template_rrd_id)) {
db_execute("update graph_templates_item set task_item_id='{$data_template_rrd_id}' where id={$graph_template_item_id}");
}
}
}
/* this will not work until the ds->graph dots are connected */
if (is_array($snmp_query_array)) {
update_graph_data_query_cache($cache_array["local_graph_id"]);
}
return $cache_array;
}
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:template.php
示例6: update_data_query_cache
function update_data_query_cache($host_id, $data_query_id)
{
$graphs = db_fetch_assoc("SELECT id FROM graph_local WHERE host_id = '{$host_id}' AND snmp_query_id = '{$data_query_id}'");
if (sizeof($graphs) > 0) {
foreach ($graphs as $graph) {
update_graph_data_query_cache($graph["id"]);
}
}
$data_sources = db_fetch_assoc("SELECT id FROM data_local WHERE host_id = '{$host_id}' AND snmp_query_id = '{$data_query_id}'");
if (sizeof($data_sources) > 0) {
foreach ($data_sources as $data_source) {
update_data_source_data_query_cache($data_source["id"]);
}
}
}
开发者ID:MrWnn,项目名称:cacti,代码行数:15,代码来源:data_query.php
示例7: create_complete_graph_from_template
//.........这里部分代码省略.........
if (sql_column_exists("data_template_data", $suggested_value["field_name"]) &&
(!substr_count($subs_string, "|"))) {
db_execute("update data_template_rrd set " . $suggested_value["field_name"] . "='" . $subs_string . "' where local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
}
}
}
}
}
}
if (is_array($snmp_query_array)) {
$data_input_field = array_rekey(db_fetch_assoc("select
data_input_fields.id,
data_input_fields.type_code
from (snmp_query
cross join data_input
cross join data_input_fields)
where snmp_query.data_input_id=data_input.id
and data_input.id=data_input_fields.data_input_id
and (data_input_fields.type_code='index_type' or data_input_fields.type_code='index_value' or data_input_fields.type_code='output_type')
and snmp_query.id=" . $snmp_query_array["snmp_query_id"]), "type_code", "id");
$snmp_cache_value = db_fetch_cell("select field_value from host_snmp_cache where host_id='$host_id' and snmp_query_id='" . $snmp_query_array["snmp_query_id"] . "' and field_name='" . $snmp_query_array["snmp_index_on"] . "' and snmp_index='" . $snmp_query_array["snmp_index"] . "'");
/* save the value to index on (ie. ifindex, ifip, etc) */
db_replace("data_input_data",array("data_input_field_id"=>$data_input_field["index_type"],"data_template_data_id"=>$data_template_data_id,"t_value"=>"","value"=>$snmp_query_array["snmp_index_on"]),array("data_input_field_id","data_template_data_id"),true);
/* save the actual value (ie. 3, 192.168.1.101, etc) */
db_replace("data_input_data",array("data_input_field_id"=>$data_input_field["index_value"],"data_template_data_id"=>$data_template_data_id,"t_value"=>"","value"=>addslashes($snmp_cache_value)),array("data_input_field_id","data_template_data_id"),true);
/* set the expected output type (ie. bytes, errors, packets) */
db_replace("data_input_data",array("data_input_field_id"=>$data_input_field["output_type"],"data_template_data_id"=>$data_template_data_id,"t_value"=>"","value"=>$snmp_query_array["snmp_query_graph_id"]),array("data_input_field_id","data_template_data_id"),true);
/* now that we have put data into the 'data_input_data' table, update the snmp cache for ds's */
update_data_source_data_query_cache($cache_array["local_data_id"]{$data_template["id"]});
}
/* suggested values: data source */
if (isset($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]})) {
reset($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]});
while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]})) {
db_execute("update data_template_data set $field_name='$field_value' where local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
}
}
/* suggested values: data source item */
if (isset($suggested_values_array[$graph_template_id]["data_template_item"])) {
reset($suggested_values_array[$graph_template_id]["data_template_item"]);
while (list($data_template_item_id, $field_array) = each($suggested_values_array[$graph_template_id]["data_template_item"])) {
while (list($field_name, $field_value) = each($field_array)) {
$data_source_item_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id=$data_template_item_id and local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
db_execute("update data_template_rrd set $field_name='$field_value' where id=$data_source_item_id");
}
}
}
/* suggested values: custom data */
if (isset($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]})) {
reset($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]});
while (list($data_input_field_id, $field_value) = each($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]})) {
db_replace("data_input_data",array("data_input_field_id"=>$data_input_field_id,"data_template_data_id"=>$data_template_data_id,"t_value"=>"","value"=>$field_value),array("data_input_field_id","data_template_data_id"),true);
}
}
update_data_source_title_cache($cache_array["local_data_id"]{$data_template["id"]});
}
}
/* connect the dots: graph -> data source(s) */
$template_item_list = db_fetch_assoc("select
graph_templates_item.id,
data_template_rrd.id as data_template_rrd_id,
data_template_rrd.data_template_id
from (graph_templates_item cross join data_template_rrd)
where graph_templates_item.task_item_id=data_template_rrd.id
and graph_templates_item.graph_template_id=$graph_template_id
and local_graph_id=0
and task_item_id>0");
/* loop through each item affected and update column data */
if (sizeof($template_item_list) > 0) {
foreach ($template_item_list as $template_item) {
$local_data_id = $cache_array["local_data_id"]{$template_item["data_template_id"]};
$graph_template_item_id = db_fetch_cell("select id from graph_templates_item where local_graph_template_item_id=" . $template_item["id"] . " and local_graph_id=" . $cache_array["local_graph_id"]);
$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id=" . $template_item["data_template_rrd_id"] . " and local_data_id=$local_data_id");
if (!empty($data_template_rrd_id)) {
db_execute("update graph_templates_item set task_item_id='$data_template_rrd_id' where id=$graph_template_item_id");
}
}
}
/* this will not work until the ds->graph dots are connected */
if (is_array($snmp_query_array)) {
update_graph_data_query_cache($cache_array["local_graph_id"]);
}
return $cache_array;
}
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:template.php
示例8: form_save
function form_save()
{
if (isset($_POST['save_component_graph_new']) && !empty($_POST['graph_template_id'])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post('graph_template_id'));
/* ==================================================== */
$save['id'] = $_POST['local_graph_id'];
$save['graph_template_id'] = $_POST['graph_template_id'];
$save['host_id'] = $_POST['host_id'];
$local_graph_id = sql_save($save, 'graph_local');
change_graph_template($local_graph_id, $_POST['graph_template_id'], true);
/* update the title cache */
update_graph_title_cache($local_graph_id);
}
if (isset($_POST['save_component_graph'])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post('graph_template_id'));
input_validate_input_number(get_request_var_post('_graph_template_id'));
/* ==================================================== */
$save1['id'] = $_POST['local_graph_id'];
$save1['host_id'] = $_POST['host_id'];
$save1['graph_template_id'] = $_POST['graph_template_id'];
$save2['id'] = $_POST['graph_template_graph_id'];
$save2['local_graph_template_graph_id'] = $_POST['local_graph_template_graph_id'];
$save2['graph_template_id'] = $_POST['graph_template_id'];
$save2['image_format_id'] = form_input_validate($_POST['image_format_id'], 'image_format_id', '', true, 3);
$save2['title'] = form_input_validate($_POST['title'], 'title', '', false, 3);
$save2['height'] = form_input_validate($_POST['height'], 'height', '^[0-9]+$', false, 3);
$save2['width'] = form_input_validate($_POST['width'], 'width', '^[0-9]+$', false, 3);
$save2['upper_limit'] = form_input_validate($_POST['upper_limit'], 'upper_limit', "^(-?([0-9]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U\$", strlen($_POST['upper_limit']) === 0 ? true : false, 3);
$save2['lower_limit'] = form_input_validate($_POST['lower_limit'], 'lower_limit', "^(-?([0-9]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U\$", strlen($_POST['lower_limit']) === 0 ? true : false, 3);
$save2['vertical_label'] = form_input_validate($_POST['vertical_label'], 'vertical_label', '', true, 3);
$save2['slope_mode'] = form_input_validate(isset($_POST['slope_mode']) ? $_POST['slope_mode'] : '', 'slope_mode', '', true, 3);
$save2['auto_scale'] = form_input_validate(isset($_POST['auto_scale']) ? $_POST['auto_scale'] : '', 'auto_scale', '', true, 3);
$save2['auto_scale_opts'] = form_input_validate($_POST['auto_scale_opts'], 'auto_scale_opts', '', true, 3);
$save2['auto_scale_log'] = form_input_validate(isset($_POST['auto_scale_log']) ? $_POST['auto_scale_log'] : '', 'auto_scale_log', '', true, 3);
$save2['scale_log_units'] = form_input_validate(isset($_POST['scale_log_units']) ? $_POST['scale_log_units'] : '', 'scale_log_units', '', true, 3);
$save2['auto_scale_rigid'] = form_input_validate(isset($_POST['auto_scale_rigid']) ? $_POST['auto_scale_rigid'] : '', 'auto_scale_rigid', '', true, 3);
$save2['auto_padding'] = form_input_validate(isset($_POST['auto_padding']) ? $_POST['auto_padding'] : '', 'auto_padding', '', true, 3);
$save2['base_value'] = form_input_validate($_POST['base_value'], 'base_value', '^[0-9]+$', false, 3);
$save2['export'] = form_input_validate(isset($_POST['export']) ? $_POST['export'] : '', 'export', '', true, 3);
$save2['unit_value'] = form_input_validate($_POST['unit_value'], 'unit_value', '', true, 3);
$save2['unit_exponent_value'] = form_input_validate($_POST['unit_exponent_value'], 'unit_exponent_value', '^-?[0-9]+$', true, 3);
if (!is_error_message()) {
$local_graph_id = sql_save($save1, 'graph_local');
}
if (!is_error_message()) {
$save2['local_graph_id'] = $local_graph_id;
$graph_templates_graph_id = sql_save($save2, 'graph_templates_graph');
if ($graph_templates_graph_id) {
raise_message(1);
/* if template information chanegd, update all necessary template information */
if ($_POST['graph_template_id'] != $_POST['_graph_template_id']) {
/* check to see if the number of graph items differs, if it does; we need user input */
if (!empty($_POST['graph_template_id']) && !empty($_POST['local_graph_id']) && sizeof(db_fetch_assoc_prepared('SELECT id FROM graph_templates_item WHERE local_graph_id = ?', array($local_graph_id))) != sizeof(db_fetch_assoc_prepared('SELECT id from graph_templates_item WHERE local_graph_id = 0 AND graph_template_id = ?', array($_POST['graph_template_id'])))) {
/* set the template back, since the user may choose not to go through with the change
at this point */
db_execute_prepared('UPDATE graph_local SET graph_template_id = ? WHERE id = ?', array($_POST['_graph_template_id'], $local_graph_id));
db_execute_prepared('UPDATE graph_templates_graph SET graph_template_id = ? WHERE local_graph_id = ?', array($_POST['_graph_template_id'], $local_graph_id));
header('Location: graphs.php?action=graph_diff&id=$local_graph_id&graph_template_id=' . $_POST['graph_template_id']);
exit;
}
}
} else {
raise_message(2);
}
/* update the title cache */
update_graph_title_cache($local_graph_id);
}
if (!is_error_message() && $_POST['graph_template_id'] != $_POST['_graph_template_id']) {
change_graph_template($local_graph_id, $_POST['graph_template_id'], true);
} elseif (!empty($_POST['graph_template_id'])) {
update_graph_data_query_cache($local_graph_id);
}
}
if (isset($_POST['save_component_input'])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post('local_graph_id'));
/* ==================================================== */
/* first; get the current graph template id */
$graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id FROM graph_local WHERE id = ?', array($_POST['local_graph_id']));
/* get all inputs that go along with this graph template, if templated */
if ($graph_template_id > 0) {
$input_list = db_fetch_assoc_prepared('SELECT id, column_name FROM graph_template_input WHERE graph_template_id = ?', array($graph_template_id));
if (sizeof($input_list) > 0) {
foreach ($input_list as $input) {
/* we need to find out which graph items will be affected by saving this particular item */
$item_list = db_fetch_assoc_prepared('SELECT
graph_templates_item.id
FROM (graph_template_input_defs, graph_templates_item)
WHERE graph_template_input_defs.graph_template_item_id = graph_templates_item.local_graph_template_item_id
AND graph_templates_item.local_graph_id = ?
AND graph_template_input_defs.graph_template_input_id = ?', array($_POST['local_graph_id'], $input['id']));
/* loop through each item affected and update column data */
if (sizeof($item_list) > 0) {
foreach ($item_list as $item) {
/* if we are changing templates, the POST vars we are searching for here will not exist.
this is because the db and form are out of sync here, but it is ok to just skip over saving
the inputs in this case. */
if (isset($_POST[$input['column_name'] . '_' . $input['id']])) {
//.........这里部分代码省略.........
开发者ID:MrWnn,项目名称:cacti,代码行数:101,代码来源:graphs.php
示例9: create_complete_graph_from_template
//.........这里部分代码省略.........
$save["id"] = 0;
$save["data_template_id"] = $data_template["id"];
$save["host_id"] = $host_id;
$cache_array["local_data_id"][$data_template["id"]] = sql_save($save, "data_local");
change_data_template($cache_array["local_data_id"][$data_template["id"]], $data_template["id"]);
$data_template_data_id = db_fetch_cell("SELECT id FROM data_template_data WHERE local_data_id=" . $cache_array["local_data_id"][$data_template["id"]]);
if (is_array($snmp_query_array)) {
/* suggested values for snmp query code */
$suggested_values = db_fetch_assoc("SELECT text,field_name FROM snmp_query_graph_rrd_sv WHERE snmp_query_graph_id=" . $snmp_query_array["snmp_query_graph_id"] . " AND data_template_id=" . $data_template["id"] . " ORDER BY sequence");
$suggested_values_ds = array();
if (sizeof($suggested_values) > 0) {
foreach ($suggested_values as $suggested_value) {
/* once we find a match; don't try to find more */
if (!isset($suggested_values_ds[$data_template["id"]][$suggested_value["field_name"]])) {
|
请发表评论