1 Star 0 Fork 0

wlnmp/cacti

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
automation_graph_rules.php 35.82 KB
一键复制 编辑 原始数据 按行查看 历史
cigamit 提交于 2019-07-24 18:05 . Resolving Issue #2839
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2019 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
include('./include/auth.php');
include_once('./lib/data_query.php');
$automation_graph_rules_actions = array(
AUTOMATION_ACTION_GRAPH_DUPLICATE => __('Duplicate'),
AUTOMATION_ACTION_GRAPH_ENABLE => __('Enable'),
AUTOMATION_ACTION_GRAPH_DISABLE => __('Disable'),
AUTOMATION_ACTION_GRAPH_DELETE => __('Delete'),
);
/* set default action */
set_default_action();
switch (get_request_var('action')) {
case 'save':
save();
break;
case 'actions':
automation_graph_rules_form_actions();
break;
case 'item_movedown':
automation_graph_rules_item_movedown();
header('Location: automation_graph_rules.php?action=edit&id=' . get_filter_request_var('id'));
break;
case 'item_moveup':
automation_graph_rules_item_moveup();
header('Location: automation_graph_rules.php?action=edit&id=' . get_filter_request_var('id'));
break;
case 'item_remove':
automation_graph_rules_item_remove();
header('Location: automation_graph_rules.php?action=edit&id=' . get_filter_request_var('id'));
break;
case 'item_edit':
top_header();
automation_graph_rules_item_edit();
bottom_footer();
break;
case 'qedit':
automation_change_query_type();
header('Location: automation_graph_rules.php?header=false&action=edit&name=' . get_request_var('name') . '&id=' . get_filter_request_var('id'));
break;
case 'remove':
automation_graph_rules_remove();
header ('Location: automation_graph_rules.php');
break;
case 'edit':
top_header();
automation_graph_rules_edit();
bottom_footer();
break;
default:
top_header();
automation_graph_rules();
bottom_footer();
break;
}
/* --------------------------
The Save Function
-------------------------- */
function save() {
if (isset_request_var('save_component_automation_graph_rule')) {
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
$save['id'] = get_nfilter_request_var('id');
$save['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3);
$save['snmp_query_id'] = form_input_validate(get_nfilter_request_var('snmp_query_id'), 'snmp_query_id', '^[0-9]+$', false, 3);
$save['graph_type_id'] = (isset_request_var('graph_type_id')) ? form_input_validate(get_nfilter_request_var('graph_type_id'), 'graph_type_id', '^[0-9]+$', false, 3) : 0;
$save['enabled'] = (isset_request_var('enabled') ? 'on' : '');
if (!is_error_message()) {
$rule_id = sql_save($save, 'automation_graph_rules');
if ($rule_id) {
raise_message(1);
} else {
raise_message(2);
}
}
header('Location: automation_graph_rules.php?header=false&action=edit&id=' . (empty($rule_id) ? get_nfilter_request_var('id') : $rule_id));
} elseif (isset_request_var('save_component_automation_graph_rule_item')) {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('item_id');
/* ==================================================== */
$save = array();
$save['id'] = form_input_validate(get_request_var('item_id'), 'item_id', '^[0-9]+$', false, 3);
$save['rule_id'] = form_input_validate(get_request_var('id'), 'id', '^[0-9]+$', false, 3);
$save['sequence'] = form_input_validate(get_nfilter_request_var('sequence'), 'sequence', '^[0-9]+$', false, 3);
$save['operation'] = form_input_validate(get_nfilter_request_var('operation'), 'operation', '^[-0-9]+$', true, 3);
$save['field'] = form_input_validate(((isset_request_var('field') && get_nfilter_request_var('field') != '0') ? get_nfilter_request_var('field') : ''), 'field', '', true, 3);
$save['operator'] = form_input_validate((isset_request_var('operator') ? get_nfilter_request_var('operator') : ''), 'operator', '^[0-9]+$', true, 3);
$save['pattern'] = form_input_validate((isset_request_var('pattern') ? get_nfilter_request_var('pattern') : ''), 'pattern', '', true, 3);
if (!is_error_message()) {
$item_id = sql_save($save, 'automation_graph_rule_items');
if ($item_id) {
raise_message(1);
} else {
raise_message(2);
}
}
if (is_error_message()) {
header('Location: automation_graph_rules.php?header=false&action=item_edit&id=' . get_request_var('id') . '&item_id=' . (empty($item_id) ? get_request_var('item_id') : $item_id) . '&rule_type=' . AUTOMATION_RULE_TYPE_GRAPH_ACTION);
} else {
header('Location: automation_graph_rules.php?header=false&action=edit&id=' . get_request_var('id') . '&rule_type=' . AUTOMATION_RULE_TYPE_GRAPH_ACTION);
}
} elseif (isset_request_var('save_component_automation_match_item')) {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('item_id');
/* ==================================================== */
unset($save);
$save['id'] = form_input_validate(get_request_var('item_id'), 'item_id', '^[0-9]+$', false, 3);
$save['rule_id'] = form_input_validate(get_request_var('id'), 'id', '^[0-9]+$', false, 3);
$save['rule_type'] = AUTOMATION_RULE_TYPE_GRAPH_MATCH;
$save['sequence'] = form_input_validate(get_nfilter_request_var('sequence'), 'sequence', '^[0-9]+$', false, 3);
$save['operation'] = form_input_validate(get_nfilter_request_var('operation'), 'operation', '^[-0-9]+$', true, 3);
$save['field'] = form_input_validate(((isset_request_var('field') && get_nfilter_request_var('field') != '0') ? get_nfilter_request_var('field') : ''), 'field', '', true, 3);
$save['operator'] = form_input_validate((isset_request_var('operator') ? get_nfilter_request_var('operator') : ''), 'operator', '^[0-9]+$', true, 3);
$save['pattern'] = form_input_validate((isset_request_var('pattern') ? get_nfilter_request_var('pattern') : ''), 'pattern', '', true, 3);
if (!is_error_message()) {
$item_id = sql_save($save, 'automation_match_rule_items');
if ($item_id) {
raise_message(1);
} else {
raise_message(2);
}
}
if (is_error_message()) {
header('Location: automation_graph_rules.php?header=false&action=item_edit&id=' . get_request_var('id') . '&item_id=' . (empty($item_id) ? get_request_var('item_id') : $item_id) . '&rule_type=' . AUTOMATION_RULE_TYPE_GRAPH_MATCH);
} else {
header('Location: automation_graph_rules.php?header=false&action=edit&id=' . get_request_var('id') . '&rule_type=' . AUTOMATION_RULE_TYPE_GRAPH_MATCH);
}
} else {
raise_message(2);
header('Location: automation_graph_rules.php?header=false');
}
}
/* ------------------------
The 'actions' function
------------------------ */
function automation_graph_rules_form_actions() {
global $config, $automation_graph_rules_actions;
/* ================= input validation ================= */
get_filter_request_var('drp_action');
/* ==================================================== */
/* if we are to save this form, instead of display it */
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_nfilter_request_var('drp_action') == AUTOMATION_ACTION_GRAPH_DELETE) { /* delete */
db_execute('DELETE FROM automation_graph_rules WHERE ' . array_to_sql_or($selected_items, 'id'));
db_execute('DELETE FROM automation_graph_rule_items WHERE ' . array_to_sql_or($selected_items, 'rule_id'));
db_execute('DELETE FROM automation_match_rule_items WHERE ' . array_to_sql_or($selected_items, 'rule_id'));
} elseif (get_nfilter_request_var('drp_action') == AUTOMATION_ACTION_GRAPH_DUPLICATE) { /* duplicate */
for ($i=0;($i<cacti_count($selected_items));$i++) {
cacti_log('form_actions duplicate: ' . $selected_items[$i] . ' name: ' . get_nfilter_request_var('name_format'), true, 'AUTOM8 TRACE', POLLER_VERBOSITY_MEDIUM);
duplicate_automation_graph_rules($selected_items[$i], get_nfilter_request_var('name_format'));
}
} elseif (get_nfilter_request_var('drp_action') == AUTOMATION_ACTION_GRAPH_ENABLE) { /* enable */
for ($i=0;($i<cacti_count($selected_items));$i++) {
cacti_log('form_actions enable: ' . $selected_items[$i], true, 'AUTOM8 TRACE', POLLER_VERBOSITY_MEDIUM);
db_execute_prepared("UPDATE automation_graph_rules
SET enabled='on'
WHERE id = ?",
array($selected_items[$i]));
}
} elseif (get_nfilter_request_var('drp_action') == AUTOMATION_ACTION_GRAPH_DISABLE) { /* disable */
for ($i=0;($i<cacti_count($selected_items));$i++) {
cacti_log('form_actions disable: ' . $selected_items[$i], true, 'AUTOM8 TRACE', POLLER_VERBOSITY_MEDIUM);
db_execute_prepared("UPDATE automation_graph_rules
SET enabled=''
WHERE id = ?",
array($selected_items[$i]));
}
}
}
header('Location: automation_graph_rules.php?header=false');
exit;
}
/* setup some variables */
$automation_graph_rules_list = ''; $i = 0;
/* loop through each of the graphs selected on the previous page and get more info about them */
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
$automation_graph_rules_list .= '<li>' . html_escape(db_fetch_cell_prepared('SELECT name FROM automation_graph_rules WHERE id = ?', array($matches[1]))) . '</li>';
$automation_graph_rules_array[] = $matches[1];
}
}
top_header();
form_start('automation_graph_rules.php', 'automation_graph_rules');
html_start_box($automation_graph_rules_actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', '');
if (get_nfilter_request_var('drp_action') == AUTOMATION_ACTION_GRAPH_DELETE) { /* delete */
print "<tr>
<td class='textArea'>
<p>" . __('Press \'Continue\' to delete the following Graph Rules.') . "</p>
<ul>$automation_graph_rules_list</ul>
</td>
</tr>";
} elseif (get_nfilter_request_var('drp_action') == AUTOMATION_ACTION_GRAPH_DUPLICATE) { /* duplicate */
print "<tr>
<td class='textArea'>
<p>" . __('Click \'Continue\' to duplicate the following Rule(s). You can optionally change the title format for the new Graph Rules.') . "</p>
<div class='itemlist'><ul>$automation_graph_rules_list</ul></div>
<p>" . __('Title Format') . '<br>'; form_text_box('name_format', '<' . __('rule_name') . '> (1)', '', '255', '30', 'text'); print "</p>
</td>
</tr>\n";
} elseif (get_nfilter_request_var('drp_action') == AUTOMATION_ACTION_GRAPH_ENABLE) { /* enable */
print "<tr>
<td class='textArea'>
<p>" . __('Click \'Continue\' to enable the following Rule(s).') . "</p>
<div class='itemlist'><ul>$automation_graph_rules_list</ul></div>
<p>" . __('Make sure, that those rules have successfully been tested!') . "</p>
</td>
</tr>\n";
} elseif (get_nfilter_request_var('drp_action') == AUTOMATION_ACTION_GRAPH_DISABLE) { /* disable */
print "<tr>
<td class='textArea'>
<p>" . __('Click \'Continue\' to disable the following Rule(s).') . "</p>
<div class='itemlist'><ul>$automation_graph_rules_list</ul></div>
</td>
</tr>\n";
}
if (!isset($automation_graph_rules_array)) {
raise_message(40);
header('Location: automation_graph_rules.php?header=false');
exit;
} else {
$save_html = "<input type='button' class='ui-button ui-corner-all ui-widget' value='" . __esc('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' class='ui-button ui-corner-all ui-widget' value='" . __esc('Continue') . "' title='" . __esc('Apply requested action') . "'>";
}
print " <tr>
<td class='saveRow'>
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . (isset($automation_graph_rules_array) ? serialize($automation_graph_rules_array) : '') . "'>
<input type='hidden' name='drp_action' value='" . html_escape(get_nfilter_request_var('drp_action')) . "'>
$save_html
</td>
</tr>\n";
html_end_box();
form_end();
bottom_footer();
}
/* --------------------------
Rule Item Functions
-------------------------- */
function automation_graph_rules_item_movedown() {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('item_id');
get_filter_request_var('rule_type');
/* ==================================================== */
if (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_GRAPH_MATCH) {
move_item_down('automation_match_rule_items', get_request_var('item_id'), 'rule_id=' . get_request_var('id') . ' AND rule_type=' . get_request_var('rule_type'));
} elseif (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_GRAPH_ACTION) {
move_item_down('automation_graph_rule_items', get_request_var('item_id'), 'rule_id=' . get_request_var('id'));
}
}
function automation_graph_rules_item_moveup() {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('item_id');
get_filter_request_var('rule_type');
/* ==================================================== */
if (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_GRAPH_MATCH) {
move_item_up('automation_match_rule_items', get_request_var('item_id'), 'rule_id=' . get_request_var('id') . ' AND rule_type=' . get_request_var('rule_type'));
} elseif (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_GRAPH_ACTION) {
move_item_up('automation_graph_rule_items', get_request_var('item_id'), 'rule_id=' . get_request_var('id'));
}
}
function automation_graph_rules_item_remove() {
/* ================= input validation ================= */
get_filter_request_var('item_id');
get_filter_request_var('rule_type');
/* ==================================================== */
if (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_GRAPH_MATCH) {
db_execute_prepared('DELETE FROM automation_match_rule_items WHERE id = ?', array(get_request_var('item_id')));
} elseif (get_request_var('rule_type') == AUTOMATION_RULE_TYPE_GRAPH_ACTION) {
db_execute_prepared('DELETE FROM automation_graph_rule_items WHERE id = ?', array(get_request_var('item_id')));
}
}
function automation_graph_rules_item_edit() {
global $config;
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('item_id');
get_filter_request_var('rule_type');
/* ==================================================== */
global_item_edit(get_request_var('id'), get_request_var('item_id'), get_request_var('rule_type'));
form_hidden_box('rule_type', get_request_var('rule_type'), get_request_var('rule_type'));
form_hidden_box('id', (isset_request_var('id') ? get_request_var('id') : '0'), '');
form_hidden_box('item_id', (isset_request_var('item_id') ? get_request_var('item_id') : '0'), '');
if(get_request_var('rule_type') == AUTOMATION_RULE_TYPE_GRAPH_MATCH) {
form_hidden_box('save_component_automation_match_item', '1', '');
} else {
form_hidden_box('save_component_automation_graph_rule_item', '1', '');
}
form_save_button('automation_graph_rules.php?action=edit&id=' . get_request_var('id') . '&rule_type='. get_request_var('rule_type'));
?>
<script type='text/javascript'>
$(function() {
toggle_operation();
toggle_operator();
});
function toggle_operation() {
if ($('#operation').val() == '<?php print AUTOMATION_OPER_RIGHT_BRACKET;?>') {
$('#field').val('');
$('#field').prop('disabled', true);
$('#operator').val(0);
$('#operator').prop('disabled', true);
$('#pattern').val('');
$('#pattern').prop('disabled', true);
} else {
$('#field').prop('disabled', false);
$('#operator').prop('disabled', false);
$('#pattern').prop('disabled', false);
}
}
function toggle_operator() {
if ($('#operator').val() == '<?php print AUTOMATION_OPER_RIGHT_BRACKET;?>') {
} else {
}
}
</script>
<?php
}
/* ---------------------
Rule Functions
--------------------- */
function automation_graph_rules_remove() {
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
if ((read_config_option('deletion_verification') == 'on') && (!isset_request_var('confirm'))) {
top_header();
form_confirm(__('Are You Sure?'), __("Are you sure you want to delete the Rule '%s'?", db_fetch_cell_prepared('SELECT name FROM automation_graph_rules WHERE id = ?', array(get_request_var('id')))), 'automation_graph_rules.php', 'automation_graph_rules.php?action=remove&id=' . get_request_var('id'));
bottom_footer();
exit;
}
if ((read_config_option('deletion_verification') == '') || (isset_request_var('confirm'))) {
db_execute_prepared('DELETE FROM automation_match_rule_items
WHERE rule_id = ?
AND rule_type = ?',
array(get_request_var('id'), AUTOMATION_RULE_TYPE_GRAPH_MATCH));
db_execute_prepared('DELETE FROM automation_graph_rule_items
WHERE rule_id = ?',
array(get_request_var('id')));
db_execute_prepared('DELETE FROM automation_graph_rules
WHERE id = ?',
array(get_request_var('id')));
}
}
function automation_change_query_type() {
$id = get_filter_request_var('id');
if (isset_request_var('snmp_query_id') && $id > 0) {
$snmp_query_id = get_filter_request_var('snmp_query_id');
$name = get_nfilter_request_var('name');
db_execute_prepared('UPDATE automation_graph_rules
SET snmp_query_id = ?, name = ?
WHERE id = ?',
array($snmp_query_id, $name, $id));
$graph_type = db_fetch_cell_prepared('SELECT id
FROM snmp_query_graph
WHERE snmp_query_id = ?
ORDER BY name
LIMIT 1', array($snmp_query_id));
db_execute_prepared('UPDATE automation_graph_rules
SET graph_type_id = ?
WHERE id = ?',
array($graph_type, $id));
} elseif (isset_request_var('graph_type_id') && $id > 0) {
$snmp_query_id = get_filter_request_var('graph_type_id');
$name = get_nfilter_request_var('name');
db_execute_prepared('UPDATE automation_graph_rules
SET graph_type_id = ?, name = ?
WHERE id = ?',
array($snmp_query_id, $name, $id));
}
}
function automation_graph_rules_edit() {
global $config;
global $fields_automation_graph_rules_edit1, $fields_automation_graph_rules_edit2, $fields_automation_graph_rules_edit3;
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('snmp_query_id');
get_filter_request_var('graph_type_id');
get_filter_request_var('show_graphs');
get_filter_request_var('show_hosts');
get_filter_request_var('show_rule');
/* ==================================================== */
/* clean up rule name */
if (isset_request_var('name')) {
set_request_var('name', sanitize_search_string(get_request_var('name')));
}
/* handle show_rule mode */
if (isset_request_var('show_rule')) {
if (get_request_var('show_rule') == '0') {
kill_session_var('automation_graph_rules_show_rule');
$_SESSION['automation_graph_rules_show_rule'] = false;
} elseif (get_request_var('show_rule') == '1') {
$_SESSION['automation_graph_rules_show_rule'] = true;
}
} elseif (!isset($_SESSION['automation_graph_rules_show_rule'])) {
$_SESSION['automation_graph_rules_show_rule'] = true;
}
/* handle show_graphs mode */
if (isset_request_var('show_graphs')) {
if (get_request_var('show_graphs') == '0') {
kill_session_var('automation_graph_rules_show_graphs');
} elseif (get_request_var('show_graphs') == '1') {
$_SESSION['automation_graph_rules_show_graphs'] = true;
}
}
/* handle show_hosts mode */
if (isset_request_var('show_hosts')) {
if (get_request_var('show_hosts') == '0') {
kill_session_var('automation_graph_rules_show_hosts');
} elseif (get_request_var('show_hosts') == '1') {
$_SESSION['automation_graph_rules_show_hosts'] = true;
}
}
/*
* display the rule -------------------------------------------------------------------------------------
*/
$rule = array();
if (!isempty_request_var('id')) {
$rule = db_fetch_row_prepared('SELECT * FROM automation_graph_rules where id = ?', array(get_request_var('id')));
if (!isempty_request_var('graph_type_id')) {
$rule['graph_type_id'] = get_request_var('graph_type_id'); # set query_type for display
}
# setup header
$header_label = __('Rule Selection [edit: %s]', html_escape($rule['name']));
} else {
$rule = array (
'name' => get_request_var('name'),
'snmp_query_id' => get_request_var('snmp_query_id'),
);
$header_label = __('Rule Selection [new]');
}
/*
* show rule? ------------------------------------------------------------------------------------------
*/
if (!isempty_request_var('id')) {
?>
<table style='width:100%;text-align:center;'>
<tr>
<td class='textInfo right' style='vertical-align:top;'><span class='linkMarker'>*</span><a class='linkEditMain' href='<?php print html_escape('automation_graph_rules.php?action=edit&id=' . (isset_request_var('id') ? get_request_var('id') : 0) . '&show_rule=') . ($_SESSION['automation_graph_rules_show_rule'] == true ? '0' : '1');?>'><?php print ($_SESSION['automation_graph_rules_show_rule'] == true ? __('Don\'t Show'):__('Show'));?> <?php print __('Rule Details.');?></a><br>
</td>
</tr>
</table>
<?php
}
/*
* show hosts? ------------------------------------------------------------------------------------------
*/
if (!isempty_request_var('id')) {
?>
<table style='width:100%;text-align:center;'>
<tr>
<td class='textInfo right' style='vertical-align:top;'><span class='linkMarker'>*</span><a class='linkEditMain' href='<?php print html_escape('automation_graph_rules.php?action=edit&id=' . (isset_request_var('id') ? get_request_var('id') : 0) . '&show_hosts=') . (isset($_SESSION['automation_graph_rules_show_hosts']) ? '0' : '1');?>'><?php print (isset($_SESSION['automation_graph_rules_show_hosts']) ? __('Don\'t Show'):__('Show'));?> <?php print __('Matching Devices.');?></a><br>
</td>
</tr>
</table>
<?php
}
/*
* show graphs? -----------------------------------------------------------------------------------------
*/
if (!empty($rule['graph_type_id']) && $rule['graph_type_id'] > 0) {
?>
<table style='width:100%;text-align:center;'>
<tr>
<td class='textInfo right' style='vertical-align:top;'>
<span class='linkMarker'>*</span><a class='linkEditMain' href='<?php print html_escape('automation_graph_rules.php?action=edit&id=' . (isset_request_var('id') ? get_request_var('id') : 0) . '&show_graphs=') . (isset($_SESSION['automation_graph_rules_show_graphs']) ? '0' : '1');?>'><?php print (isset($_SESSION['automation_graph_rules_show_graphs']) ? __('Don\'t Show'):__('Show'));?> <?php print __('Matching Objects.');?></a><br>
</td>
</tr>
</table>
<?php
}
if ($_SESSION['automation_graph_rules_show_rule']) {
form_start('automation_graph_rules.php', 'chk');
html_start_box($header_label, '100%', true, '3', 'center', '');
if (!isempty_request_var('id')) {
/* display whole rule */
$form_array = $fields_automation_graph_rules_edit1 + $fields_automation_graph_rules_edit2 + $fields_automation_graph_rules_edit3;
} else {
/* display first part of rule only and request user to proceed */
$form_array = $fields_automation_graph_rules_edit1;
}
if (isset_request_var('name')) {
$rule['name'] = get_request_var('name');
}
draw_edit_form(array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($form_array, (isset($rule) ? $rule : array()))
));
html_end_box(true, true);
form_hidden_box('id', (isset($rule['id']) ? $rule['id'] : '0'), '');
form_hidden_box('item_id', (isset($rule['item_id']) ? $rule['item_id'] : '0'), '');
form_hidden_box('save_component_automation_graph_rule', '1', '');
/*
* display the rule items -------------------------------------------------------------------------------
*/
if (!empty($rule['id'])) {
# display graph rules for host match
display_match_rule_items(__('Device Selection Criteria'),
$rule['id'],
AUTOMATION_RULE_TYPE_GRAPH_MATCH,
'automation_graph_rules.php');
# fetch graph action rules
display_graph_rule_items(__('Graph Creation Criteria'),
$rule['id'],
AUTOMATION_RULE_TYPE_GRAPH_ACTION,
'automation_graph_rules.php');
}
form_save_button('automation_graph_rules.php', 'return');
print '<br>';
}
if (!empty($rule['id'])) {
/* display list of matching hosts */
if (isset($_SESSION['automation_graph_rules_show_hosts'])) {
if ($_SESSION['automation_graph_rules_show_hosts']) {
display_matching_hosts($rule, AUTOMATION_RULE_TYPE_GRAPH_MATCH, 'automation_graph_rules.php?action=edit&id=' . get_request_var('id'));
}
}
/* display list of new graphs */
if (isset($_SESSION['automation_graph_rules_show_graphs'])) {
if ($_SESSION['automation_graph_rules_show_graphs']) {
display_new_graphs($rule, 'automation_graph_rules.php?action=edit&id=' . get_request_var('id'));
}
}
}
?>
<script type='text/javascript'>
function applySNMPQueryIdChange() {
strURL = 'automation_graph_rules.php?action=qedit';
strURL += '&id=' + $('#id').val();
strURL += '&name=' + $('#name').val();
strURL += '&snmp_query_id=' + $('#snmp_query_id').val();
strURL += '&header=false';
loadPageNoHeader(strURL);
}
function applySNMPQueryTypeChange() {
strURL = 'automation_graph_rules.php?action=qedit'
strURL += '&id=' + $('#id').val();
strURL += '&name=' + $('#name').val();
strURL += '&graph_type_id=' + $('#graph_type_id').val();
strURL += '&header=false';
loadPageNoHeader(strURL);
}
</script>
<?php
}
function automation_graph_rules() {
global $automation_graph_rules_actions, $config, $item_rows;
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'name',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
),
'status' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'snmp_query_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => ''
)
);
validate_store_request_vars($filters, 'sess_autom_gr');
/* ================= input validation ================= */
if (get_request_var('rows') == -1) {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
if ((!empty($_SESSION['sess_autom_gr_status'])) && (!isempty_request_var('status'))) {
if ($_SESSION['sess_autom_gr_status'] != get_nfilter_request_var('status')) {
set_request_var('page', 1);
}
}
html_start_box(__('Graph Rules'), '100%', '', '3', 'center', 'automation_graph_rules.php?action=edit');
?>
<tr class='even'>
<td>
<form id='form_automation' action='automation_graph_rules.php'>
<table class='filterTable'>
<tr>
<td>
<?php print __('Search');?>
</td>
<td>
<input type='text' class='ui-state-default ui-corner-all' id='filter' size='25' value='<?php print html_escape_request_var('filter');?>'>
</td>
<td>
<?php print __('Data Query');?>
</td>
<td>
<select id='snmp_query_id'>
<option value='-1'<?php print (get_request_var('snmp_query_id') == '-1' ? ' selected':'');?>><?php print __('Any');?></option>
<?php
$available_data_queries = db_fetch_assoc('SELECT DISTINCT
sq.id, sq.name
FROM automation_graph_rules AS ar
LEFT JOIN snmp_query AS sq
ON ar.snmp_query_id=sq.id
ORDER BY sq.name');
if (cacti_sizeof($available_data_queries)) {
foreach ($available_data_queries as $data_query) {
print "<option value='" . $data_query['id'] . "'" . (get_request_var('snmp_query_id') == $data_query['id'] ? ' selected':'') . '>' . $data_query['name'] . "</option>\n";
}
}
?>
</select>
</td>
<td>
<?php print __('Status');?>
</td>
<td>
<select id='status'>
<option value='-1' <?php print (get_request_var('status') == '-1' ? ' selected':'');?>><?php print __('Any');?></option>
<option value='-2' <?php print (get_request_var('status') == '-2' ? ' selected':'');?>><?php print __('Enabled');?></option>
<option value='-3' <?php print (get_request_var('status') == '-3' ? ' selected':'');?>><?php print __('Disabled');?></option>
</select>
</td>
<td>
<?php print __('Graph Rules');?>
</td>
<td>
<select id='rows'>
<option value='-1'<?php print (get_request_var('rows') == '-1' ? ' selected>':'>') . __('Default');?></option>
<?php
if (cacti_sizeof($item_rows) > 0) {
foreach ($item_rows as $key => $value) {
print "<option value='" . $key . "'" . (get_request_var('rows') == $key ? ' selected':'') . '>' . $value . "</option>\n";
}
}
?>
</select>
</td>
<td>
<span>
<input type='submit' class='ui-button ui-corner-all ui-widget' id='refresh' name='go' value='<?php print __esc('Go');?>'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='clear' value='<?php print __esc('Clear');?>'></td>
</span>
</tr>
</table>
</form>
<script type='text/javascript'>
function applyFilter() {
strURL = 'automation_graph_rules.php' +
'?status=' + $('#status').val()+
'&filter=' + $('#filter').val()+
'&rows=' + $('#rows').val()+
'&snmp_query_id=' + $('#snmp_query_id').val()+
'&header=false';
loadPageNoHeader(strURL);
}
function clearFilter() {
strURL = 'automation_graph_rules.php?clear=1&header=false';
loadPageNoHeader(strURL);
}
$(function() {
$('#refresh, #rules, #rows, #status, #snmp_query_id').change(function() {
applyFilter();
});
$('#clear').click(function() {
clearFilter();
});
$('#form_automation').submit(function(event) {
event.preventDefault();
applyFilter();
});
});
</script>
</td>
</tr>
<?php
html_end_box();
/* form the 'where' clause for our main sql query */
if (get_request_var('filter') != '') {
$sql_where = 'WHERE (agr.name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'sqg.name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'sq.name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')';
} else {
$sql_where = '';
}
if (get_request_var('status') == '-1') {
/* Show all items */
} elseif (get_request_var('status') == '-2') {
$sql_where .= ($sql_where != '' ? " and agr.enabled='on'" : "where agr.enabled='on'");
} elseif (get_request_var('status') == '-3') {
$sql_where .= ($sql_where != '' ? " and agr.enabled=''" : "where agr.enabled=''");
}
if (get_request_var('snmp_query_id') == '-1') {
/* show all items */
} elseif (!isempty_request_var('snmp_query_id')) {
$sql_where .= ($sql_where != '' ? ' AND ' : ' WHERE ');
$sql_where .= 'agr.snmp_query_id=' . get_request_var('snmp_query_id');
}
$total_rows = db_fetch_cell("SELECT
COUNT(agr.id)
FROM automation_graph_rules AS agr
LEFT JOIN snmp_query AS sq
ON (agr.snmp_query_id=sq.id)
$sql_where");
$sql_order = get_order_string();
$sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows;
$automation_graph_rules_list = db_fetch_assoc("SELECT agr.id, agr.name, agr.snmp_query_id, agr.graph_type_id,
agr.enabled, sq.name AS snmp_query_name, sqg.name AS graph_type_name
FROM automation_graph_rules AS agr
LEFT JOIN snmp_query AS sq
ON (agr.snmp_query_id=sq.id)
LEFT JOIN snmp_query_graph AS sqg
ON (agr.graph_type_id=sqg.id)
$sql_where
$sql_order
$sql_limit");
$nav = html_nav_bar('automation_graph_rules.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 7, __('Graph Rules'), 'page', 'main');
form_start('automation_graph_rules.php', 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array(
'name' => array('display' => __('Rule Name'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('The name of this rule.')),
'id' => array('display' => __('ID'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The internal database ID for this rule. Useful in performing debugging and automation.')),
'snmp_query_name' => array('display' => __('Data Query'), 'align' => 'left', 'sort' => 'ASC'),
'graph_type_name' => array('display' => __('Graph Type'), 'align' => 'left', 'sort' => 'ASC'),
'enabled' => array('display' => __('Enabled'), 'align' => 'right', 'sort' => 'ASC'),
);
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
if (cacti_sizeof($automation_graph_rules_list)) {
foreach ($automation_graph_rules_list as $automation_graph_rules) {
$snmp_query_name = ((empty($automation_graph_rules['snmp_query_name'])) ? __('None') : html_escape($automation_graph_rules['snmp_query_name']));
$graph_type_name = ((empty($automation_graph_rules['graph_type_name'])) ? __('None') : html_escape($automation_graph_rules['graph_type_name']));
form_alternate_row('line' . $automation_graph_rules['id'], true);
form_selectable_cell(filter_value($automation_graph_rules['name'], get_request_var('filter'), 'automation_graph_rules.php?action=edit&id=' . $automation_graph_rules['id'] . '&page=1'), $automation_graph_rules['id']);
form_selectable_cell($automation_graph_rules['id'], $automation_graph_rules['id'], '', 'text-align:right');
form_selectable_cell(filter_value($snmp_query_name, get_request_var('filter')), $automation_graph_rules['id']);
form_selectable_cell(filter_value($graph_type_name, get_request_var('filter')), $automation_graph_rules['id']);
form_selectable_cell($automation_graph_rules['enabled'] ? __('Enabled') : __('Disabled'), $automation_graph_rules['id'], '', 'text-align:right');
form_checkbox_cell($automation_graph_rules['name'], $automation_graph_rules['id']);
form_end_row();
}
} else {
print "<tr class='tableRow'><td colspan='" . (cacti_sizeof($display_text)+1) . "'><em>" . __('No Graph Rules Found') . "</em></td></tr>\n";
}
html_end_box(false);
if (cacti_sizeof($automation_graph_rules_list)) {
print $nav;
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($automation_graph_rules_actions);
form_end();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/whsir/cacti.git
git@gitee.com:whsir/cacti.git
whsir
cacti
cacti
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385