Allow to specify nodes.json-URLs for multiple communities / domains.
This commit is contained in:
parent
e7a362b020
commit
5086d8c71f
4 changed files with 89 additions and 81 deletions
server/services
|
@ -418,6 +418,87 @@ angular.module('ffffng')
|
|||
});
|
||||
}
|
||||
|
||||
function retrieveNodeInformationForUrl(url, callback) {
|
||||
Logger.tag('monitoring', 'information-retrieval').debug('Retrieving nodes.json: %s', url);
|
||||
request(url, function (err, response, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (response.statusCode !== 200) {
|
||||
return callback(new Error(
|
||||
'Could not download nodes.json from ' + url + ': ' +
|
||||
response.statusCode + ' - ' + response.statusMessage
|
||||
));
|
||||
}
|
||||
|
||||
parseNodesJson(body, function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (previousImportTimestamp !== null && !data.importTimestamp.isAfter(previousImportTimestamp)) {
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.debug(
|
||||
'No new data, skipping. Current timestamp: %s, previous timestamp: %s',
|
||||
data.importTimestamp.format(),
|
||||
previousImportTimestamp.format()
|
||||
);
|
||||
return callback();
|
||||
}
|
||||
previousImportTimestamp = data.importTimestamp;
|
||||
|
||||
// We do not parallelize here as the sqlite will start slowing down and blocking with too many
|
||||
// parallel queries. This has resulted in blocking other requests too and thus in a major slowdonw.
|
||||
async.eachSeries(
|
||||
data.nodes,
|
||||
function (nodeData, nodeCallback) {
|
||||
Logger.tag('monitoring', 'information-retrieval').debug('Importing: %s', nodeData.mac);
|
||||
|
||||
NodeService.getNodeDataByMac(nodeData.mac, function (err, node) {
|
||||
if (err) {
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.error('Error importing: ' + nodeData.mac, err);
|
||||
return nodeCallback(err);
|
||||
}
|
||||
|
||||
if (!node) {
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.debug('Unknown node, skipping: %s', nodeData.mac);
|
||||
return nodeCallback(null);
|
||||
}
|
||||
|
||||
storeNodeInformation(nodeData, node, function (err) {
|
||||
if (err) {
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.debug('Could not update / deleting node data: %s', nodeData.mac, err);
|
||||
return nodeCallback(err);
|
||||
}
|
||||
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.debug('Updating / deleting node data done: %s', nodeData.mac);
|
||||
|
||||
nodeCallback();
|
||||
});
|
||||
});
|
||||
},
|
||||
function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
markMissingNodesAsOffline(data.nodes, callback);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
getAll: function (restParams, callback) {
|
||||
var sortFields = [
|
||||
|
@ -554,85 +635,12 @@ angular.module('ffffng')
|
|||
},
|
||||
|
||||
retrieveNodeInformation: function (callback) {
|
||||
var url = config.server.map.nodesJsonUrl;
|
||||
Logger.tag('monitoring', 'information-retrieval').debug('Retrieving nodes.json: %s', url);
|
||||
request(url, function (err, response, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var urls = config.server.map.nodesJsonUrl;
|
||||
if (_.isString(urls)) {
|
||||
urls = [urls];
|
||||
}
|
||||
|
||||
if (response.statusCode !== 200) {
|
||||
return callback(new Error(
|
||||
'Could not download nodes.json from ' + url + ': ' +
|
||||
response.statusCode + ' - ' + response.statusMessage
|
||||
));
|
||||
}
|
||||
|
||||
parseNodesJson(body, function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (previousImportTimestamp !== null && !data.importTimestamp.isAfter(previousImportTimestamp)) {
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.debug(
|
||||
'No new data, skipping. Current timestamp: %s, previous timestamp: %s',
|
||||
data.importTimestamp.format(),
|
||||
previousImportTimestamp.format()
|
||||
);
|
||||
return callback();
|
||||
}
|
||||
previousImportTimestamp = data.importTimestamp;
|
||||
|
||||
// We do not parallelize here as the sqlite will start slowing down and blocking with too many
|
||||
// parallel queries. This has resulted in blocking other requests too and thus in a major slowdonw.
|
||||
async.eachSeries(
|
||||
data.nodes,
|
||||
function (nodeData, nodeCallback) {
|
||||
Logger.tag('monitoring', 'information-retrieval').debug('Importing: %s', nodeData.mac);
|
||||
|
||||
NodeService.getNodeDataByMac(nodeData.mac, function (err, node) {
|
||||
if (err) {
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.error('Error importing: ' + nodeData.mac, err);
|
||||
return nodeCallback(err);
|
||||
}
|
||||
|
||||
if (!node) {
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.debug('Unknown node, skipping: %s', nodeData.mac);
|
||||
return nodeCallback(null);
|
||||
}
|
||||
|
||||
storeNodeInformation(nodeData, node, function (err) {
|
||||
if (err) {
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.debug('Could not update / deleting node data: %s', nodeData.mac, err);
|
||||
return nodeCallback(err);
|
||||
}
|
||||
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.debug('Updating / deleting node data done: %s', nodeData.mac);
|
||||
|
||||
nodeCallback();
|
||||
});
|
||||
});
|
||||
},
|
||||
function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
markMissingNodesAsOffline(data.nodes, callback);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
async.eachSeries(urls, retrieveNodeInformationForUrl, callback);
|
||||
},
|
||||
|
||||
sendMonitoringMails: function (callback) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue