Documents the main structure, that sends out emails for offline nodes

This commit is contained in:
rubo77 2016-07-24 13:36:56 +02:00
parent 7ab25d0491
commit 0435df2ef3

View file

@ -22,6 +22,9 @@ angular.module('ffffng')
) { ) {
var MONITORING_STATE_MACS_CHUNK_SIZE = 100; var MONITORING_STATE_MACS_CHUNK_SIZE = 100;
var MONITORING_MAILS_DB_BATCH_SIZE = 50; var MONITORING_MAILS_DB_BATCH_SIZE = 50;
/**
* Defines the intervals emails are sent if a node is offline
*/
var MONITORING_OFFLINE_MAILS_SCHEDULE = { var MONITORING_OFFLINE_MAILS_SCHEDULE = {
1: { amount: 3, unit: 'hours' }, 1: { amount: 3, unit: 'hours' },
2: { amount: 1, unit: 'days' }, 2: { amount: 1, unit: 'days' },
@ -193,20 +196,20 @@ angular.module('ffffng')
callback(null, data); callback(null, data);
} }
function updateSkippedNode(id, node, callback) { function updateSkippedNode(id, node, callback) {
Database.run( Database.run(
'UPDATE node_state ' + 'UPDATE node_state ' +
'SET hostname = ?, monitoring_state = ?, modified_at = ?' + 'SET hostname = ?, monitoring_state = ?, modified_at = ?' +
'WHERE id = ?', 'WHERE id = ?',
[ [
node ? node.hostname : '', node ? node.monitoringState : '', moment().unix(), node ? node.hostname : '', node ? node.monitoringState : '', moment().unix(),
id id
], ],
callback callback
); );
} }
function sendMonitoringMailsBatched(name, mailType, findBatchFun, callback) { function sendMonitoringMailsBatched(name, mailType, findBatchFun, callback) {
Logger.tag('monitoring', 'mail-sending').debug('Sending "%s" mails...', name); Logger.tag('monitoring', 'mail-sending').debug('Sending "%s" mails...', name);
var sendNextBatch = function (err) { var sendNextBatch = function (err) {
@ -327,11 +330,20 @@ angular.module('ffffng')
); );
} }
/**
* sends one of three mails if a node is offline
* @param {moment} startTime the moment the job started
* @param {Number} mailNumber which of three mails
* @param {Function} callback gets all nodes that are offline
*/
function sendOfflineMails(startTime, mailNumber, callback) { function sendOfflineMails(startTime, mailNumber, callback) {
sendMonitoringMailsBatched( sendMonitoringMailsBatched(
'offline ' + mailNumber, 'offline ' + mailNumber,
'monitoring-offline-' + mailNumber, 'monitoring-offline-' + mailNumber,
function (findBatchCallback) { function (findBatchCallback) {
/**
* descriptive string that stores, which was the last mail type, stored in the database as last_status_mail_type
*/
var previousType = var previousType =
mailNumber === 1 mailNumber === 1
? 'monitoring-online-again' ? 'monitoring-online-again'