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

Introduced thresholdMinPeers to all monitors. This allows to set the number of peers that need to see the issue before to trigger an alert.

This commit is contained in:
Massimo Candela
2019-10-05 16:32:37 +02:00
parent 0be673ad29
commit 22e413ee60
7 changed files with 78 additions and 12 deletions

11
env.js
View File

@@ -70,23 +70,32 @@ let config = {
file: "monitorHijack",
channel: "hijack",
name: "basic-hijack-detection",
params: {
thresholdMinPeers: 2
}
},
{
file: "monitorPath",
channel: "path",
name: "path-matching",
params: {
thresholdMinPeers: 0
}
},
{
file: "monitorNewPrefix",
channel: "newprefix",
name: "prefix-detection",
params: {
thresholdMinPeers: 2
}
},
{
file: "monitorVisibility",
channel: "visibility",
name: "withdrawal-detection",
params: {
threshold: 10
thresholdMinPeers: 10
}
}
],

View File

@@ -36,6 +36,7 @@ export default class MonitorHijack extends Monitor {
constructor(name, channel, params, env){
super(name, channel, params, env);
this.thresholdMinPeers = (params && params.thresholdMinPeers != null) ? params.thresholdMinPeers : 2;
};
updateMonitoredPrefixes = () => {
@@ -47,7 +48,13 @@ export default class MonitorHijack extends Monitor {
};
squashAlerts = (alerts) => {
return alerts[0].message;
const peers = [...new Set(alerts.map(alert => alert.matchedMessage.peer))].length;
if (peers >= this.thresholdMinPeers) {
return alerts[0].message;
}
return false;
};
monitor = (message) =>

View File

@@ -36,6 +36,7 @@ export default class MonitorNewPrefix extends Monitor {
constructor(name, channel, params, env){
super(name, channel, params, env);
this.thresholdMinPeers = (params && params.thresholdMinPeers != null) ? params.thresholdMinPeers : 2;
this.updateMonitoredPrefixes();
};
@@ -48,7 +49,13 @@ export default class MonitorNewPrefix extends Monitor {
};
squashAlerts = (alerts) => {
return alerts[0].message;
const peers = [...new Set(alerts.map(alert => alert.matchedMessage.peer))].length;
if (peers >= this.thresholdMinPeers) {
return alerts[0].message;
}
return false;
};
monitor = (message) =>

View File

@@ -31,12 +31,12 @@
*/
import Monitor from "./monitor";
import {logger} from "../env";
export default class MonitorPath extends Monitor {
constructor(name, channel, params, env){
super(name, channel, params, env);
this.thresholdMinPeers = (params && params.thresholdMinPeers != null) ? params.thresholdMinPeers : 0;
this.updateMonitoredPrefixes();
};
@@ -50,8 +50,14 @@ export default class MonitorPath extends Monitor {
squashAlerts = (alerts) => {
alerts = alerts.filter(i => i.matchedRule && i.matchedRule.path);
const lengthViolation = (alerts.some(i => i.extra.lengthViolation)) ? "(including length violation) " : "";
return `Matched ${alerts[0].matchedRule.path.matchDescription} on prefix ${alerts[0].matchedMessage.prefix} ${lengthViolation}${alerts.length} times.`;
const peers = [...new Set(alerts.map(alert => alert.matchedMessage.peer))].length;
if (peers >= this.thresholdMinPeers) {
const lengthViolation = (alerts.some(i => i.extra.lengthViolation)) ? "(including length violation) " : "";
return `Matched ${alerts[0].matchedRule.path.matchDescription} on prefix ${alerts[0].matchedMessage.prefix} ${lengthViolation}${alerts.length} times.`;
}
return false;
};
monitor = (message) =>

View File

@@ -36,7 +36,14 @@ export default class MonitorVisibility extends Monitor {
constructor(name, channel, params, env){
super(name, channel, params, env);
this.threshold = (params.threshold != null) ? params.threshold : 10;
this.thresholdMinPeers = (params && params.thresholdMinPeers != null) ? params.thresholdMinPeers : 10;
if (params.threshold) {
this.logger.log({
level: 'error',
message: "The parameter threshold has been replaced by thresholdMinPeers and it will be soon deprecated."
});
this.thresholdMinPeers = params.threshold;
}
this.updateMonitoredPrefixes();
};
@@ -54,7 +61,7 @@ export default class MonitorVisibility extends Monitor {
squashAlerts = (alerts) => {
const peers = [...new Set(alerts.map(alert => alert.matchedMessage.peer))].length;
if (peers >= this.threshold) {
if (peers >= this.thresholdMinPeers) {
return (peers === 1) ?
`The prefix ${alerts[0].matchedMessage.prefix} (${alerts[0].matchedRule.description}) it's no longer visible (withdrawn) from the peer ${alerts[0].matchedMessage.peer}.` :
`The prefix ${alerts[0].matchedMessage.prefix} (${alerts[0].matchedRule.description}) has been withdrawn. It is no longer visible from ${peers} peers.`;

View File

@@ -10,20 +10,26 @@ monitors:
- file: monitorHijack
channel: hijack
name: basic-hijack-detection
params:
thresholdMinPeers: 0
- file: monitorNewPrefix
channel: newprefix
name: prefix-detection
params:
thresholdMinPeers: 0
- file: monitorVisibility
channel: visibility
name: withdrawal-detection
params:
threshold: 4
thresholdMinPeers: 4
- file: monitorPath
channel: path
name: path-matching
params:
thresholdMinPeers: 0
reports:
- file: reportFile

View File

@@ -79,18 +79,26 @@ describe("Tests", function() {
it("loading monitors", function () {
expect(env.config.monitors.length).to.equal(5);
expect(env.config.monitors[0]).to
.containSubset({
"channel": "hijack",
"name": "basic-hijack-detection",
"params": undefined
"params": {
"thresholdMinPeers": 0
}
});
expect(env.config.monitors[1]).to
.containSubset({
"channel": "newprefix",
"name": "prefix-detection",
"params": undefined
"params": {
"thresholdMinPeers": 0
}
});
expect(env.config.monitors[2]).to
@@ -98,10 +106,26 @@ describe("Tests", function() {
"channel": "visibility",
"name": "withdrawal-detection",
"params": {
"threshold": 4
"thresholdMinPeers": 4
}
});
expect(env.config.monitors[3]).to
.containSubset({
"channel": "path",
"name": "path-matching",
"params": {
"thresholdMinPeers": 0
}
});
expect(env.config.monitors[env.config.monitors.length - 1]).to
.containSubset({
"channel": "software-update",
"name": "software-update",
"params": undefined
});
expect(env.config.monitors[0]).to.have
.property('class')
});