Skip to content

Commit

Permalink
monit: add dashboard widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Brendel authored and fichtner committed Jun 27, 2018
1 parent 74a489b commit b009984
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/www/widgets/include/monit.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

$monit_title = gettext('Monit');
$monit_title_link = 'ui/monit/status';
96 changes: 96 additions & 0 deletions src/www/widgets/widgets/monit.widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/*
Copyright (C) 2018 EURO-LOG AG
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.
*/

require_once("widgets/include/monit.inc");

?>
<link rel="stylesheet" type="text/css" href="/ui/css/jquery.bootgrid.css">
<script src="ui/js/jquery.bootgrid.js"></script>

<script>

$( document ).ready(function() {

const serviceTypes = [
"<?= gettext('Filesystem') ?>",
"<?= gettext('Directory') ?>",
"<?= gettext('File') ?>",
"<?= gettext('Process') ?>",
"<?= gettext('Host') ?>",
"<?= gettext('System') ?>",
"<?= gettext('Fifo') ?>",
"<?= gettext('Custom') ?>",
"<?= gettext('Network') ?>"
];
const statusTypes = [
"<?= gettext('OK') ?>",
"<?= gettext('Failed') ?>",
"<?= gettext('Changed') ?>",
"<?= gettext('Not changed') ?>"
];

$("#grid-monit").bootgrid({
navigation: 2,
rowCount: 7
});

function statusPoll() {
var pollInterval = 10;
ajaxCall(url="/api/monit/status/get/xml", sendData={}, callback=function(data, status) {

$("#grid-monit").bootgrid("clear");
if (data['result'] === 'ok') {
// poll is in minutes
pollInterval = data['status']['server']['poll'] * 60000;
$.each(data['status']['service'], function(index, service) {
$("#grid-monit").bootgrid("append", [{name: service['name'], type: serviceTypes[service['@attributes']['type']], status: statusTypes[service['status']]}]);
});
}
setTimeout(statusPoll, pollInterval);
});
};
statusPoll();

});

</script>

<table id="grid-monit" class="table table-condensed table-hove table-striped table-responsive bootgrid-table">
<thead>
<tr>
<th data-column-id="name"><?= gettext('Name') ?></th>
<th data-column-id="type"><?= gettext('Type') ?></th>
<th data-column-id="status"><?= gettext('Status') ?></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
</tfoot>
</table>

0 comments on commit b009984

Please sign in to comment.