Mark nodes not listed in nodes.json as offline.

This commit is contained in:
baldo 2016-07-29 21:49:03 +02:00
parent 28a1db7c83
commit d63cf55abf

View file

@ -96,10 +96,22 @@ angular.module('ffffng')
return callback(err);
}
if (_.isUndefined(row)) {
return insertNodeInformation(nodeData, node, callback);
var nodeDataForStoring;
if (nodeData === 'missing') {
nodeDataForStoring = {
mac: node.mac,
state: 'OFFLINE',
lastSeen: _.isUndefined(row) ? moment() : moment.unix(row.last_seen),
importTimestamp: moment()
};
} else {
return updateNodeInformation(nodeData, node, row, callback);
nodeDataForStoring = nodeData;
}
if (_.isUndefined(row)) {
return insertNodeInformation(nodeDataForStoring, node, callback);
} else {
return updateNodeInformation(nodeDataForStoring, node, row, callback);
}
});
}
@ -364,6 +376,32 @@ angular.module('ffffng')
);
}
function markMissingNodesAsOffline(nodes, callback) {
var knownNodes = {};
_.each(nodes, function (node) {
knownNodes[Strings.normalizeMac(node.mac)] = 1;
});
NodeService.getAllNodes(function (err, nodes) {
if (err) {
return callback(err);
}
async.eachSeries(
nodes,
function (node, nodeCallback) {
if (knownNodes[Strings.normalizeMac(node.mac)]) {
// node is known in nodes.json so it has already been handled
return nodeCallback(null);
}
storeNodeInformation('missing', node, nodeCallback);
},
callback
);
});
}
return {
getAll: function (restParams, callback) {
var sortFields = [
@ -569,7 +607,13 @@ angular.module('ffffng')
});
});
},
callback
function (err) {
if (err) {
return callback(err);
}
markMissingNodesAsOffline(data.nodes, callback);
}
);
});
});