(rrd) add configd "systemhealth flush" command, add flush single report. closes https://github.com/opnsense/core/issues/984

This commit is contained in:
Ad Schellevis 2016-07-24 12:54:38 +02:00
parent 768d5e8113
commit b7657a6fdf
4 changed files with 123 additions and 9 deletions

View File

@ -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}))

View File

@ -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):

View File

@ -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

View File

@ -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);
}
?>
<section class="col-xs-12">
<form method="post" name="iform" id="iform">
<input type="hidden" id="action" name="action" value="" />
<form method="post" name="iform" id="iform">
<input type="hidden" id="action" name="action" value="" />
<input type="hidden" id="filename" name="filename" value="" />
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12 __mb">
<div class="table-responsive">
<table class="table table-striped opnsense_standard_table_form">
@ -128,8 +155,42 @@ $(document).ready(function() {
</table>
</div>
</div>
</form>
</section>
</section>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12 __mb">
<div class="table-responsive">
<table class="table table-striped opnsense_standard_table_form">
<tr>
<td colspan="2"><strong><?=gettext('Collected reports');?></strong></td>
</tr>
<tr>
<td width="22%"><i class="fa fa-info-circle text-muted"></i> <?=gettext("Reports");?> </td>
<td>
<table class="table table-condensed">
<?php
foreach ($all_rrd_files as $rrd_name => $rrd_file):?>
<tr>
<td width="22%">
<button class="act_flush btn btn-default btn-xs"
title="<?=gettext("flush report");?>" data-toggle="tooltip"
data-id="<?=$rrd_file['filename'];?>">
<span class="fa fa-trash text-muted"></span>
</button>
<?=$rrd_name;?>
</td>
<td>
</td>
</tr>
<?php
endforeach;?>
</table>
</td>
</tr>
</table>
</div>
</div>
</section>
</form>
</div>
</div>
</section>