diff --git a/src/opnsense/scripts/systemhealth/flush_rrd.py b/src/opnsense/scripts/systemhealth/flush_rrd.py
new file mode 100755
index 000000000..a59c09591
--- /dev/null
+++ b/src/opnsense/scripts/systemhealth/flush_rrd.py
@@ -0,0 +1,46 @@
+#!/usr/local/bin/python2.7
+
+"""
+ Copyright (c) 2016 Deciso B.V. - Ad Schellevis
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+"""
+import glob
+import os
+import sys
+import os.path
+import ujson
+
+rrd_reports_dir = '/var/db/rrd'
+
+if len(sys.argv) < 2:
+ print ("usage %s rrd_filename" % os.path.basename(sys.argv[0]))
+ sys.exit(-1)
+else:
+ flushed = list()
+ for filename in glob.glob(rrd_reports_dir+'/*.rrd'):
+ if sys.argv[1] == '*' or os.path.basename(filename) == sys.argv[1]:
+ os.remove(filename)
+ flushed.append(os.path.basename(filename))
+ print (ujson.dumps({'flushed':flushed}))
diff --git a/src/opnsense/scripts/systemhealth/listReports.py b/src/opnsense/scripts/systemhealth/listReports.py
index 91515f3e1..86892504f 100755
--- a/src/opnsense/scripts/systemhealth/listReports.py
+++ b/src/opnsense/scripts/systemhealth/listReports.py
@@ -53,7 +53,8 @@ for filename in glob.glob('%s/*.rrd' % rrd_reports_dir):
else:
topic = rrdFilename.split('-')[-1]
itemName = '-'.join(rrdFilename.split('-')[:-1])
- result[rrdFilename] = {'title': '', 'y-axis_label': '', 'field_units': {}, 'topic': topic, 'itemName': itemName}
+ result[rrdFilename] = {'title': '','y-axis_label': '', 'field_units': {},
+ 'topic': topic, 'itemName': itemName, 'filename': os.path.basename(filename)}
# scan all definition files
for filename in glob.glob('%s/*.xml' % rrd_definition_dir):
diff --git a/src/opnsense/service/conf/actions.d/actions_systemhealth.conf b/src/opnsense/service/conf/actions.d/actions_systemhealth.conf
index 956165e20..13da75251 100644
--- a/src/opnsense/service/conf/actions.d/actions_systemhealth.conf
+++ b/src/opnsense/service/conf/actions.d/actions_systemhealth.conf
@@ -9,3 +9,9 @@ command:/usr/local/opnsense/scripts/systemhealth/fetchData.py
parameters: %s
type:script_output
message:fetch systemhealth report data
+
+[flush]
+command:/usr/local/opnsense/scripts/systemhealth/flush_rrd.py
+parameters: %s
+type:script_output
+message:flush rrd data
diff --git a/src/www/reporting_settings.php b/src/www/reporting_settings.php
index 5adb4a709..5759c3910 100644
--- a/src/www/reporting_settings.php
+++ b/src/www/reporting_settings.php
@@ -39,11 +39,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array();
$pconfig['rrdenable'] = isset($config['rrd']['enable']);
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ $pconfig = $_POST;
if (!empty($_POST['action']) && $_POST['action'] == "ResetRRD") {
$savemsg = gettext('RRD data has been cleared.');
- mwexec('/bin/rm /var/db/rrd/*');
+ configd_run("systemhealth flush *");
+ } elseif (!empty($_POST['action']) && $_POST['action'] == "flush_file") {
+ $savemsg = gettext('RRD report has been cleared.');
+ configd_run("systemhealth flush ". escapeshellarg($_POST['filename']));
} else {
- $pconfig = $_POST;
$config['rrd']['enable'] = !empty($_POST['rrdenable']);
$savemsg = get_std_save_message();
write_config();
@@ -53,6 +56,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
setup_gateways_monitor();
}
+$all_rrd_files = json_decode(configd_run("systemhealth list"), true);
+ksort($all_rrd_files);
legacy_html_escape_form_data($pconfig);
include("head.inc");
@@ -68,7 +73,7 @@ $(document).ready(function() {
event.preventDefault();
BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER,
- title: "= gettext("Syslog");?>",
+ title: "= gettext("RRD");?>",
message: "=gettext('Do you really want to reset the RRD graphs? This will erase all graph data.');?>",
buttons: [{
label: "= gettext("No");?>",
@@ -83,6 +88,27 @@ $(document).ready(function() {
}]
});
});
+ $(".act_flush").click(function(event){
+ var filename = $(this).data('id');
+ event.preventDefault();
+ BootstrapDialog.show({
+ type:BootstrapDialog.TYPE_DANGER,
+ title: filename,
+ message: "=gettext('Do you really want to reset the selected graph?');?>",
+ buttons: [{
+ label: "= gettext("No");?>",
+ action: function(dialogRef) {
+ dialogRef.close();
+ }}, {
+ label: "= gettext("Yes");?>",
+ action: function(dialogRef) {
+ $("#action").val("flush_file");
+ $("#filename").val(filename);
+ $("#iform").submit()
+ }
+ }]
+ });
+ });
});
//]]>
@@ -96,9 +122,10 @@ $(document).ready(function() {
print_info_box($savemsg);
}
?>
-
-
-
+
+
+