1
0
mirror of https://github.com/nttgin/BGPalerter.git synced 2024-05-19 06:50:08 +00:00

small fix to showPaths option + option to detect disconnections in ris

This commit is contained in:
Massimo Candela
2020-01-23 03:20:09 +01:00
parent 6d962a1ff5
commit 902ac859d1
4 changed files with 42 additions and 23 deletions

View File

@@ -107,10 +107,12 @@ export default class ConnectorFactory {
resolve(true);
})
.catch((error) => {
if (error) {
env.logger.log({
level: 'error',
message: error
});
}
resolve(false);
})
}))));

View File

@@ -72,6 +72,9 @@ export default class ConnectorRIS extends Connector{
};
_openConnect = (resolve) => {
if (this.connectionFailedTimer) {
clearTimeout(this.connectionFailedTimer);
}
resolve(true);
this._connect(this.name + ' connector connected');
};
@@ -87,8 +90,18 @@ export default class ConnectorRIS extends Connector{
perMessageDeflate: this.params.perMessageDeflate
});
this.connectionFailedTimer = setTimeout(() => {
this.ws.terminate();
this.ws.removeAllListeners();
this.connect();
reject("RIPE RIS connection failed. Trying again...");
}, 20000);
this.ws.on('message', this._messageToJson);
this.ws.on('close', (error) => {
if (this.connectionFailedTimer) {
clearTimeout(this.connectionFailedTimer);
}
this._close("RIPE RIS disconnected (error: " + error + "). Read more at https://github.com/nttgin/BGPalerter/blob/master/docs/ris-disconnections.md");
});
this.ws.on('error', this._error);

View File

@@ -78,9 +78,11 @@ export default class Report {
let matched = null;
let pathsCount = {};
let sortedPathIndex = null;
let sortedPathIndex;
if (this.params.showPaths > 0) {
content.data
.filter(i => !!i.matchedMessage && !!i.matchedMessage.path)
.map(i => JSON.stringify(i.matchedMessage.path.getValues().slice(1)))
.forEach(path => {
if (!pathsCount[path]) {
@@ -93,15 +95,17 @@ export default class Report {
.map(key => [key, pathsCount[key]]);
sortedPathIndex.sort((first, second) => second[1] - first[1]);
context.pathNumber = (this.params.showPaths > 0) ? Math.min(this.params.showPaths, sortedPathIndex.length) : "";
context.paths = (this.params.showPaths > 0) ? sortedPathIndex
context.pathNumber = Math.min(this.params.showPaths, sortedPathIndex.length);
context.paths = sortedPathIndex
.slice(0, this.params.showPaths)
.map(i => i[0]).join("\n") : "Disabled";
.map(i => i[0]).join("\n");
} else {
context.pathNumber = "";
context.paths = "Disabled";
}
switch(channel){
case "hijack":
matched = content.data[0].matchedRule;
context.prefix = matched.prefix;
context.description = matched.description;