Overview over monitoring states in admin panel.

This commit is contained in:
baldo 2016-06-11 15:31:57 +02:00
parent eb3e0d96be
commit 4ea37d59cd
4 changed files with 126 additions and 2 deletions

View file

@ -73,7 +73,7 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest
nga.field('monitoringState').cssClasses(nodeClasses).template(function (node) { nga.field('monitoringState').cssClasses(nodeClasses).template(function (node) {
switch (node.values.monitoringState) { switch (node.values.monitoringState) {
case 'active': case 'active':
return '<i class="fa fa-check monitoring-active" title="active"></i>'; return '<i class="fa fa-heartbeat monitoring-active" title="active"></i>';
case 'pending': case 'pending':
return '<i class="fa fa-envelope monitoring-confirmation-pending" title="confirmation pending"></i>'; return '<i class="fa fa-envelope monitoring-confirmation-pending" title="confirmation pending"></i>';
@ -129,6 +129,51 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest
admin.addEntity(nodes); admin.addEntity(nodes);
function monitoringStateClasses(monitoringState) {
if (!monitoringState) {
return;
}
return;
}
var monitoringStates = nga.entity('monitoring').label('Monitoring');
monitoringStates
.listView()
.title('Monitoring')
.perPage(30)
.sortDir('ASC')
.sortField('id')
.actions([])
.batchActions([])
.exportFields([])
.fields([
nga.field('id').cssClasses(monitoringStateClasses()),
nga.field('mac').cssClasses(monitoringStateClasses()),
nga.field('state').cssClasses(monitoringStateClasses()),
nga.field('last_seen').map(formatMoment).cssClasses(monitoringStateClasses()),
nga.field('import_timestamp').map(formatMoment).cssClasses(monitoringStateClasses()),
nga.field('last_status_mail_type').cssClasses(monitoringStateClasses()),
nga.field('last_status_mail_sent').map(formatMoment).cssClasses(monitoringStateClasses()),
nga.field('created_at').map(formatMoment).cssClasses(monitoringStateClasses()),
nga.field('modified_at').map(formatMoment).cssClasses(monitoringStateClasses())
])
.filters([
nga.field('q')
.label('')
.pinned(true)
.template(
'<div class="input-group">' +
'<input type="text" ng-model="value" placeholder="Search" class="form-control"></input>' +
'<span class="input-group-addon"><i class="fa fa-search"></i></span></div>'),
])
.listActions(
'<a class="btn btn-success btn-sm" href="' + config.map.mapUrl +
'/#!v:m;n:{{entry.values.mapId}}" target="_blank"><i class="fa fa-map-o"></i> Map</a>'
)
;
admin.addEntity(monitoringStates);
function mailClasses(mail) { function mailClasses(mail) {
if (!mail) { if (!mail) {
return; return;
@ -232,6 +277,10 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest
.menu(nodes) .menu(nodes)
.icon('<i class="fa fa-dot-circle-o"></i>') .icon('<i class="fa fa-dot-circle-o"></i>')
) )
.addChild(nga
.menu(monitoringStates)
.icon('<span class="fa fa-heartbeat"></span>')
)
.addChild(nga .addChild(nga
.menu(mails) .menu(mails)
.icon('<span class="fa fa-envelope"></span>') .icon('<span class="fa fa-envelope"></span>')

View file

@ -4,6 +4,7 @@ angular.module('ffffng').factory('MonitoringResource', function (
Constraints, Constraints,
Validator, Validator,
MonitoringService, MonitoringService,
Logger,
_, _,
Strings, Strings,
Resources, Resources,
@ -12,6 +13,30 @@ angular.module('ffffng').factory('MonitoringResource', function (
var isValidToken = Validator.forConstraint(Constraints.token); var isValidToken = Validator.forConstraint(Constraints.token);
return { return {
getAll: function (req, res) {
Resources.getValidRestParams('list', req, function (err, restParams) {
if (err) {
return Resources.error(res, err);
}
return MonitoringService.getAll(
restParams,
function (err, monitoringStates, total) {
if (err) {
Logger.tag('monitoring', 'admin').error('Could not get monitoring states:', err);
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
}
res.set('X-Total-Count', total);
return Resources.success(res, _.map(monitoringStates, function (state) {
state.mapId = _.toLower(state.mac).replace(/:/g, '');
return state;
}));
}
);
});
},
confirm: function (req, res) { confirm: function (req, res) {
var data = Resources.getData(req); var data = Resources.getData(req);

View file

@ -25,6 +25,8 @@ angular.module('ffffng').factory('Router', function (
app.put('/internal/api/tasks/enable/:id', TaskResource.enable); app.put('/internal/api/tasks/enable/:id', TaskResource.enable);
app.put('/internal/api/tasks/disable/:id', TaskResource.disable); app.put('/internal/api/tasks/disable/:id', TaskResource.disable);
app.get('/internal/api/monitoring', MonitoringResource.getAll);
app.get('/internal/api/mails', MailResource.getAll); app.get('/internal/api/mails', MailResource.getAll);
app.get('/internal/api/mails/:id', MailResource.get); app.get('/internal/api/mails/:id', MailResource.get);
app.delete('/internal/api/mails/:id', MailResource.delete); app.delete('/internal/api/mails/:id', MailResource.delete);

View file

@ -15,7 +15,8 @@ angular.module('ffffng')
Strings, Strings,
UrlBuilder, UrlBuilder,
Validator, Validator,
Constraints Constraints,
Resources
) { ) {
var MONITORING_MAILS_DB_BATCH_SIZE = 50; var MONITORING_MAILS_DB_BATCH_SIZE = 50;
var MONITORING_OFFLINE_MAILS_SCHEDULE = { var MONITORING_OFFLINE_MAILS_SCHEDULE = {
@ -352,6 +353,53 @@ angular.module('ffffng')
} }
return { return {
getAll: function (restParams, callback) {
Database.get(
'SELECT count(*) AS total FROM node_state',
[],
function (err, row) {
if (err) {
return callback(err);
}
var total = row.total;
var filter = Resources.filterClause(
restParams,
'id',
[
'id',
'mac',
'state',
'last_seen',
'import_timestamp',
'last_status_mail_type',
'last_status_mail_sent',
'created_at',
'modified_at'
],
[
'mac',
'state',
'last_status_mail_type'
]
);
Database.all(
'SELECT * FROM node_state WHERE ' + filter.query,
_.concat([], filter.params),
function (err, rows) {
if (err) {
return callback(err);
}
callback(null, rows, total);
}
);
}
);
},
confirm: function (token, callback) { confirm: function (token, callback) {
NodeService.getNodeDataByMonitoringToken(token, function (err, node, nodeSecrets) { NodeService.getNodeDataByMonitoringToken(token, function (err, node, nodeSecrets) {
if (err) { if (err) {