本文整理汇总了PHP中get_data_query_array函数的典型用法代码示例。如果您正苦于以下问题:PHP get_data_query_array函数的具体用法?PHP get_data_query_array怎么用?PHP get_data_query_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_data_query_array函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: data_query_item_edit
function data_query_item_edit() {
global $colors, $fields_data_query_item_edit;
if (!empty($_GET["id"])) {
$snmp_query_item = db_fetch_row("select * from snmp_query_graph where id=" . $_GET["id"]);
}
$snmp_query = db_fetch_row("select name,xml_path from snmp_query where id=" . $_GET["snmp_query_id"]);
$header_label = "[edit: " . $snmp_query["name"] . "]";
html_start_box("<strong>Associated Graph/Data Templates</strong> $header_label", "98%", $colors["header"], "3", "center", "");
draw_edit_form(array(
"config" => array(),
"fields" => inject_form_variables($fields_data_query_item_edit, (isset($snmp_query_item) ? $snmp_query_item : array()), $_GET)
));
html_end_box();
if (!empty($snmp_query_item["id"])) {
html_start_box("<strong>Associated Data Templates</strong>", "98%", $colors["header"], "3", "center", "");
$data_templates = db_fetch_assoc("select
data_template.id,
data_template.name
from data_template, data_template_rrd, 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=" . $snmp_query_item["graph_template_id"] . "
group by data_template.id
order by data_template.name");
$i = 0;
if (sizeof($data_templates) > 0) {
foreach ($data_templates as $data_template) {
print " <tr bgcolor='#" . $colors["header_panel"] . "'>
<td><span style='color: white; font-weight: bold;'>Data Template - " . $data_template["name"] . "</span></td>
</tr>";
$data_template_rrds = db_fetch_assoc("select
data_template_rrd.id,
data_template_rrd.data_source_name,
snmp_query_graph_rrd.snmp_field_name,
snmp_query_graph_rrd.snmp_query_graph_id
from data_template_rrd
left join snmp_query_graph_rrd on (snmp_query_graph_rrd.data_template_rrd_id=data_template_rrd.id and snmp_query_graph_rrd.snmp_query_graph_id=" . $_GET["id"] . " and snmp_query_graph_rrd.data_template_id=" . $data_template["id"] . ")
where data_template_rrd.data_template_id=" . $data_template["id"] . "
and data_template_rrd.local_data_id=0
order by data_template_rrd.data_source_name");
$i = 0;
if (sizeof($data_template_rrds) > 0) {
foreach ($data_template_rrds as $data_template_rrd) {
if (empty($data_template_rrd["snmp_query_graph_id"])) {
$old_value = "";
}else{
$old_value = "on";
}
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++;
?>
<td>
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="200">
<strong>Data Source:</strong>
</td>
<td width="200">
<?php print $data_template_rrd["data_source_name"];?>
</td>
<td width="1">
<?php
$snmp_queries = get_data_query_array($_GET["snmp_query_id"]);
$xml_outputs = array();
while (list($field_name, $field_array) = each($snmp_queries["fields"])) {
if ($field_array["direction"] == "output") {
$xml_outputs[$field_name] = $field_name . " (" . $field_array["name"] . ")";;
}
}
form_dropdown("dsdt_" . $data_template["id"] . "_" . $data_template_rrd["id"] . "_snmp_field_output",$xml_outputs,"","",$data_template_rrd["snmp_field_name"],"","");?>
</td>
<td align="right">
<?php form_checkbox("dsdt_" . $data_template["id"] . "_" . $data_template_rrd["id"] . "_check", $old_value, "", "",$_GET["id"]); print "<br>";?>
</td>
</tr>
</table>
</td>
</tr>
<?php
}
}
}
}
html_end_box();
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:data_queries.php
示例2: update_reindex_cache
function update_reindex_cache($host_id, $data_query_id)
{
global $config;
include_once $config["library_path"] . "/data_query.php";
include_once $config["library_path"] . "/snmp.php";
/* will be used to keep track of sql statements to execute later on */
$recache_stack = array();
$host = db_fetch_row("select hostname, snmp_community, snmp_version, snmp_username, snmp_password, snmp_auth_protocol, snmp_priv_passphrase, snmp_priv_protocol, snmp_context, snmp_port, snmp_timeout from host where id={$host_id}");
$data_query = db_fetch_row("select reindex_method, sort_field from host_snmp_query where host_id={$host_id} and snmp_query_id={$data_query_id}");
$data_query_type = db_fetch_cell("select data_input.type_id from (data_input,snmp_query) where data_input.id=snmp_query.data_input_id and snmp_query.id={$data_query_id}");
$data_query_xml = get_data_query_array($data_query_id);
switch ($data_query["reindex_method"]) {
case DATA_QUERY_AUTOINDEX_NONE:
break;
case DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME:
/* the uptime backwards method requires snmp, so make sure snmp is actually enabled
* on this device first */
if ($host["snmp_version"] > 0) {
if (isset($data_query_xml["oid_uptime"])) {
$oid_uptime = $data_query_xml["oid_uptime"];
} elseif (isset($data_query_xml["uptime_oid"])) {
$oid_uptime = $data_query_xml["uptime_oid"];
} else {
$oid_uptime = ".1.3.6.1.2.1.1.3.0";
}
$assert_value = cacti_snmp_get($host["hostname"], $host["snmp_community"], $oid_uptime, $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], SNMP_POLLER);
$recache_stack[] = "('{$host_id}', '{$data_query_id}'," . POLLER_ACTION_SNMP . ", '<', '{$assert_value}', '{$oid_uptime}', '1')";
}
break;
case DATA_QUERY_AUTOINDEX_INDEX_NUM_CHANGE:
/* this method requires that some command/oid can be used to determine the
* current number of indexes in the data query
* pay ATTENTION to quoting!
* the script parameters are usually enclosed in single tics: '
* so we have to enclose the whole list of parameters in double tics: "
* */
/* the assert_value counts the number of distinct indexes currently available in host_snmp_cache
* we do NOT make use of <oid_num_indexes> or the like!
* this works, even if no <oid_num_indexes> was given
*/
$assert_value = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id={$host_id} and snmp_query_id={$data_query_id} group by snmp_index"));
/* now, we have to build the (list of) commands that are later used on a recache event
* the result of those commands will be compared to the assert_value we have just computed
* on a comparison failure, a reindex event will be generated
*/
switch ($data_query_type) {
case DATA_INPUT_TYPE_SNMP_QUERY:
if (isset($data_query_xml["oid_num_indexes"])) {
/* we have a specific OID for counting indexes */
$recache_stack[] = "({$host_id}, {$data_query_id}," . POLLER_ACTION_SNMP . ", '=', '{$assert_value}', '" . $data_query_xml["oid_num_indexes"] . "', '1')";
} else {
/* count all indexes found */
$recache_stack[] = "({$host_id}, {$data_query_id}," . POLLER_ACTION_SNMP_COUNT . ", '=', '{$assert_value}', '" . $data_query_xml["oid_index"] . "', '1')";
}
break;
case DATA_INPUT_TYPE_SCRIPT_QUERY:
if (isset($data_query_xml["arg_num_indexes"])) {
/* we have a specific request for counting indexes */
/* escape path (windows!) and parameters for use with database sql; TODO: replace by db specific escape function like mysql_real_escape_string? */
$recache_stack[] = "({$host_id}, {$data_query_id}," . POLLER_ACTION_SCRIPT . ", '=', '{$assert_value}', '" . addslashes(get_script_query_path((isset($data_query_xml["arg_prepend"]) ? $data_query_xml["arg_prepend"] . " " : "") . $data_query_xml["arg_num_indexes"], $data_query_xml["script_path"], $host_id)) . "', '1')";
} else {
/* count all indexes found */
/* escape path (windows!) and parameters for use with database sql; TODO: replace by db specific escape function like mysql_real_escape_string? */
$recache_stack[] = "({$host_id}, {$data_query_id}," . POLLER_ACTION_SCRIPT_COUNT . ", '=', '{$assert_value}', '" . addslashes(get_script_query_path((isset($data_query_xml["arg_prepend"]) ? $data_query_xml["arg_prepend"] . " " : "") . $data_query_xml["arg_index"], $data_query_xml["script_path"], $host_id)) . "', '1')";
}
break;
case DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER:
if (isset($data_query_xml["arg_num_indexes"])) {
/* we have a specific request for counting indexes */
/* escape path (windows!) and parameters for use with database sql; TODO: replace by db specific escape function like mysql_real_escape_string? */
$recache_stack[] = "({$host_id}, {$data_query_id}," . POLLER_ACTION_SCRIPT_PHP . ", '=', '{$assert_value}', '" . addslashes(get_script_query_path($data_query_xml["script_function"] . " " . (isset($data_query_xml["arg_prepend"]) ? $data_query_xml["arg_prepend"] . " " : "") . $data_query_xml["arg_num_indexes"], $data_query_xml["script_path"], $host_id)) . "', '1')";
} else {
/* count all indexes found */
# TODO: push the correct assert value
/* escape path (windows!) and parameters for use with database sql; TODO: replace by db specific escape function like mysql_real_escape_string? */
#$recache_stack[] = "($host_id, $data_query_id," . POLLER_ACTION_SCRIPT_PHP_COUNT . ", '=', '$assert_value', '" . addslashes(get_script_query_path($data_query_xml["script_function"] . " " . (isset($data_query_xml["arg_prepend"]) ? $data_query_xml["arg_prepend"] . " ": "") . $data_query_xml["arg_index"], $data_query_xml["script_path"], $host_id)) . "', '1')";
# omit the assert value until we are able to run an 'index' command through script server
}
break;
}
break;
case DATA_QUERY_AUTOINDEX_FIELD_VERIFICATION:
$primary_indexes = db_fetch_assoc("select snmp_index,oid,field_value from host_snmp_cache where host_id={$host_id} and snmp_query_id={$data_query_id} and field_name='" . $data_query["sort_field"] . "'");
if (sizeof($primary_indexes) > 0) {
foreach ($primary_indexes as $index) {
$assert_value = $index["field_value"];
if ($data_query_type == DATA_INPUT_TYPE_SNMP_QUERY) {
$recache_stack[] = "({$host_id}, {$data_query_id}," . POLLER_ACTION_SNMP . ", '=', '{$assert_value}', '" . $data_query_xml["fields"][$data_query["sort_field"]]["oid"] . "." . $index["snmp_index"] . "', '1')";
} else {
if ($data_query_type == DATA_INPUT_TYPE_SCRIPT_QUERY) {
$recache_stack[] = "('{$host_id}', '{$data_query_id}'," . POLLER_ACTION_SCRIPT . ", '=', '{$assert_value}', '" . get_script_query_path((isset($data_query_xml["arg_prepend"]) ? $data_query_xml["arg_prepend"] . " " : "") . $data_query_xml["arg_get"] . " " . $data_query_xml["fields"][$data_query["sort_field"]]["query_name"] . " " . $index["snmp_index"], $data_query_xml["script_path"], $host_id) . "', '1')";
}
}
}
}
break;
}
if (sizeof($recache_stack)) {
poller_update_poller_reindex_from_buffer($host_id, $data_query_id, $recache_stack);
}
//.........这里部分代码省略.........
开发者ID:teddywen,项目名称:cacti,代码行数:101,代码来源:poller.php
示例3: update_poller_cache
//.........这里部分代码省略.........
data_input_data.value
FROM data_input_fields
LEFT JOIN data_input_data
ON (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id=" . $data_input["data_template_data_id"] . ")
WHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))
AND data_input_data.value != ''"), "type_code", "value");
$data_template_fields = array_rekey(db_fetch_assoc("SELECT
data_input_fields.type_code,
data_input_data.value
FROM data_input_fields
LEFT JOIN data_input_data
ON (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id=$data_template_id)
WHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))
AND data_template_data_id=$data_template_id
AND data_input_data.value != ''"), "type_code", "value");
if (sizeof($device_fields)) {
if (sizeof($data_template_fields)) {
foreach($data_template_fields as $key => $value) {
if (!isset($device_fields[$key])) {
$device_fields[$key] = $value;
}
}
}
} elseif (sizeof($data_template_fields)) {
$device_fields = $data_template_fields;
}
$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_id=$local_data_id");
$poller_items[] = api_poller_cache_item_add($data_source["device_id"], $device_fields, $local_data_id, $data_input["rrd_step"], 0, get_data_source_item_name($data_template_rrd_id), 1, (isset($device_fields["snmp_oid"]) ? $device_fields["snmp_oid"] : ""));
}else if ($data_input["type_id"] == DATA_INPUT_TYPE_SNMP_QUERY) { /* snmp query */
$snmp_queries = get_data_query_array($data_source["snmp_query_id"]);
/* get the device override fields */
$data_template_id = db_fetch_cell("SELECT data_template_id FROM data_template_data WHERE local_data_id=$local_data_id");
/* get device fields first */
$device_fields = array_rekey(db_fetch_assoc("SELECT
data_input_fields.type_code,
data_input_data.value
FROM data_input_fields
LEFT JOIN data_input_data
ON (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id=" . $data_input["data_template_data_id"] . ")
WHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))
AND data_input_data.value != ''"), "type_code", "value");
$data_template_fields = array_rekey(db_fetch_assoc("SELECT
data_input_fields.type_code,
data_input_data.value
FROM data_input_fields
LEFT JOIN data_input_data
ON (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id=$data_template_id)
WHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))
AND data_template_data_id=$data_template_id
AND data_input_data.value != ''"), "type_code", "value");
if (sizeof($device_fields)) {
if (sizeof($data_template_fields)) {
foreach($data_template_fields as $key => $value) {
if (!isset($device_fields[$key])) {
$device_fields[$key] = $value;
}
}
}
开发者ID:songchin,项目名称:Cacti,代码行数:67,代码来源:utility.php
示例4: graphs
//.........这里部分代码省略.........
foreach ($template_graphs as $template_graph) {
$script .= ($cg_ctr > 0 ? "," : "") . "'" . $template_graph["graph_template_id"] . "'";
$cg_ctr++;
}
$script .= ")\n";
}
/* create a row for each graph template associated with the host template */
if (sizeof($graph_templates) > 0) {
foreach ($graph_templates as $graph_template) {
$query_row = $graph_template["graph_template_id"];
print "<tr id='gt_line{$query_row}' class='" . ($i % 2 == 0 ? "odd" : "even") . "'>";
$i++;
print "\t\t<td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>Create:</strong> " . htmlspecialchars($graph_template["graph_template_name"]) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}' onClick='gt_update_selection_indicators();'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
}
}
$script .= "gt_update_deps(1);\n";
$available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name");
/* create a row at the bottom that lets the user create any graph they choose */
print "\t<tr class='" . ($i % 2 == 0 ? "odd" : "even") . "'>\n\t\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t\t<strong>Create:</strong> ";
form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea");
print "\t\t</td>\n\t\t\t</tr>";
html_end_box();
}
if ($_REQUEST["graph_type"] != -1) {
$snmp_queries = db_fetch_assoc("SELECT\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\tsnmp_query.xml_path\n\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\tAND host_snmp_query.host_id=" . $host["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . "\n\t\t\tORDER BY snmp_query.name");
if (sizeof($snmp_queries) > 0) {
foreach ($snmp_queries as $snmp_query) {
unset($total_rows);
if (!$changed) {
$page = $_REQUEST["page" . $snmp_query["id"]];
} else {
$page = 1;
}
$xml_array = get_data_query_array($snmp_query["id"]);
$num_input_fields = 0;
$num_visible_fields = 0;
if ($xml_array != false) {
/* loop through once so we can find out how many input fields there are */
reset($xml_array["fields"]);
while (list($field_name, $field_array) = each($xml_array["fields"])) {
if ($field_array["direction"] == "input") {
$num_input_fields++;
if (!isset($total_rows)) {
$total_rows = db_fetch_cell("SELECT count(*) FROM host_snmp_cache WHERE host_id=" . $host["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='{$field_name}'");
}
}
}
}
if (!isset($total_rows)) {
$total_rows = 0;
}
$snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name");
if (sizeof($snmp_query_graphs) > 0) {
foreach ($snmp_query_graphs as $snmp_query_graph) {
$created_graphs = db_fetch_assoc("SELECT DISTINCT\n\t\t\t\t\t\tdata_local.snmp_index\n\t\t\t\t\t\tFROM (data_local,data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id=data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code='output_type'\n\t\t\t\t\t\tAND data_input_data.value='" . $snmp_query_graph["id"] . "'\n\t\t\t\t\t\tAND data_local.host_id=" . $host["id"]);
$script .= "created_graphs[" . $snmp_query_graph["id"] . "] = new Array(";
$cg_ctr = 0;
if (sizeof($created_graphs) > 0) {
foreach ($created_graphs as $created_graph) {
$script .= ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'";
$cg_ctr++;
}
}
$script .= ")\n";
}
}
开发者ID:teddywen,项目名称:cacti,代码行数:67,代码来源:graphs_new.php
示例5: update_poller_cache
function update_poller_cache($local_data_id, $truncate_performed = false) {
global $config;
include_once($config["library_path"] . "/data_query.php");
include_once($config["library_path"] . "/api_poller.php");
$data_input = db_fetch_row("select
data_input.id,
data_input.type_id,
data_template_data.id as data_template_data_id,
data_template_data.data_template_id,
data_template_data.active,
data_template_data.rrd_step
from (data_template_data,data_input)
where data_template_data.data_input_id=data_input.id
and data_template_data.local_data_id=$local_data_id");
$data_source = db_fetch_row("select host_id,snmp_query_id,snmp_index from data_local where id=$local_data_id");
/* clear cache for this local_data_id */
if (!$truncate_performed) {
db_execute("delete from poller_item where local_data_id=$local_data_id");
}
/* we have to perform some additional sql queries if this is a "query" */
if (($data_input["type_id"] == DATA_INPUT_TYPE_SNMP_QUERY) ||
($data_input["type_id"] == DATA_INPUT_TYPE_SCRIPT_QUERY) ||
($data_input["type_id"] == DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER)){
$field = data_query_field_list($data_input["data_template_data_id"]);
if (($data_input["type_id"] != DATA_INPUT_TYPE_PHP_SCRIPT_SERVER) &&
(empty($field["output_type"]))) { return; }
if (strlen($field["output_type"])) {
$output_type_sql = "and snmp_query_graph_rrd.snmp_query_graph_id=" . $field["output_type"];
}else{
$output_type_sql = "";
}
$outputs = db_fetch_assoc("select
snmp_query_graph_rrd.snmp_field_name,
data_template_rrd.id as data_template_rrd_id
from (snmp_query_graph_rrd,data_template_rrd)
where snmp_query_graph_rrd.data_template_rrd_id=data_template_rrd.local_data_template_rrd_id
$output_type_sql
and snmp_query_graph_rrd.data_template_id=" . $data_input["data_template_id"] . "
and data_template_rrd.local_data_id=$local_data_id");
}
if ($data_input["active"] == "on") {
if (($data_input["type_id"] == DATA_INPUT_TYPE_SCRIPT) || ($data_input["type_id"] == DATA_INPUT_TYPE_PHP_SCRIPT_SERVER)) { /* script */
/* fall back to non-script server actions if the user is running a version of php older than 4.3 */
if (($data_input["type_id"] == DATA_INPUT_TYPE_PHP_SCRIPT_SERVER) && (function_exists("proc_open"))) {
$action = POLLER_ACTION_SCRIPT_PHP;
$script_path = get_full_script_path($local_data_id);
}else if (($data_input["type_id"] == DATA_INPUT_TYPE_PHP_SCRIPT_SERVER) && (!function_exists("proc_open"))) {
$action = POLLER_ACTION_SCRIPT;
$script_path = read_config_option("path_php_binary") . " -q " . get_full_script_path($local_data_id);
}else{
$action = POLLER_ACTION_SCRIPT;
$script_path = get_full_script_path($local_data_id);
}
$num_output_fields = sizeof(db_fetch_assoc("select id from data_input_fields where data_input_id=" . $data_input["id"] . " and input_output='out' and update_rra='on'"));
if ($num_output_fields == 1) {
$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_id=$local_data_id");
$data_source_item_name = get_data_source_item_name($data_template_rrd_id);
}else{
$data_source_item_name = "";
}
api_poller_cache_item_add($data_source["host_id"], array(), $local_data_id, $data_input["rrd_step"], $action, $data_source_item_name, 1, addslashes($script_path));
}else if ($data_input["type_id"] == DATA_INPUT_TYPE_SNMP) { /* snmp */
$host_fields = array_rekey(db_fetch_assoc("select
data_input_fields.type_code,
data_input_data.value
from data_input_fields left join data_input_data
on (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id=" . $data_input["data_template_data_id"] . ")
where (data_input_fields.type_code='snmp_oid'
or data_input_fields.type_code='hostname'
or data_input_fields.type_code='snmp_community'
or data_input_fields.type_code='snmp_username'
or data_input_fields.type_code='snmp_password'
or data_input_fields.type_code='snmp_auth_protocol'
or data_input_fields.type_code='snmp_priv_passphrase'
or data_input_fields.type_code='snmp_priv_protocol'
or data_input_fields.type_code='snmp_context'
or data_input_fields.type_code='snmp_version'
or data_input_fields.type_code='snmp_port'
or data_input_fields.type_code='snmp_timeout')
and data_input_data.value != ''"), "type_code", "value");
$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_id=$local_data_id");
api_poller_cache_item_add($data_source["host_id"], $host_fields, $local_data_id, $data_input["rrd_step"], 0, get_data_source_item_name($data_template_rrd_id), 1, (isset($host_fields["snmp_oid"]) ? $host_fields["snmp_oid"] : ""));
}else if ($data_input["type_id"] == DATA_INPUT_TYPE_SNMP_QUERY) { /* snmp query */
$snmp_queries = get_data_query_array($data_source["snmp_query_id"]);
if (sizeof($outputs) > 0) {
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:utility.php
示例6: displaySNMPValuesExtended
/** displaySNMPValuesExtended
*
* @param int $deviceId
* @param string $fields
* @param int $snmpQueryId
* @param bool $quietMode
*/
function displaySNMPValuesExtended($deviceId, $fields, $snmpQueryId, $quietMode = FALSE) {
$exit_code = 1; # assume an error until we've printed sth
$req_fields = array();
if (strlen($fields) > 0) {
# remove unwanted blanks
$query_FieldSpec = str_replace(" ", "", $fields);
# add tics for SQL query
$query_FieldSpec = str_replace(",", "','", $query_FieldSpec);
$query_FieldSpec = " AND field_name in ('" . $query_FieldSpec . "')";
} else {
$query_FieldSpec = "";
}
$xml_array = get_data_query_array($snmpQueryId);
if ($xml_array != false) {
/* loop through once so we can find out how many input fields there are */
reset($xml_array["fields"]);
while (list ($field_name, $field_array) = each($xml_array["fields"])) {
if ($field_array["direction"] == "input") {
# if spec was given ...
if (strlen($fields) > 0) {
# ... but current field doesn't match (make it case-insensitive, beware of the users!)
if (strpos(strtolower($fields), strtolower($field_name)) === false) {
# skip it
continue;
}
}
$req_fields[$field_name] = $xml_array["fields"][$field_name];
/* initialize column lengths */
$req_fields[$field_name]["length"] = $quietMode ? 0 : max(strlen($field_array["name"]), strlen($field_name));
if (!isset ($total_rows)) {
$total_rows = db_fetch_cell("SELECT COUNT(*) FROM device_snmp_cache WHERE device_id=" . $deviceId . " AND snmp_query_id=" . $snmpQueryId . " AND field_name='$field_name'");
}
}
}
if (!isset ($total_rows)) {
if (!sizeof($req_fields)) {
echo __("ERROR: Invalid --snmp-field-spec (found: %s) given", $fields) . "\n";
echo __("Try --list-snmp-fields") . "\n";
return (1);
} else {
echo __("ERROR: No cached SNMP values found for this SNMP Query") . "\n";
return (1);
}
}
$snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmpQueryId . " ORDER BY snmp_query_graph.name");
reset($req_fields);
$snmp_query_indexes = array ();
$sql_order = "";
/* get the unique field values from the database */
$field_names = db_fetch_assoc("SELECT DISTINCT " .
"field_name " .
"FROM " .
"device_snmp_cache " .
"WHERE " .
"device_id=" . $deviceId .
" AND " .
"snmp_query_id=" . $snmpQueryId .
$query_FieldSpec);
/* build magic query */
$sql_query = "SELECT device_id, snmp_query_id, snmp_index";
if (sizeof($field_names) > 0) {
foreach ($field_names as $column) {
$field_name = $column["field_name"];
$sql_query .= ", MAX(CASE WHEN field_name='$field_name' THEN field_value ELSE NULL END) AS '$field_name'";
}
} else {
echo __("ERROR: No SNMP field names found for this SNMP Query") . "\n";
return (1);
}
$sql_query .= " FROM device_snmp_cache " .
"WHERE device_id=" . $deviceId .
" AND snmp_query_id=" . $snmpQueryId .
$query_FieldSpec .
" GROUP BY device_id, snmp_query_id, snmp_index " .
$sql_order;
$snmp_query_indexes = db_fetch_assoc($sql_query);
if (!sizeof($snmp_query_indexes)) {
print __("This data query returned 0 rows, perhaps there was a problem executing this data query.") . "\n";
return (1);
}
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:api_automation_tools.php
示例7: graphs
//.........这里部分代码省略.........
$cg_ctr++;
}
print ")\n";
print "//-->\n</script>\n";
}
/* create a row for each graph template associated with the host template */
if (sizeof($graph_templates) > 0) {
foreach ($graph_templates as $graph_template) {
$query_row = $graph_template["graph_template_id"];
print "<tr id='gt_line{$query_row}' bgcolor='#" . ($i % 2 == 0 ? "ffffff" : $colors["light"]) . "'>";
$i++;
print "\t\t<td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'><span id='gt_text{$query_row}" . "_0'>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>Create:</strong> " . $graph_template["graph_template_name"] . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}' onClick='gt_update_selection_indicators();'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
}
}
print "<script type='text/javascript'>gt_update_deps(1);</script>\n";
$available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name");
/* create a row at the bottom that lets the user create any graph they choose */
print "\t<tr bgcolor='#" . ($i % 2 == 0 ? "ffffff" : $colors["light"]) . "'>\n\t\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t\t<strong>Create:</strong> ";
form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea");
print "\t\t</td>\n\t\t\t</tr>";
html_end_box();
}
if ($_REQUEST["graph_type"] != -1) {
$snmp_queries = db_fetch_assoc("SELECT\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\tsnmp_query.xml_path\n\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\tAND host_snmp_query.host_id=" . $host["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . "\n\t\t\tORDER BY snmp_query.name");
print "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n";
if (sizeof($snmp_queries) > 0) {
foreach ($snmp_queries as $snmp_query) {
unset($total_rows);
if (!$changed) {
$page = $_REQUEST["page" . $snmp_query["id"]];
} else {
$page = 1;
}
$xml_array = get_data_query_array($snmp_query["id"]);
$num_input_fields = 0;
$num_visible_fields = 0;
if ($xml_array != false) {
/* loop through once so we can find out how many input fields there are */
reset($xml_array["fields"]);
while (list($field_name, $field_array) = each($xml_array["fields"])) {
if ($field_array["direction"] == "input") {
$num_input_fields++;
if (!isset($total_rows)) {
$total_rows = db_fetch_cell("SELECT count(*) FROM host_snmp_cache WHERE host_id=" . $host["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='{$field_name}'");
}
}
}
}
if (!isset($total_rows)) {
$total_rows = 0;
}
$snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name");
if (sizeof($snmp_query_graphs) > 0) {
print "<script type='text/javascript'>\n<!--\n";
foreach ($snmp_query_graphs as $snmp_query_graph) {
$created_graphs = db_fetch_assoc("SELECT DISTINCT\n\t\t\t\t\t\tdata_local.snmp_index\n\t\t\t\t\t\tFROM (data_local,data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id=data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code='output_type'\n\t\t\t\t\t\tAND data_input_data.value='" . $snmp_query_graph["id"] . "'\n\t\t\t\t\t\tAND data_local.host_id=" . $host["id"]);
print "created_graphs[" . $snmp_query_graph["id"] . "] = new Array(";
$cg_ctr = 0;
if (sizeof($created_graphs) > 0) {
foreach ($created_graphs as $created_graph) {
print ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'";
$cg_ctr++;
}
}
print ")\n";
}
开发者ID:songchin,项目名称:Cacti,代码行数:67,代码来源:graphs_new.php
示例8: update_poller_cache
function update_poller_cache($local_data_id, $commit = false)
{
global $config;
include_once $config["library_path"] . "/data_query.php";
include_once $config["library_path"] . "/api_poller.php";
$poller_items = array();
$data_input = db_fetch_row("select\r\n\t\tdata_input.id,\r\n\t\tdata_input.type_id,\r\n\t\tdata_template_data.id as data_template_data_id,\r\n\t\tdata_template_data.data_template_id,\r\n\t\tdata_template_data.active,\r\n\t\tdata_template_data.rrd_step\r\n\t\tfrom (data_template_data,data_input)\r\n\t\twhere data_template_data.data_input_id=data_input.id\r\n\t\tand data_template_data.local_data_id={$local_data_id}");
$data_source = db_fetch_row("select host_id,snmp_query_id,snmp_index from data_local where id={$local_data_id}");
/* we have to perform some additional sql queries if this is a "query" */
if ($data_input["type_id"] == DATA_INPUT_TYPE_SNMP_QUERY || $data_input["type_id"] == DATA_INPUT_TYPE_SCRIPT_QUERY || $data_input["type_id"] == DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER) {
$field = data_query_field_list($data_input["data_template_data_id"]);
if (strlen($field["output_type"])) {
$output_type_sql = "and snmp_query_graph_rrd.snmp_query_graph_id='" . $field["output_type"] . "'";
} else {
$output_type_sql = "";
}
$outputs = db_fetch_assoc("select\r\n\t\t\tsnmp_query_graph_rrd.snmp_field_name,\r\n\t\t\tdata_template_rrd.id as data_template_rrd_id\r\n\t\t\tfrom (snmp_query_graph_rrd,data_template_rrd)\r\n\t\t\twhere snmp_query_graph_rrd.data_template_rrd_id=data_template_rrd.local_data_template_rrd_id\r\n\t\t\t{$output_type_sql}\r\n\t\t\tand snmp_query_graph_rrd.data_template_id=" . $data_input["data_template_id"] . "\r\n\t\t\tand data_template_rrd.local_data_id={$local_data_id}\r\n\t\t\torder by data_template_rrd.id");
}
if ($data_input["active"] == "on") {
if ($data_input["type_id"] == DATA_INPUT_TYPE_SCRIPT || $data_input["type_id"] == DATA_INPUT_TYPE_PHP_SCRIPT_SERVER) {
/* script */
/* fall back to non-script server actions if the user is running a version of php older than 4.3 */
if ($data_input["type_id"] == DATA_INPUT_TYPE_PHP_SCRIPT_SERVER && function_exists("proc_open")) {
$action = POLLER_ACTION_SCRIPT_PHP;
$script_path = get_full_script_path($local_data_id);
} else {
if ($data_input["type_id"] == DATA_INPUT_TYPE_PHP_SCRIPT_SERVER && !function_exists("proc_open")) {
$action = POLLER_ACTION_SCRIPT;
$script_path = read_config_option("path_php_binary") . " -q " . get_full_script_path($local_data_id);
} else {
$action = POLLER_ACTION_SCRIPT;
$script_path = get_full_script_path($local_data_id);
}
}
$num_output_fields = sizeof(db_fetch_assoc("select id from data_input_fields where data_input_id=" . $data_input["id"] . " and input_output='out' and update_rra='on'"));
if ($num_output_fields == 1) {
$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_id={$local_data_id}");
$data_source_item_name = get_data_source_item_name($data_template_rrd_id);
} else {
$data_source_item_name = "";
}
$poller_items[] = api_poller_cache_item_add($data_source["host_id"], array(), $local_data_id, $data_input["rrd_step"], $action, $data_source_item_name, 1, addslashes($script_path));
} else {
if ($data_input["type_id"] == DATA_INPUT_TYPE_SNMP) {
/* snmp */
/* get the host override fields */
$data_template_id = db_fetch_cell("SELECT data_template_id FROM data_template_data WHERE local_data_id={$local_data_id}");
/* get host fields first */
$host_fields = array_rekey(db_fetch_assoc("SELECT\r\n\t\t\t\tdata_input_fields.type_code,\r\n\t\t\t\tdata_input_data.value\r\n\t\t\t\tFROM data_input_fields\r\n\t\t\t\tLEFT JOIN data_input_data\r\n\t\t\t\tON (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id=" . $data_input["data_template_data_id"] . ")\r\n\t\t\t\tWHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname') OR (type_code='host_id'))\r\n\t\t\t\tAND data_input_data.value != ''"), "type_code", "value");
$data_template_fields = array_rekey(db_fetch_assoc("SELECT\r\n\t\t\t\tdata_input_fields.type_code,\r\n\t\t\t\tdata_input_data.value\r\n\t\t\t\tFROM data_input_fields\r\n\t\t\t\tLEFT JOIN data_input_data\r\n\t\t\t\tON (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id={$data_template_id})\r\n\t\t\t\tWHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))\r\n\t\t\t\tAND data_template_data_id={$data_template_id}\r\n\t\t\t\tAND data_input_data.value != ''"), "type_code", "value");
if (sizeof($host_fields)) {
if (sizeof($data_template_fields)) {
foreach ($data_template_fields as $key => $value) {
if (!isset($host_fields[$key])) {
$host_fields[$key] = $value;
}
}
}
} elseif (sizeof($data_template_fields)) {
$host_fields = $data_template_fields;
}
$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_id={$local_data_id}");
$poller_items[] = api_poller_cache_item_add($data_source["host_id"], $host_fields, $local_data_id, $data_input["rrd_step"], 0, get_data_source_item_name($data_template_rrd_id), 1, isset($host_fields["snmp_oid"]) ? $host_fields["snmp_oid"] : "");
} else {
if ($data_input["type_id"] == DATA_INPUT_TYPE_SNMP_QUERY) {
/* snmp query */
$snmp_queries = get_data_query_array($data_source["snmp_query_id"]);
/* get the host override fields */
$data_template_id = db_fetch_cell("SELECT data_template_id FROM data_template_data WHERE local_data_id={$local_data_id}");
/* get host fields first */
$host_fields = array_rekey(db_fetch_assoc("SELECT\r\n\t\t\t\tdata_input_fields.type_code,\r\n\t\t\t\tdata_input_data.value\r\n\t\t\t\tFROM data_input_fields\r\n\t\t\t\tLEFT JOIN data_input_data\r\n\t\t\t\tON (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id=" . $data_input["data_template_data_id"] . ")\r\n\t\t\t\tWHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))\r\n\t\t\t\tAND data_input_data.value != ''"), "type_code", "value");
$data_template_fields = array_rekey(db_fetch_assoc("SELECT\r\n\t\t\t\tdata_input_fields.type_code,\r\n\t\t\t\tdata_input_data.value\r\n\t\t\t\tFROM data_input_fields\r\n\t\t\t\tLEFT JOIN data_input_data\r\n\t\t\t\tON (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id={$data_template_id})\r\n\t\t\t\tWHERE ((type_code LIKE 'snmp_%') OR (type_code='hostname'))\r\n\t\t\t\tAND data_template_data_id={$data_template_id}\r\n\t\t\t\tAND data_input_data.value != ''"), "type_code", "value");
if (sizeof($host_fields)) {
if (sizeof($data_template_fields)) {
foreach ($data_template_fields as $key => $value) {
if (!isset($host_fields[$key])) {
$host_fields[$key] = $value;
}
}
}
} elseif (sizeof($data_template_fields)) {
$host_fields = $data_template_fields;
}
if (sizeof($outputs) > 0) {
foreach ($outputs as $output) {
if (isset($snmp_queries["fields"][$output["snmp_field_name"]]["oid"])) {
$oid = $snmp_queries["fields"][$output["snmp_field_name"]]["oid"] . "." . $data_source["snmp_index"];
if (isset($snmp_queries["fields"][$output["snmp_field_name"]]["oid_suffix"])) {
$oid .= "." . $snmp_queries["fields"][$output["snmp_field_name"]]["oid_suffix"];
}
}
if (!empty($oid)) {
$poller_items[] = api_poller_cache_item_add($data_source["host_id"], $host_fields, $local_data_id, $data_input["rrd_step"], 0, get_data_source_item_name($output["data_template_rrd_id"]), sizeof($outputs), $oid);
}
}
}
} else {
if ($data_input["type_id"] == DATA_INPUT_TYPE_SCRIPT_QUERY || $data_input["type_id"] == DATA_INPUT_TYPE_QUERY_SCRIPT_SERVER) {
/* script query */
$script_queries = get_data_query_array($data_source["snmp_query_id"]);
//.........这里部分代码省略.........
开发者ID:resmon,项目名称:resmon-cacti,代码行数:101,代码来源:utility.php
示例9: graphs
//.........这里部分代码省略.........
}
$available_graph_templates = db_fetch_assoc("SELECT
graph_templates.id, graph_templates.name
FROM snmp_query_graph RIGHT JOIN graph_templates
ON (snmp_query_graph.graph_template_id = graph_templates.id)
WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name");
/* create a row at the bottom that lets the user create any graph they choose */
print " <tr bgcolor='#" . (($i % 2 == 0) ? "ffffff" : $colors["light"]) . "'>
<td colspan='2' width='60' nowrap>
<strong>Create:</strong> ";
form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "font-size: 10px;");
print " </td>
</tr>";
html_end_box();
$snmp_queries = db_fetch_assoc("select
snmp_query.id,
snmp_query.name,
snmp_query.xml_path
from (snmp_query,host_snmp_query)
where host_snmp_query.snmp_query_id=snmp_query.id
and host_snmp_query.host_id=" . $host["id"] . "
order by snmp_query.name");
print "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n";
if (sizeof($snmp_queries) > 0) {
foreach ($snmp_queries as $snmp_query) {
unset($total_rows);
$xml_array = get_data_query_array($snmp_query["id"]);
$num_input_fields = 0;
$num_visi
|
请发表评论