function form_actions()
{
global $colors, $device_actions, $fields_host_edit;
/* if we are to save this form, instead of display it */
if (isset($_POST["selected_items"])) {
$selected_items = unserialize(stripslashes($_POST["selected_items"]));
if ($_POST["drp_action"] == "2") {
/* Enable Selected Devices */
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");
/* update poller cache */
$data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");
if (sizeof($data_sources) > 0) {
foreach ($data_sources as $data_source) {
update_poller_cache($data_source["id"], false);
}
}
}
} elseif ($_POST["drp_action"] == "3") {
/* Disable Selected Devices */
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");
/* update poller cache */
db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
}
} elseif ($_POST["drp_action"] == "4") {
/* change snmp options */
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
reset($fields_host_edit);
while (list($field_name, $field_array) = each($fields_host_edit)) {
if (isset($_POST["t_{$field_name}"])) {
db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
}
}
push_out_host($selected_items[$i]);
}
} elseif ($_POST["drp_action"] == "5") {
/* Clear Statisitics for Selected Devices */
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'");
}
} elseif ($_POST["drp_action"] == "6") {
/* change availability options */
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
reset($fields_host_edit);
while (list($field_name, $field_array) = each($fields_host_edit)) {
if (isset($_POST["t_{$field_name}"])) {
db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
}
}
push_out_host($selected_items[$i]);
}
} elseif ($_POST["drp_action"] == "1") {
/* delete */
if (!isset($_POST["delete_type"])) {
$_POST["delete_type"] = 2;
}
$data_sources_to_act_on = array();
$graphs_to_act_on = array();
$devices_to_act_on = array();
for ($i = 0; $i < count($selected_items); $i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
$data_sources = db_fetch_assoc("select\n\t\t\t\t\tdata_local.id as local_data_id\n\t\t\t\t\tfrom data_local\n\t\t\t\t\twhere " . array_to_sql_or($selected_items, "data_local.host_id"));
if (sizeof($data_sources) > 0) {
foreach ($data_sources as $data_source) {
$data_sources_to_act_on[] = $data_source["local_data_id"];
}
}
if ($_POST["delete_type"] == 2) {
$graphs = db_fetch_assoc("select\n\t\t\t\t\t\tgraph_local.id as local_graph_id\n\t\t\t\t\t\tfrom graph_local\n\t\t\t\t\t\twhere " . array_to_sql_or($selected_items, "graph_local.host_id"));
if (sizeof($graphs) > 0) {
foreach ($graphs as $graph) {
$graphs_to_act_on[] = $graph["local_graph_id"];
}
}
}
$devices_to_act_on[] = $selected_items[$i];
}
switch ($_POST["delete_type"]) {
case '1':
/* leave graphs and data_sources in place, but disable the data sources */
api_data_source_disable_multi($data_sources_to_act_on);
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:host.php
示例4: push_out_host
function push_out_host($host_id, $local_data_id = 0, $data_template_id = 0) {
/* ok here's the deal: first we need to find every data source that uses this host.
then we go through each of those data sources, finding each one using a data input method
with "special fields". if we find one, fill it will the data here from this host */
if (!empty($data_template_id)) {
$hosts = db_fetch_assoc("select host_id from data_local where data_template_id=$data_template_id group by host_id");
if (sizeof($hosts) > 0) {
foreach ($hosts as $host) {
push_out_host($host["host_id"]);
}
}
}
if (empty($host_id)) { return 0; }
/* get all information about this host so we can write it to the data source */
$host = db_fetch_row("select * from host where id=$host_id");
$data_sources = db_fetch_assoc("select
data_template_data.id,
data_template_data.data_input_id,
data_template_data.local_data_id,
data_template_data.local_data_template_data_id
from data_local,data_template_data
where " . (empty($local_data_id) ? "data_local.host_id=$host_id" : "data_local.id=$local_data_id") . "
and data_local.id=data_template_data.local_data_id
and data_template_data.data_input_id>0");
/* loop through each matching data source */
if (sizeof($data_sources) > 0) {
foreach ($data_sources as $data_source) {
/* get field information from the data template */
if (!isset($template_fields{$data_source["local_data_template_data_id"]})) {
$template_fields{$data_source["local_data_template_data_id"]} = db_fetch_assoc("select
data_input_data.value,
data_input_data.t_value,
data_input_fields.id,
data_input_fields.type_code
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_source["local_data_template_data_id"] . ")
where data_input_fields.data_input_id=" . $data_source["data_input_id"] . "
and (data_input_data.t_value='' or data_input_data.t_value is null)
and data_input_fields.input_output='in'");
}
reset($template_fields{$data_source["local_data_template_data_id"]});
/* loop through each field contained in the data template and push out a host value if:
- the field is a valid "host field"
- the value of the field is empty
- the field is set to 'templated' */
if (sizeof($template_fields{$data_source["local_data_template_data_id"]})) {
foreach ($template_fields{$data_source["local_data_template_data_id"]} as $template_field) {
if ((eregi('^' . VALID_HOST_FIELDS . '$', $template_field["type_code"])) && ($template_field["value"] == "") && ($template_field["t_value"] == "")) {
db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,value) values (" . $template_field["id"] . "," . $data_source["id"] . ",'" . $host{$template_field["type_code"]} . "')");
}
}
}
/* make sure to update the poller cache as well */
update_poller_cache($data_source["local_data_id"], false);
}
}
}
function host_new_graphs_save()
{
$selected_graphs_array = unserialize(stripslashes($_POST['selected_graphs_array']));
/* form an array that contains all of the data on the previous form */
while (list($var, $val) = each($_POST)) {
if (preg_match('/^g_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) {
/* 1: snmp_query_id, 2: graph_template_id, 3: field_name */
if (empty($matches[1])) {
/* this is a new graph from template field */
$values['cg'][$matches[2]]['graph_template'][$matches[3]] = $val;
} else {
/* this is a data query field */
$values['sg'][$matches[1]][$matches[2]]['graph_template'][$matches[3]] = $val;
}
} elseif (preg_match('/^gi_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) {
/* 1: snmp_query_id, 2: graph_template_id, 3: graph_template_input_id, 4:field_name */
/* ================= input validation ================= */
input_validate_input_number($matches[3]);
/* ==================================================== */
/* we need to find out which graph items will be affected by saving this particular item */
$item_list = db_fetch_assoc_prepared('SELECT
graph_template_item_id
FROM graph_template_input_defs
WHERE graph_template_input_id = ?', array($matches[3]));
/* loop through each item affected and update column data */
if (sizeof($item_list) > 0) {
foreach ($item_list as $item) {
if (empty($matches[1])) {
/* this is a new graph from template field */
$values['cg'][$matches[2]]['graph_template_item'][$item['graph_template_item_id']][$matches[4]] = $val;
} else {
/* this is a data query field */
$values['sg'][$matches[1]][$matches[2]]['graph_template_item'][$item['graph_template_item_id']][$matches[4]] = $val;
}
}
}
} elseif (preg_match('/^d_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) {
/* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:field_name */
if (empty($matches[1])) {
/* this is a new graph from template field */
$values['cg'][$matches[2]]['data_template'][$matches[3]][$matches[4]] = $val;
} else {
/* this is a data query field */
$values['sg'][$matches[1]][$matches[2]]['data_template'][$matches[3]][$matches[4]] = $val;
}
} elseif (preg_match('/^c_(\\d+)_(\\d+)_(\\d+)_(\\d+)/', $var, $matches)) {
/* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:data_input_field_id */
if (empty($matches[1])) {
/* this is a new graph from template field */
$values['cg'][$matches[2]]['custom_data'][$matches[3]][$matches[4]] = $val;
} else {
/* this is a data query field */
$values['sg'][$matches[1]][$matches[2]]['custom_data'][$matches[3]][$matches[4]] = $val;
}
} elseif (preg_match('/^di_(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) {
/* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:local_data_template_rrd_id, 5:field_name */
if (empty($matches[1])) {
/* this is a new graph from template field */
$values['cg'][$matches[2]]['data_template_item'][$matches[4]][$matches[5]] = $val;
} else {
/* this is a data query field */
$values['sg'][$matches[1]][$matches[2]]['data_template_item'][$matches[4]][$matches[5]] = $val;
}
}
}
debug_log_clear('new_graphs');
while (list($form_type, $form_array) = each($selected_graphs_array)) {
$current_form_type = $form_type;
while (list($form_id1, $form_array2) = each($form_array)) {
/* enumerate information from the arrays stored in post variables */
if ($form_type == 'cg') {
$graph_template_id = $form_id1;
} elseif ($form_type == 'sg') {
while (list($form_id2, $form_array3) = each($form_array2)) {
$snmp_index_array = $form_array3;
$snmp_query_array['snmp_query_id'] = $form_id1;
$snmp_query_array['snmp_index_on'] = get_best_data_query_index_type($_POST['host_id'], $form_id1);
$snmp_query_array['snmp_query_graph_id'] = $form_id2;
}
$graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id FROM snmp_query_graph WHERE id = ?', array($snmp_query_array['snmp_query_graph_id']));
}
if ($current_form_type == 'cg') {
$return_array = create_complete_graph_from_template($graph_template_id, $_POST['host_id'], '', $values['cg']);
debug_log_insert('new_graphs', 'Created graph: ' . get_graph_title($return_array['local_graph_id']));
/* lastly push host-specific information to our data sources */
if (sizeof($return_array['local_data_id'])) {
# we expect at least one data source associated
foreach ($return_array['local_data_id'] as $item) {
push_out_host($_POST['host_id'], $item);
}
} else {
debug_log_insert('new_graphs', 'ERROR: no Data Source associated. Check Template');
}
} elseif ($current_form_type == 'sg') {
while (list($snmp_index, $true) = each($snmp_index_array)) {
$snmp_query_array['snmp_index'] = decode_data_query_index($snmp_index, $snmp_query_array['snmp_query_id'], $_POST['host_id']);
$return_array = create_complete_graph_from_template($graph_template_id, $_POST['host_id'], $snmp_query_array, $values['sg'][$snmp_query_array['snmp_query_id']]);
debug_log_insert('new_graphs', 'Created graph: ' . get_graph_title($return_array['local_graph_id']));
/* lastly push host-specific information to our data sources */
if (sizeof($return_array['local_data_id'])) {
//.........这里部分代码省略.........
请发表评论