1<?php 2/* 3 +-------------------------------------------------------------------------+ 4 | Copyright (C) 2004-2021 The Cacti Group | 5 | | 6 | This program is free software; you can redistribute it and/or | 7 | modify it under the terms of the GNU General Public License | 8 | as published by the Free Software Foundation; either version 2 | 9 | of the License, or (at your option) any later version. | 10 | | 11 | This program is distributed in the hope that it will be useful, | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | GNU General Public License for more details. | 15 +-------------------------------------------------------------------------+ 16 | Cacti: The Complete RRDtool-based Graphing Solution | 17 +-------------------------------------------------------------------------+ 18 | This code is designed, written, and maintained by the Cacti Group. See | 19 | about.php and/or the AUTHORS file for specific developer information. | 20 +-------------------------------------------------------------------------+ 21 | http://www.cacti.net/ | 22 +-------------------------------------------------------------------------+ 23*/ 24 25include('./include/auth.php'); 26include_once($config['base_path'] . '/lib/spikekill.php'); 27 28$debug = false; 29 30if (isset_request_var('method')) { 31 switch(get_nfilter_request_var('method')) { 32 case 'stddev': 33 case 'float': 34 case 'variance': 35 case 'fill': 36 break; 37 default: 38 print __("FATAL: Spike Kill method '%s' is Invalid", html_escape(get_nfilter_request_var('method'))) . PHP_EOL; 39 exit(1); 40 break; 41 } 42} 43 44if (is_realm_allowed(1043)) { 45 $local_data_ids = db_fetch_assoc_prepared('SELECT DISTINCT data_template_rrd.local_data_id 46 FROM graph_templates_item 47 LEFT JOIN data_template_rrd 48 ON graph_templates_item.task_item_id=data_template_rrd.id 49 WHERE graph_templates_item.local_graph_id = ?', 50 array(get_filter_request_var('local_graph_id'))); 51 52 $results = ''; 53 if (cacti_sizeof($local_data_ids)) { 54 foreach($local_data_ids as $local_data_id) { 55 $data_source_path = get_data_source_path($local_data_id['local_data_id'], true); 56 57 if ($data_source_path != '') { 58 $html = true; 59 $dryrun = false; 60 $out_start = ''; 61 $out_end = ''; 62 $avgnan = ''; 63 $method = ''; 64 $rrdfile = $data_source_path; 65 66 if (isset_request_var('dryrun')) { 67 $dryrun = true; 68 } 69 70 if (isset_request_var('method')) { 71 $method = get_nfilter_request_var('method'); 72 } 73 74 if (isset_request_var('avgnan')) { 75 $avgnan = get_nfilter_request_var('avgnan'); 76 } 77 78 if (isset_request_var('outlier-start')) { 79 $out_start = get_nfilter_request_var('outlier-start'); 80 } 81 82 if (isset_request_var('outlier-end')) { 83 $out_end = get_nfilter_request_var('outlier-end'); 84 } 85 86 $spiker = new spikekill($rrdfile, $method, $avgnan, '', $out_start, $out_end); 87 88 $spiker->dryrun = $dryrun; 89 $spiker->html = $html; 90 91 $result = $spiker->remove_spikes(); 92 93 if ($debug) { 94 if (!$result) { 95 cacti_log("ERROR: SpikeKill failed for $rrdfile. Message is " . $spiker->get_errors(), false, 'SPIKEKILL'); 96 } else { 97 cacti_log("NOTICE: SpikeKill succeeded for $rrdfile. Message is " . $spiker->get_output(), false, 'SPIKEKILL'); 98 } 99 } else { 100 if (!$result) { 101 $results = $spiker->get_errors(); 102 } else { 103 $results = $spiker->get_output(); 104 } 105 } 106 } 107 } 108 } 109 110 print json_encode(array('local_graph_id' => get_request_var('local_graph_id'), 'results' => $results)); 111} else { 112 print __("FATAL: Spike Kill Not Allowed") . PHP_EOL; 113} 114 115