From 88dab5743fcc52b42ee766bb555b9aca59a59b79 Mon Sep 17 00:00:00 2001 From: baldo Date: Sun, 13 Aug 2017 17:22:34 +0200 Subject: [PATCH] Add field "site" in admin panel. --- admin/js/main.js | 2 ++ server/db/patches/006_add_site.sql | 1 + server/resources/nodeResource.js | 1 + server/services/monitoringService.js | 24 ++++++++++++++++++++---- 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 server/db/patches/006_add_site.sql diff --git a/admin/js/main.js b/admin/js/main.js index e5aebfb..488b077 100644 --- a/admin/js/main.js +++ b/admin/js/main.js @@ -112,6 +112,7 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest ? '' : ''; }), + nga.field('site').map(nullable).cssClasses(nodeClasses), nga.field('coords').label('GPS').cssClasses(nodeClasses).template(function (node) { return node.values.coords ? '' @@ -238,6 +239,7 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest nga.field('id').cssClasses(monitoringStateClasses), nga.field('hostname').cssClasses(monitoringStateClasses), nga.field('mac').cssClasses(monitoringStateClasses), + nga.field('site').map(nullable).cssClasses(monitoringStateClasses), nga.field('monitoring_state').cssClasses(monitoringStateClasses).template(function (monitoringState) { switch (monitoringState.values.monitoring_state) { case 'active': diff --git a/server/db/patches/006_add_site.sql b/server/db/patches/006_add_site.sql new file mode 100644 index 0000000..380f96a --- /dev/null +++ b/server/db/patches/006_add_site.sql @@ -0,0 +1 @@ +ALTER TABLE node_state ADD COLUMN site VARCHAR(32); diff --git a/server/resources/nodeResource.js b/server/resources/nodeResource.js index a2b6898..ed70680 100644 --- a/server/resources/nodeResource.js +++ b/server/resources/nodeResource.js @@ -127,6 +127,7 @@ angular.module('ffffng').factory('NodeResource', function ( var nodeState = nodeStateByMac[node.mac]; if (nodeState) { return deepExtend({}, node, { + site: nodeState.site, onlineState: nodeState.state }); } diff --git a/server/services/monitoringService.js b/server/services/monitoringService.js index 9d460f4..bffeb02 100644 --- a/server/services/monitoringService.js +++ b/server/services/monitoringService.js @@ -44,11 +44,12 @@ angular.module('ffffng') return Database.run( 'INSERT INTO node_state ' + - '(hostname, mac, monitoring_state, state, last_seen, import_timestamp, last_status_mail_sent, last_status_mail_type) ' + - 'VALUES (?, ?, ?, ?, ?, ?, ?, ?)', + '(hostname, mac, site, monitoring_state, state, last_seen, import_timestamp, last_status_mail_sent, last_status_mail_type) ' + + 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', [ node.hostname, node.mac, + node.site, node.monitoringState, nodeData.state, nodeData.lastSeen.unix(), @@ -80,10 +81,18 @@ angular.module('ffffng') return Database.run( 'UPDATE node_state ' + - 'SET hostname = ?, monitoring_state = ?, state = ?, last_seen = ?, import_timestamp = ?, modified_at = ?' + + 'SET ' + + 'hostname = ?, ' + + 'site = ?, ' + + 'monitoring_state = ?, ' + + 'state = ?, ' + + 'last_seen = ?, ' + + 'import_timestamp = ?, ' + + 'modified_at = ? ' + 'WHERE id = ? AND mac = ?', [ node.hostname, + node.site, node.monitoringState, nodeData.state, nodeData.lastSeen.unix(), @@ -201,11 +210,17 @@ angular.module('ffffng') ); } + var site = null; + if (_.isPlainObject(nodeData.nodeinfo.system) && _.isString(nodeData.nodeinfo.system.site_code)) { + site = nodeData.nodeinfo.system.site_code; + } + return { mac: mac, importTimestamp: data.importTimestamp, state: isOnline ? 'ONLINE' : 'OFFLINE', - lastSeen: lastSeen + lastSeen: lastSeen, + site: site }; })); } @@ -533,6 +548,7 @@ angular.module('ffffng') 'id', 'hostname', 'mac', + 'site', 'monitoring_state', 'state', 'last_seen',