From 0e5c5e4e1efa38bdac554b0df89981c624db8406 Mon Sep 17 00:00:00 2001 From: baldo Date: Sat, 25 Jun 2016 14:33:51 +0200 Subject: [PATCH] Fix: Display Last Status Mail Sent for monitoring in admin panel correctly. Naming of column is now also consistent. --- .../004_fix_up_column_name_for_monitoring.sql | 45 +++++++++++++++++++ server/services/monitoringService.js | 12 ++--- 2 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 server/db/patches/004_fix_up_column_name_for_monitoring.sql diff --git a/server/db/patches/004_fix_up_column_name_for_monitoring.sql b/server/db/patches/004_fix_up_column_name_for_monitoring.sql new file mode 100644 index 0000000..ef36218 --- /dev/null +++ b/server/db/patches/004_fix_up_column_name_for_monitoring.sql @@ -0,0 +1,45 @@ +-- sqlite only supports a limited subset of ALTER TABLE, thus this workaround + +ALTER TABLE node_state RENAME TO tmp_node_state; + +CREATE TABLE node_state ( + id INTEGER PRIMARY KEY, + + mac VARCHAR(17) NOT NULL UNIQUE, + + state VARCHAR(10) NOT NULL, + last_seen DATETIME NOT NULL, + + import_timestamp DATETIME NOT NULL, + + last_status_mail_sent DATETIME, + last_status_mail_type VARCHAR(20), + + created_at DATETIME DEFAULT (strftime('%s','now')) NOT NULL, + modified_at DATETIME DEFAULT (strftime('%s','now')) NOT NULL +); + +INSERT INTO node_state( + id, + mac, + state, + last_seen, + import_timestamp, + last_status_mail_sent, + last_status_mail_type, + created_at, + modified_at +) +SELECT + id, + mac, + state, + last_seen, + import_timestamp, + last_status_mail_send, + last_status_mail_type, + created_at, + modified_at +FROM tmp_node_state; + +DROP TABLE tmp_node_state; diff --git a/server/services/monitoringService.js b/server/services/monitoringService.js index cfdd5e0..d2be71c 100644 --- a/server/services/monitoringService.js +++ b/server/services/monitoringService.js @@ -34,7 +34,7 @@ angular.module('ffffng') return Database.run( 'INSERT INTO node_state ' + - '(mac, state, last_seen, import_timestamp, last_status_mail_send, last_status_mail_type) ' + + '(mac, state, last_seen, import_timestamp, last_status_mail_sent, last_status_mail_type) ' + 'VALUES (?, ?, ?, ?, ?, ?)', [ node.mac, @@ -267,7 +267,7 @@ angular.module('ffffng') var now = moment().unix(); Database.run( 'UPDATE node_state ' + - 'SET modified_at = ?, last_status_mail_send = ?, last_status_mail_type = ?' + + 'SET modified_at = ?, last_status_mail_sent = ?, last_status_mail_type = ?' + 'WHERE id = ?', [ now, now, mailType, @@ -330,19 +330,19 @@ angular.module('ffffng') var allowNull = mailNumber === 1 ? ' OR last_status_mail_type IS NULL' : ''; var schedule = MONITORING_OFFLINE_MAILS_SCHEDULE[mailNumber]; - var scheduleTimeBefore = moment().subtract(schedule.amount, schedule.unit); + var scheduledTimeBefore = moment().subtract(schedule.amount, schedule.unit); Database.all( 'SELECT * FROM node_state ' + 'WHERE modified_at < ? AND state = ? AND (last_status_mail_type = ?' + allowNull + ') AND ' + - 'last_seen <= ? AND last_status_mail_send <= ? ' + + 'last_seen <= ? AND last_status_mail_sent <= ? ' + 'ORDER BY id ASC LIMIT ?', [ startTime.unix(), 'OFFLINE', previousType, - scheduleTimeBefore.unix(), - scheduleTimeBefore.unix(), + scheduledTimeBefore.unix(), + scheduledTimeBefore.unix(), MONITORING_MAILS_DB_BATCH_SIZE ],