Overview over monitoring states in admin panel.
This commit is contained in:
parent
eb3e0d96be
commit
4ea37d59cd
4 changed files with 126 additions and 2 deletions
|
@ -73,7 +73,7 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest
|
|||
nga.field('monitoringState').cssClasses(nodeClasses).template(function (node) {
|
||||
switch (node.values.monitoringState) {
|
||||
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':
|
||||
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);
|
||||
|
||||
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) {
|
||||
if (!mail) {
|
||||
return;
|
||||
|
@ -232,6 +277,10 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest
|
|||
.menu(nodes)
|
||||
.icon('<i class="fa fa-dot-circle-o"></i>')
|
||||
)
|
||||
.addChild(nga
|
||||
.menu(monitoringStates)
|
||||
.icon('<span class="fa fa-heartbeat"></span>')
|
||||
)
|
||||
.addChild(nga
|
||||
.menu(mails)
|
||||
.icon('<span class="fa fa-envelope"></span>')
|
||||
|
|
|
@ -4,6 +4,7 @@ angular.module('ffffng').factory('MonitoringResource', function (
|
|||
Constraints,
|
||||
Validator,
|
||||
MonitoringService,
|
||||
Logger,
|
||||
_,
|
||||
Strings,
|
||||
Resources,
|
||||
|
@ -12,6 +13,30 @@ angular.module('ffffng').factory('MonitoringResource', function (
|
|||
var isValidToken = Validator.forConstraint(Constraints.token);
|
||||
|
||||
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) {
|
||||
var data = Resources.getData(req);
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ angular.module('ffffng').factory('Router', function (
|
|||
app.put('/internal/api/tasks/enable/:id', TaskResource.enable);
|
||||
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/:id', MailResource.get);
|
||||
app.delete('/internal/api/mails/:id', MailResource.delete);
|
||||
|
|
|
@ -15,7 +15,8 @@ angular.module('ffffng')
|
|||
Strings,
|
||||
UrlBuilder,
|
||||
Validator,
|
||||
Constraints
|
||||
Constraints,
|
||||
Resources
|
||||
) {
|
||||
var MONITORING_MAILS_DB_BATCH_SIZE = 50;
|
||||
var MONITORING_OFFLINE_MAILS_SCHEDULE = {
|
||||
|
@ -352,6 +353,53 @@ angular.module('ffffng')
|
|||
}
|
||||
|
||||
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) {
|
||||
NodeService.getNodeDataByMonitoringToken(token, function (err, node, nodeSecrets) {
|
||||
if (err) {
|
||||
|
|
Loading…
Reference in a new issue