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

better message swuashing for monitorAS

This commit is contained in:
Massimo Candela
2019-11-28 19:14:01 +01:00
parent 1fa3f08976
commit 23b6241857
5 changed files with 47 additions and 26 deletions

View File

@@ -255,13 +255,35 @@ export default class ConnectorTest extends Connector{
{
data: {
announcements: [{
prefixes: ["2.2.2.2/22"],
prefixes: ["2.2.2.3/22"],
next_hop: "124.0.0.3"
}],
peer: "124.0.0.4",
path: [1, 2, 3, 4321, 5060, 2914]
},
type: "ris_message"
},
{
data: {
announcements: [{
prefixes: ["2.2.2.5/22"],
next_hop: "124.0.0.3"
}],
peer: "124.0.0.3",
path: [1, 2, 3, 4321, 5060, 2914]
},
type: "ris_message"
},
{
data: {
announcements: [{
prefixes: ["2.2.2.3/22"],
next_hop: "124.0.0.5"
}],
peer: "124.0.0.6",
path: [1, 2, 3, 4321, 5060, 2914]
},
type: "ris_message"
}
];
break;

View File

@@ -49,9 +49,25 @@ export default class MonitorAS extends Monitor {
};
squashAlerts = (alerts) => {
const peers = [...new Set(alerts.map(alert => alert.matchedMessage.peer))].length;
const matchedMessages = alerts.map(alert => alert.matchedMessage);
const matchPerPrefix = {};
const prefixesOut = [];
if (peers >= this.thresholdMinPeers) {
for (let m of matchedMessages) { // Get the number of peers that triggered the alert for each prefix
matchPerPrefix[m.prefix] = matchPerPrefix[m.prefix] || [];
matchPerPrefix[m.prefix].push(m.peer);
}
for (let p in matchPerPrefix) { // Check if any of the prefixes went above the thresholdMinPeers
const peers = [...new Set(matchPerPrefix[p])];
if (peers.length >= this.thresholdMinPeers) {
prefixesOut.push(p);
}
}
if (prefixesOut.length > 1) {
return `${matchedMessages[0].originAS} is announcing some prefixes which are not in the configured list of announced prefixes: ${prefixesOut}`
} else if (prefixesOut.length === 1) {
return alerts[0].message;
}
@@ -71,7 +87,7 @@ export default class MonitorAS extends Monitor {
if (!matchedPrefixRule) {
const text = `${messageOrigin} is announcing ${messagePrefix} but this prefix is not in the configured list of announced prefixes`;
this.publishAlert(messageOrigin.getId() + "-" + messagePrefix,
this.publishAlert(messageOrigin.getId().toString(),
text,
messageOrigin.getId(),
matchedRule,

View File

@@ -138,7 +138,7 @@ describe("Composition", function() {
"channel": "misconfiguration",
"name": "asn-monitor",
"params": {
"thresholdMinPeers": 0
"thresholdMinPeers": 2
}
});

View File

@@ -465,28 +465,11 @@ describe("Alerting", function () {
pubSub.publish("test-type", "misconfiguration");
const expectedData = {
"2914-2.2.2.2/22": {
id: '2914-2.2.2.2/22',
"2914": {
id: '2914',
origin: 'asn-monitor',
affected: 2914,
message: 'AS2914 is announcing 2.2.2.2/22 but this prefix is not in the configured list of announced prefixes',
data: [
{
extra: {},
matchedRule: {
group: 'default',
asn: [2914],
},
matchedMessage: {
type: 'announcement',
prefix: '2.2.2.2/22',
peer: '124.0.0.3',
path: [1, 2, 3, 4321, 5060, 2914],
originAS: [2914],
nextHop: '124.0.0.3'
}
}
]
message: 'AS2914 is announcing 2.2.2.3/22 but this prefix is not in the configured list of announced prefixes',
}
};

View File

@@ -35,7 +35,7 @@ monitors:
channel: misconfiguration
name: asn-monitor
params:
thresholdMinPeers: 0
thresholdMinPeers: 2
reports:
- file: reportFile