本文整理汇总了PHP中substitute_snmp_query_data函数的典型用法代码示例。如果您正苦于以下问题:PHP substitute_snmp_query_data函数的具体用法?PHP substitute_snmp_query_data怎么用?PHP substitute_snmp_query_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了substitute_snmp_query_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rrdtool_function_graph
//.........这里部分代码省略.........
/* note the current item_id for easy access */
$graph_item_id = $graph_item["graph_templates_item_id"];
/* the following fields will be searched for graph variables */
$variable_fields = array(
"text_format" => array(
"process_no_legend" => false
),
"value" => array(
"process_no_legend" => true
)
);
/* loop through each field that we want to substitute values for:
currently: text format and value */
while (list($field_name, $field_array) = each($variable_fields)) {
/* certain fields do not require values when the legend is not to be shown */
if (($field_array["process_no_legend"] == false) && (isset($graph_data_array["graph_nolegend"]))) {
continue;
}
$graph_variables[$field_name][$graph_item_id] = $graph_item[$field_name];
/* date/time substitution */
if (strstr($graph_variables[$field_name][$graph_item_id], "|date_time|")) {
$graph_variables[$field_name][$graph_item_id] = str_replace("|date_time|", date('D d M H:i:s T Y', strtotime(db_fetch_cell("select value from settings where name='date'"))), $graph_variables[$field_name][$graph_item_id]);
}
/* data query variables */
if (preg_match("/\|query_[a-zA-Z0-9_]+\|/", $graph_variables[$field_name][$graph_item_id])) {
/* default to the graph data query information from the graph */
if (empty($graph_item["local_data_id"])) {
$graph_variables[$field_name][$graph_item_id] = substitute_snmp_query_data($graph_variables[$field_name][$graph_item_id], $graph["host_id"], $graph["snmp_query_id"], $graph["snmp_index"]);
/* use the data query information from the data source if possible */
}else{
$data_local = db_fetch_row("select snmp_index,snmp_query_id,host_id from data_local where id='" . $graph_item["local_data_id"] . "'");
$graph_variables[$field_name][$graph_item_id] = substitute_snmp_query_data($graph_variables[$field_name][$graph_item_id], $data_local["host_id"], $data_local["snmp_query_id"], $data_local["snmp_index"]);
}
}
/* 95th percentile */
if (preg_match_all("/\|95:(bits|bytes):(\d):(current|total|max)(:(\d))?\|/", $graph_variables[$field_name][$graph_item_id], $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$graph_variables[$field_name][$graph_item_id] = str_replace($match[0], variable_ninety_fifth_percentile($match, $graph_item, $graph_items, $graph_start, $graph_end), $graph_variables[$field_name][$graph_item_id]);
}
}
/* bandwidth summation */
if (preg_match_all("/\|sum:(\d|auto):(current|total|atomic):(\d):(\d+|auto)\|/", $graph_variables[$field_name][$graph_item_id], $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$graph_variables[$field_name][$graph_item_id] = str_replace($match[0], variable_bandwidth_summation($match, $graph_item, $graph_items, $graph_start, $graph_end, $rra["steps"], $ds_step), $graph_variables[$field_name][$graph_item_id]);
}
}
}
/* if we are not displaying a legend there is no point in us even processing the auto padding,
text format stuff. */
if (!isset($graph_data_array["graph_nolegend"])) {
/* set hard return variable if selected (\n) */
if ($graph_item["hard_return"] == "on") {
$hardreturn[$graph_item_id] = "\\n";
}else{
$hardreturn[$graph_item_id] = "";
}
示例2: api_reapply_suggested_graph_title
function api_reapply_suggested_graph_title($local_graph_id) {
global $config;
/* get graphs template id */
$graph_template_id = db_fetch_cell("select graph_template_id from graph_templates_graph where local_graph_id=" . $local_graph_id);
/* if a non-template graph, simply return */
if ($graph_template_id == 0) {
return;
}
/* get the host associated with this graph */
$graph_local = db_fetch_row("select host_id, graph_template_id, snmp_query_id, snmp_index from graph_local where id=" . $local_graph_id);
$snmp_query_graph_id = db_fetch_cell("select id from snmp_query_graph where graph_template_id=" . $graph_local["graph_template_id"] .
" and snmp_query_id=" . $graph_local["snmp_query_id"]);
/* get the suggested values from the suggested values cache */
$suggested_values = db_fetch_assoc("select text,field_name from snmp_query_graph_sv where snmp_query_graph_id=" . $snmp_query_graph_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_graph[$graph_template_id]{$suggested_value["field_name"]})) {
$subs_string = substitute_snmp_query_data($suggested_value["text"], $graph_local["host_id"], $graph_local["snmp_query_id"], $graph_local["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")) {
db_execute("update graph_templates_graph set " . $suggested_value["field_name"] . "='" . $suggested_value["text"] . "' where local_graph_id=" . $local_graph_id);
/* once we find a working value, stop */
$suggested_values_graph[$graph_template_id]{$suggested_value["field_name"]} = true;
}
}
}
}
/* suggested values: graph */
if (isset($suggested_values_array[$graph_template_id]["graph_template"])) {
while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["graph_template"])) {
db_execute("update graph_templates_graph set $field_name='$field_value' where local_graph_id=" . $local_graph_id);
}
}
/* suggested values: graph item */
if (isset($suggested_values_array[$graph_template_id]["graph_template_item"])) {
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=" . $local_graph_id);
db_execute("update graph_templates_item set $field_name='$field_value' where id=$graph_item_id");
}
}
}
}
示例3: expand_title
function expand_title($host_id, $snmp_query_id, $snmp_index, $title)
{
if (strstr($title, '|') && !empty($host_id)) {
if ($snmp_query_id != '0' && $snmp_index != '') {
return substitute_snmp_query_data(null_out_substitutions(substitute_host_data($title, '|', '|', $host_id)), $host_id, $snmp_query_id, $snmp_index, read_config_option('max_data_query_field_length'));
} else {
return null_out_substitutions(substitute_host_data($title, '|', '|', $host_id));
}
} else {
return null_out_substitutions($title);
}
}
示例4: api_reapply_suggested_data_source_title
function api_reapply_suggested_data_source_title($local_data_id)
{
global $config;
$data_template_data_id = db_fetch_cell("select id from data_template_data where local_data_id={$local_data_id}");
if (empty($data_template_data_id)) {
return;
}
/* require query type data sources only (snmp_query_id > 0) */
$data_local = db_fetch_row("SELECT id, host_id, data_template_id, snmp_query_id, snmp_index FROM data_local WHERE snmp_query_id>0 AND id={$local_data_id}");
/* if this is not a data query graph, simply return */
if (!isset($data_local["host_id"])) {
return;
}
$snmp_query_graph_id = db_fetch_cell("SELECT " . "data_input_data.value from data_input_data " . "JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id) " . "JOIN data_template_data ON (data_template_data.id = data_input_data.data_template_data_id) " . "WHERE data_input_fields.type_code = 'output_type' " . "AND data_template_data.local_data_id=" . $data_local["id"]);
/* no snmp query graph id found */
if ($snmp_query_graph_id == 0) {
return;
}
$suggested_values = db_fetch_assoc("SELECT " . "text, " . "field_name " . "FROM snmp_query_graph_rrd_sv " . "WHERE snmp_query_graph_id=" . $snmp_query_graph_id . " " . "AND data_template_id=" . $data_local["data_template_id"] . " " . "AND field_name = 'name' " . "ORDER BY sequence");
$suggested_values_data = array();
if (sizeof($suggested_values) > 0) {
foreach ($suggested_values as $suggested_value) {
if (!isset($suggested_values_data[$suggested_value["field_name"]])) {
$subs_string = substitute_snmp_query_data($suggested_value["text"], $data_local["host_id"], $data_local["snmp_query_id"], $data_local["snmp_index"], read_config_option("max_data_query_field_length"));
/* if there are no '|query' characters, all of the substitutions were successful */
if (!substr_count($subs_string, "|query")) {
db_execute("UPDATE data_template_data SET " . $suggested_value["field_name"] . "='" . $suggested_value["text"] . "' WHERE local_data_id=" . $local_data_id);
/* once we find a working value for that very field, stop */
$suggested_values_data[$suggested_value["field_name"]] = true;
}
}
}
}
}
示例5: boost_rrdtool_function_create
function boost_rrdtool_function_create($local_data_id, $initial_time, $show_source)
{
global $config;
include $config["include_path"] . "/global_arrays.php";
$data_source_path = get_data_source_path($local_data_id, TRUE);
/* ok, if that passes lets check to make sure an rra does not already
exist, the last thing we want to do is overright data! */
if ($show_source != TRUE) {
if (file_exists($data_source_path) == TRUE) {
return -1;
}
}
/* the first thing we must do is make sure there is at least one
rra associated with this data source... *
UPDATE: As of version 0.6.6, we are splitting this up into two
SQL strings because of the multiple DS per RRD support. This is
not a big deal however since this function gets called once per
data source */
$rras = db_fetch_assoc("select\r\n\t\tdata_template_data.rrd_step,\r\n\t\trra.x_files_factor,\r\n\t\trra.steps,\r\n\t\trra.rows,\r\n\t\trra_cf.consolidation_function_id,\r\n\t\t(rra.rows*rra.steps) as rra_order\r\n\t\tfrom data_template_data\r\n\t\tleft join data_template_data_rra on (data_template_data.id=data_template_data_rra.data_template_data_id)\r\n\t\tleft join rra on (data_template_data_rra.rra_id=rra.id)\r\n\t\tleft join rra_cf on (rra.id=rra_cf.rra_id)\r\n\t\twhere data_template_data.local_data_id={$local_data_id}\r\n\t\tand (rra.steps is not null or rra.rows is not null)\r\n\t\torder by rra_cf.consolidation_function_id,rra_order");
/* if we find that this DS has no RRA associated; get out. This would
* indicate that a data sources has been deleted
*/
if (sizeof($rras) <= 0) {
return FALSE;
}
/* back off the initial time to allow updates */
$initial_time -= 300;
/* create the "--step" line */
$create_ds = RRD_NL . "--start " . $initial_time . " --step " . $rras[0]["rrd_step"] . " " . RRD_NL;
/* query the data sources to be used in this .rrd file */
$data_sources = db_fetch_assoc("SELECT\r\n\t\tdata_template_rrd.id,\r\n\t\tdata_template_rrd.rrd_heartbeat,\r\n\t\tdata_template_rrd.rrd_minimum,\r\n\t\tdata_template_rrd.rrd_maximum,\r\n\t\tdata_template_rrd.data_source_type_id\r\n\t\tFROM data_template_rrd\r\n\t\tWHERE data_template_rrd.local_data_id={$local_data_id}\r\n\t\tORDER BY local_data_template_rrd_id");
/* ONLY make a new DS entry if:
- There is multiple data sources and this item is not the main one.
- There is only one data source (then use it) */
if (sizeof($data_sources) > 0) {
foreach ($data_sources as $data_source) {
/* use the cacti ds name by default or the user defined one, if entered */
$data_source_name = get_data_source_item_name($data_source["id"]);
if (empty($data_source["rrd_maximum"])) {
/* in case no maximum is given, use "Undef" value */
$data_source["rrd_maximum"] = "U";
} elseif (strpos($data_source["rrd_maximum"], "|query_") !== false) {
if ($data_source["rrd_maximum"] == "|query_ifSpeed|" || $data_source["rrd_maximum"] == "|query_ifHighSpeed|") {
$highSpeed = db_fetch_cell("SELECT field_value\r\n\t\t\t\t\tFROM host_snmp_cache\r\n\t\t\t\t\tWHERE host_id=" . $data_local["host_id"] . "\r\n\t\t\t\t\tAND snmp_query_id=" . $data_local["snmp_query_id"] . "\r\n\t\t\t\t\tAND snmp_index='" . $data_local["snmp_index"] . "'\r\n\t\t\t\t\tAND field_name='ifHighSpeed'");
if (!empty($highSpeed)) {
$data_source["rrd_maximum"] = $highSpeed * 1000000;
} else {
$data_source["rrd_maximum"] = substitute_snmp_query_data("|query_ifSpeed|", $data_local["host_id"], $data_local["snmp_query_id"], $data_local["snmp_index"]);
}
} else {
$data_source["rrd_maximum"] = substitute_snmp_query_data($data_source["rrd_maximum"], $data_local["host_id"], $data_local["snmp_query_id"], $data_local["snmp_index"]);
}
} elseif ($data_source["rrd_maximum"] != "U" && (int) $data_source["rrd_maximum"] <= (int) $data_source["rrd_minimum"]) {
/* max > min required, but take care of an "Undef" value */
$data_source["rrd_maximum"] = (int) $data_source["rrd_minimum"] + 1;
}
/* min==max==0 won't work with rrdtool */
if ($data_source["rrd_minimum"] == 0 && $data_source["rrd_maximum"] == 0) {
$data_source["rrd_maximum"] = "U";
}
$create_ds .= "DS:{$data_source_name}:" . $data_source_types[$data_source["data_source_type_id"]] . ":" . $data_source["rrd_heartbeat"] . ":" . $data_source["rrd_minimum"] . ":" . $data_source["rrd_maximum"] . RRD_NL;
}
}
$create_rra = "";
/* loop through each available RRA for this DS */
foreach ($rras as $rra) {
$create_rra .= "RRA:" . $consolidation_functions[$rra["consolidation_function_id"]] . ":" . $rra["x_files_factor"] . ":" . $rra["steps"] . ":" . $rra["rows"] . RRD_NL;
}
/* check for structured path configuration, if in place verify directory
exists and if not create it.
*/
if (read_config_option("extended_paths") == "on") {
if (!is_dir(dirname($data_source_path))) {
if (mkdir(dirname($data_source_path), 0775)) {
if ($config["cacti_server_os"] != "win32") {
$owner_id = fileowner($config["rra_path"]);
$group_id = filegroup($config["rra_path"]);
if (chown(dirname($data_source_path), $owner_id) && chgrp(dirname($data_source_path), $group_id)) {
/* permissions set ok */
} else {
cacti_log("ERROR: Unable to set directory permissions for '" . dirname($data_source_path) . "'", FALSE);
}
}
} else {
cacti_log("ERROR: Unable to create directory '" . dirname($data_source_path) . "'", FALSE);
}
}
}
if ($show_source == TRUE) {
return read_config_option("path_rrdtool") . " create" . RRD_NL . "{$data_source_path}{$create_ds}{$create_rra}";
} else {
return boost_rrdtool_execute("create {$data_source_path} {$create_ds}{$create_rra}", FALSE, RRDTOOL_OUTPUT_STDOUT);
}
}
示例6: boost_rrdtool_function_create
function boost_rrdtool_function_create($local_data_id, $initial_time, $show_source)
{
global $config;
include $config['include_path'] . '/global_arrays.php';
$data_source_path = get_data_source_path($local_data_id, true);
/* ok, if that passes lets check to make sure an rra does not already
exist, the last thing we want to do is overright data! */
if ($show_source != true) {
if (file_exists($data_source_path) == true) {
return -1;
}
}
/* the first thing we must do is make sure there is at least one
rra associated with this data source... *
UPDATE: As of version 0.6.6, we are splitting this up into two
SQL strings because of the multiple DS per RRD support. This is
not a big deal however since this function gets called once per
data source */
$rras = db_fetch_assoc_prepared('SELECT
data_template_data.rrd_step,
rra.x_files_factor,
rra.steps,
rra.rows,
rra_cf.consolidation_function_id,
(rra.rows * rra.steps) AS rra_order
FROM data_template_data
LEFT JOIN data_template_data_rra ON (data_template_data.id = data_template_data_rra.data_template_data_id)
LEFT JOIN rra ON (data_template_data_rra.rra_id = rra.id)
LEFT JOIN rra_cf ON (rra.id = rra_cf.rra_id)
WHERE data_template_data.local_data_id = ?
AND (rra.steps is not null OR rra.rows is not null)
ORDER BY rra_cf.consolidation_function_id, rra_order', array($local_data_id));
/* if we find that this DS has no RRA associated; get out. This would
* indicate that a data sources has been deleted
*/
if (sizeof($rras) <= 0) {
return false;
}
/* back off the initial time to allow updates */
$initial_time -= 300;
/* create the "--step" line */
$create_ds = RRD_NL . '--start ' . $initial_time . ' --step ' . $rras[0]['rrd_step'] . ' ' . RRD_NL;
/* query the data sources to be used in this .rrd file */
$data_sources = db_fetch_assoc_prepared('SELECT
data_template_rrd.id,
data_template_rrd.rrd_heartbeat,
data_template_rrd.rrd_minimum,
data_template_rrd.rrd_maximum,
data_template_rrd.data_source_type_id
FROM data_template_rrd
WHERE data_template_rrd.local_data_id = ?
ORDER BY local_data_template_rrd_id', array($local_data_id));
/* ONLY make a new DS entry if:
- There is multiple data sources and this item is not the main one.
- There is only one data source (then use it) */
if (sizeof($data_sources) > 0) {
foreach ($data_sources as $data_source) {
/* use the cacti ds name by default or the user defined one, if entered */
$data_source_name = get_data_source_item_name($data_source['id']);
if (empty($data_source['rrd_maximum'])) {
/* in case no maximum is given, use "Undef" value */
$data_source['rrd_maximum'] = 'U';
} elseif (strpos($data_source['rrd_maximum'], '|query_') !== false) {
$data_local = db_fetch_row_prepared('SELECT * FROM data_local WHERE id = ?', array($local_data_id));
if ($data_source['rrd_maximum'] == '|query_ifSpeed|' || $data_source['rrd_maximum'] == '|query_ifHighSpeed|') {
$highSpeed = db_fetch_cell_prepared("SELECT field_value\n\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\tWHERE host_id = ?\n\t\t\t\t\tAND snmp_query_id = ?\n\t\t\t\t\tAND snmp_index = ?\n\t\t\t\t\tAND field_name = 'ifHighSpeed'", array($data_local['host_id'], $data_local['snmp_query_id'], $data_local['snmp_index']));
if (!empty($highSpeed)) {
$data_source['rrd_maximum'] = $highSpeed * 1000000;
} else {
$data_source['rrd_maximum'] = substitute_snmp_query_data('|query_ifSpeed|', $data_local['host_id'], $data_local['snmp_query_id'], $data_local['snmp_index']);
}
} else {
$data_source['rrd_maximum'] = substitute_snmp_query_data($data_source['rrd_maximum'], $data_local['host_id'], $data_local['snmp_query_id'], $data_local['snmp_index']);
}
} elseif ($data_source['rrd_maximum'] != 'U' && (int) $data_source['rrd_maximum'] <= (int) $data_source['rrd_minimum']) {
/* max > min required, but take care of an "Undef" value */
$data_source['rrd_maximum'] = (int) $data_source['rrd_minimum'] + 1;
}
/* min==max==0 won't work with rrdtool */
if ($data_source['rrd_minimum'] == 0 && $data_source['rrd_maximum'] == 0) {
$data_source['rrd_maximum'] = 'U';
}
$create_ds .= "DS:{$data_source_name}:" . $data_source_types[$data_source['data_source_type_id']] . ':' . $data_source['rrd_heartbeat'] . ':' . $data_source['rrd_minimum'] . ':' . $data_source['rrd_maximum'] . RRD_NL;
}
}
$create_rra = '';
/* loop through each available RRA for this DS */
foreach ($rras as $rra) {
$create_rra .= 'RRA:' . $consolidation_functions[$rra['consolidation_function_id']] . ':' . $rra['x_files_factor'] . ':' . $rra['steps'] . ':' . $rra['rows'] . RRD_NL;
}
/* check for structured path configuration, if in place verify directory
exists and if not create it.
*/
if (read_config_option('extended_paths') == 'on') {
if (!is_dir(dirname($data_source_path))) {
if (mkdir(dirname($data_source_path), 0775)) {
if ($config['cacti_server_os'] != 'win32') {
$owner_id = fileowner($config['rra_path']);
$group_id = filegroup($config['rra_path']);
if (chown(dirname($data_source_path), $owner_id) && chgrp(dirname($data_source_path), $group_id)) {
//.........这里部分代码省略.........
示例7: create_complete_graph_from_template
function create_complete_graph_from_template($graph_template_id, $host_id, $snmp_query_array, &$suggested_values_array)
{
global $config;
include_once $config["library_path"] . "/data_query.php";
/* create the graph */
$save["id"] = 0;
$save["graph_template_id"] = $graph_template_id;
$save["host_id"] = $host_id;
$cache_array["local_graph_id"] = sql_save($save, "graph_local");
change_graph_template($cache_array["local_graph_id"], $graph_template_id, true);
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_sv WHERE snmp_query_graph_id=" . $snmp_query_array["snmp_query_graph_id"] . " ORDER BY sequence");
$suggested_values_graph = 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_graph[$graph_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")) {
db_execute("UPDATE graph_templates_graph SET " . $suggested_value["field_name"] . "='" . $suggested_value["text"] . "' WHERE local_graph_id=" . $cache_array["local_graph_id"]);
/* once we find a working value, stop */
$suggested_values_graph[$graph_template_id][$suggested_value["field_name"]] = true;
}
}
}
}
}
/* suggested values: graph */
if (isset($suggested_values_array[$graph_template_id]["graph_template"])) {
while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["graph_template"])) {
db_execute("UPDATE graph_templates_graph SET {$field_name}='{$field_value}' WHERE local_graph_id=" . $cache_array["local_graph_id"]);
}
}
/* suggested values: graph item */
if (isset($suggested_values_array[$graph_template_id]["graph_template_item"])) {
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");
$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"]])) {
$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"] . "='" . $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"] . "='" . $suggested_value["text"] . "' 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'\n\t\t\t\t\tOR data_input_fields.type_code='index_value'\n\t\t\t\t\tOR 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\n\t\t\t\tFROM host_snmp_cache\n\t\t\t\tWHERE host_id='{$host_id}'\n\t\t\t\tAND snmp_query_id='" . $snmp_query_array["snmp_query_id"] . "'\n\t\t\t\tAND field_name='" . $snmp_query_array["snmp_index_on"] . "'\n\t\t\t\tAND snmp_index='" . $snmp_query_array["snmp_index"] . "'");
/* save the value to index on (ie. ifindex, ifip, etc) */
db_execute("REPLACE INTO data_input_data\n\t\t\t\t(data_input_field_id, data_template_data_id, t_value, value)\n\t\t\t\tVALUES (" . $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\n\t\t\t\t(data_input_field_id,data_template_data_id,t_value,value)\n\t\t\t\tVALUES (" . $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\n\t\t\t\t(data_input_field_id,data_template_data_id,t_value,value)\n\t\t\t\tVALUES (" . $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\n\t\t\t\t\tSET {$field_name}='{$field_value}'\n\t\t\t\t\tWHERE local_data_id=" . $cache_array["local_data_id"][$data_template["id"]]);
}
}
/* suggested values: data source item */
//.........这里部分代码省略.........
示例8: rrd_substitute_host_query_data
function rrd_substitute_host_query_data($txt_graph_item, $graph, $graph_item) {
/* replace host variables in graph elements */
$txt_graph_item = substitute_host_data($txt_graph_item, '|','|', $graph["host_id"]);
/* replace query variables in graph elements */
if (preg_match("/\|query_[a-zA-Z0-9_]+\|/", $txt_graph_item)) {
/* default to the graph data query information from the graph */
if (empty($graph_item["local_data_id"])) {
return substitute_snmp_query_data($txt_graph_item, $graph["host_id"], $graph["snmp_query_id"], $graph["snmp_index"]);
/* use the data query information from the data source if possible */
}else{
$data_local = db_fetch_row("select snmp_index,snmp_query_id,host_id from data_local where id='" . $graph_item["local_data_id"] . "'");
return substitute_snmp_query_data($txt_graph_item, $data_local["host_id"], $data_local["snmp_query_id"], $data_local["snmp_index"]);
}
}else{
return $txt_graph_item;
}
}
示例9: api_reapply_suggested_data_source_title
function api_reapply_suggested_data_source_title($local_data_id)
{
global $config;
$data_template_data_id = db_fetch_cell("select id from data_template_data where local_data_id={$local_data_id}");
if (empty($data_template_data_id)) {
return;
}
$data_local = db_fetch_row("select host_id, data_template_id, snmp_query_id, snmp_index from data_local where id={$local_data_id}");
$suggested_values = db_fetch_assoc("select text,field_name from snmp_query_graph_rrd_sv where data_template_id=" . $data_local["data_template_id"] . " order by sequence");
if (sizeof($suggested_values) > 0) {
foreach ($suggested_values as $suggested_value) {
if (!isset($suggested_values_data[$data_template_data_id][$suggested_value["field_name"]])) {
$subs_string = substitute_snmp_query_data($suggested_value["text"], $data_local["host_id"], $data_local["snmp_query_id"], $data_local["snmp_index"], read_config_option("max_data_query_field_length"));
/* if there are no '|query' characters, all of the substitutions were successful */
if (!substr_count($subs_string, "|query") && $suggested_value["field_name"] == "name") {
db_execute("update data_template_data set " . $suggested_value["field_name"] . "='" . $suggested_value["text"] . "' where local_data_id=" . $local_data_id);
/* once we find a working value, stop */
$suggested_values_data[$data_template_data_id][$suggested_value["field_name"]] = true;
}
}
}
}
}
示例10: api_reapply_suggested_graph_title
function api_reapply_suggested_graph_title($local_graph_id)
{
global $config;
/* get graphs template id */
$graph_template_id = db_fetch_cell("select graph_template_id from graph_templates_graph where local_graph_id=" . $local_graph_id);
/* if a non-template graph, simply return */
if ($graph_template_id == 0) {
return;
}
/* get the host associated with this graph for data queries only
* there's no "reapply suggested title" for "simple" graph templates */
$graph_local = db_fetch_row("select host_id, graph_template_id, snmp_query_id, snmp_index from graph_local where snmp_query_id>0 AND id=" . $local_graph_id);
/* if this is not a data query graph, simply return */
if (!isset($graph_local["host_id"])) {
return;
}
/* get data source associated with the graph */
$data_local = db_fetch_cell("SELECT " . "data_template_data.local_data_id " . "FROM (data_template_rrd,data_template_data,graph_templates_item) " . "WHERE graph_templates_item.task_item_id=data_template_rrd.id " . "AND data_template_rrd.local_data_id=data_template_data.local_data_id " . "AND graph_templates_item.local_graph_id=" . $local_graph_id . " " . "GROUP BY data_template_data.local_data_id");
$snmp_query_graph_id = db_fetch_cell("SELECT " . "data_input_data.value from data_input_data " . "JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id) " . "JOIN data_template_data ON (data_template_data.id = data_input_data.data_template_data_id) " . "WHERE data_input_fields.type_code = 'output_type' " . "AND data_template_data.local_data_id=" . $data_local);
/* no snmp query graph id found */
if ($snmp_query_graph_id == 0) {
return;
}
/* get the suggested values from the suggested values cache */
$suggested_values = db_fetch_assoc("SELECT " . "text, " . "field_name " . "FROM snmp_query_graph_sv " . "WHERE snmp_query_graph_id=" . $snmp_query_graph_id . " " . "AND field_name = 'title' " . "ORDER BY sequence");
$found = false;
if (sizeof($suggested_values) > 0) {
foreach ($suggested_values as $suggested_value) {
/* once we find a match; don't try to find more */
if (!$found) {
$subs_string = substitute_snmp_query_data($suggested_value["text"], $graph_local["host_id"], $graph_local["snmp_query_id"], $graph_local["snmp_index"], read_config_option("max_data_query_field_length"));
/* if there are no '|' characters, all of the substitutions were successful */
if (!substr_count($subs_string, "|query")) {
db_execute("UPDATE graph_templates_graph SET " . $suggested_value["field_name"] . "='" . $suggested_value["text"] . "' WHERE local_graph_id=" . $local_graph_id);
/* once we find a working value, stop */
$found = true;
}
}
}
}
}
示例11: create_complete_graph_from_template
function create_complete_graph_from_template($graph_template_id, $host_id, $snmp_query_array, &$suggested_values_array)
{
global $config;
include_once $config["library_path"] . "/data_query.php";
/* create the graph */
$save["id"] = 0;
$save["graph_template_id"] = $graph_template_id;
$save["host_id"] = $host_id;
$cache_array["local_graph_id"] = sql_save($save, "graph_local");
change_graph_template($cache_array["local_graph_id"], $graph_template_id, true);
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_sv where snmp_query_graph_id=" . $snmp_query_array["snmp_query_graph_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_graph[$graph_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")) {
db_execute("update graph_templates_graph set " . $suggested_value["field_name"] . "='" . addslashes($suggested_value["text"]) . "' where local_graph_id=" . $cache_array["local_graph_id"]);
/* once we find a working value, stop */
$suggested_values_graph[$graph_template_id][$suggested_value["field_name"]] = true;
}
}
}
}
}
/* suggested values: graph */
if (isset($suggested_values_array[$graph_template_id]["graph_template"])) {
while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["graph_template"])) {
db_execute("update graph_templates_graph set {$field_name}='{$field_value}' where local_graph_id=" . $cache_array["local_graph_id"]);
}
}
/* suggested values: graph item */
if (isset($suggested_values_array[$graph_template_id]["graph_template_item"])) {
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"]);
//.........这里部分代码省略.........
示例12: get_formatted_data_query_index
function get_formatted_data_query_index($host_id, $data_query_id, $data_query_index)
{
/* FROM the xml; cached in 'host_snmp_query' */
$sort_cache = db_fetch_row("SELECT sort_field,title_format FROM host_snmp_query WHERE host_id='{$host_id}' AND snmp_query_id='{$data_query_id}'");
return substitute_snmp_query_data($sort_cache["title_format"], $host_id, $data_query_id, $data_query_index);
}
示例13: create_complete_graph_from_template
function create_complete_graph_from_template($graph_template_id, $host_id, $snmp_query_array, &$suggested_values_array) {
global $config;
include_once($config["library_path"] . "/data_query.php");
/* create the graph */
$save["id"] = 0;
$save["graph_template_id"] = $graph_template_id;
$save["host_id"] = $host_id;
$cache_array["local_graph_id"] = sql_save($save, "graph_local");
change_graph_template($cache_array["local_graph_id"], $graph_template_id, true);
/* This next block is simply designed to find the best suggested template
* name for our new graph. The suggested values are held in
* snmp_query_graph_sv and the graph is updated in graph_templates_graph.
*/
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_sv where snmp_query_graph_id=" . $snmp_query_array["snmp_query_graph_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_graph[$graph_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")) {
db_execute("update graph_templates_graph set " . $suggested_value["field_name"] . "='" . addslashes($suggested_value["text"]) . "' where local_graph_id=" . $cache_array["local_graph_id"]);
/* once we find a working value, stop */
$suggested_values_graph[$graph_template_id]{$suggested_value["field_name"]} = true;
}
}
}
}
}
/* suggested values: graph */
if (isset($suggested_values_array[$graph_template_id]["graph_template"])) {
while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["graph_template"])) {
db_execute("update graph_templates_graph set $field_name='$field_value' where local_graph_id=" . $cache_array["local_graph_id"]);
}
}
/* suggested values: graph item */
if (isset($suggested_values_array[$graph_template_id]["graph_template_item"])) {
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 */
/* FIXED: group by */
$data_templates = db_fetch_assoc("select
data_template.id,
data_template.name,
max(data_template_rrd.data_source_name) as data_source_name
from (data_template
cross join data_template_rrd
cross join 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_rrd.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,
data_template.name
order 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"]})) {
//.........这里部分代码省略.........
示例14: expand_title
function expand_title($host_id, $snmp_query_id, $snmp_index, $title) {
if ((strstr($title, "|")) && (!empty($host_id))) {
if (($snmp_query_id != "0") && ($snmp_index != "")) {
return substitute_snmp_query_data(null_out_substitutions(substitute_host_data($title, "|", "|", $host_id)), $host_id, $snmp_query_id, $snmp_index, read_config_option("max_data_query_field_length"));
}else{
return null_out_substitutions(substitute_host_data($title, "|", "|", $host_id));
}
}else{
return null_out_substitutions($title);
}
}
示例15: api_reapply_suggested_data_source_title
function api_reapply_suggested_data_source_title($local_data_id)
{
global $config;
$data_template_data_id = db_fetch_cell_prepared('SELECT id FROM data_template_data WHERE local_data_id = ?', array($local_data_id));
if (empty($data_template_data_id)) {
return;
}
/* require query type data sources only (snmp_query_id > 0) */
$data_local = db_fetch_row_prepared('SELECT id, host_id, data_template_id, snmp_query_id, snmp_index FROM data_local WHERE snmp_query_id > 0 AND id = ?', array($local_data_id));
/* if this is not a data query graph, simply return */
if (!isset($data_local['host_id'])) {
return;
}
$snmp_query_graph_id = db_fetch_cell_prepared("SELECT \n\t\tdata_input_data.value FROM data_input_data \n\t\tJOIN data_input_fields ON (data_input_data.data_input_field_id = data_input_fields.id) \n\t\tJOIN data_template_data ON (data_template_data.id = data_input_data.data_template_data_id) \n\t\tWHERE data_input_fields.type_code = 'output_type' \n\t\tAND data_template_data.local_data_id = ?", array($data_local['id']));
/* no snmp query graph id found */
if ($snmp_query_graph_id == 0) {
return;
}
$suggested_values = db_fetch_assoc_prepared("SELECT \n\t\ttext, \n\t\tfield_name \n\t\tFROM snmp_query_graph_rrd_sv \n\t\tWHERE snmp_query_graph_id = ?\n\t\tAND data_template_id = ?\n\t\tAND field_name = 'name'\n\t\tORDER BY sequence", array($snmp_query_graph_id, $data_local['data_template_id']));
$suggested_values_data = array();
if (sizeof($suggested_values) > 0) {
foreach ($suggested_values as $suggested_value) {
if (!isset($suggested_values_data[$suggested_value['field_name']])) {
$subs_string = substitute_snmp_query_data($suggested_value['text'], $data_local['host_id'], $data_local['snmp_query_id'], $data_local['snmp_index'], read_config_option('max_data_query_field_length'));
/* if there are no '|query' characters, all of the substitutions were successful */
if (!substr_count($subs_string, '|query')) {
db_execute_prepared('UPDATE data_template_data SET ' . $suggested_value['field_name'] . ' = ? WHERE local_data_id = ?', array($suggested_value['text'], $local_data_id));
/* once we find a working value for that very field, stop */
$suggested_values_data[$suggested_value['field_name']] = true;
}
}
}
}
}