Fix: Display Last Status Mail Sent for monitoring in admin panel correctly.
Naming of column is now also consistent.
This commit is contained in:
parent
c5938d3e13
commit
0e5c5e4e1e
45
server/db/patches/004_fix_up_column_name_for_monitoring.sql
Normal file
45
server/db/patches/004_fix_up_column_name_for_monitoring.sql
Normal file
|
@ -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;
|
|
@ -34,7 +34,7 @@ angular.module('ffffng')
|
||||||
|
|
||||||
return Database.run(
|
return Database.run(
|
||||||
'INSERT INTO node_state ' +
|
'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 (?, ?, ?, ?, ?, ?)',
|
'VALUES (?, ?, ?, ?, ?, ?)',
|
||||||
[
|
[
|
||||||
node.mac,
|
node.mac,
|
||||||
|
@ -267,7 +267,7 @@ angular.module('ffffng')
|
||||||
var now = moment().unix();
|
var now = moment().unix();
|
||||||
Database.run(
|
Database.run(
|
||||||
'UPDATE node_state ' +
|
'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 = ?',
|
'WHERE id = ?',
|
||||||
[
|
[
|
||||||
now, now, mailType,
|
now, now, mailType,
|
||||||
|
@ -330,19 +330,19 @@ angular.module('ffffng')
|
||||||
var allowNull = mailNumber === 1 ? ' OR last_status_mail_type IS NULL' : '';
|
var allowNull = mailNumber === 1 ? ' OR last_status_mail_type IS NULL' : '';
|
||||||
|
|
||||||
var schedule = MONITORING_OFFLINE_MAILS_SCHEDULE[mailNumber];
|
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(
|
Database.all(
|
||||||
'SELECT * FROM node_state ' +
|
'SELECT * FROM node_state ' +
|
||||||
'WHERE modified_at < ? AND state = ? AND (last_status_mail_type = ?' + allowNull + ') AND ' +
|
'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 ?',
|
'ORDER BY id ASC LIMIT ?',
|
||||||
[
|
[
|
||||||
startTime.unix(),
|
startTime.unix(),
|
||||||
'OFFLINE',
|
'OFFLINE',
|
||||||
previousType,
|
previousType,
|
||||||
scheduleTimeBefore.unix(),
|
scheduledTimeBefore.unix(),
|
||||||
scheduleTimeBefore.unix(),
|
scheduledTimeBefore.unix(),
|
||||||
|
|
||||||
MONITORING_MAILS_DB_BATCH_SIZE
|
MONITORING_MAILS_DB_BATCH_SIZE
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue