Skip to content

Commit

Permalink
fixed ambiguity on neighbor monitoring activation
Browse files Browse the repository at this point in the history
  • Loading branch information
massimocandela committed Jan 4, 2025
1 parent c64848c commit c0d0ee8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/monitors/monitorAS.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Monitor from "./monitor";

export default class MonitorAS extends Monitor {

constructor(name, channel, params, env, input){
constructor(name, channel, params, env, input) {
super(name, channel, params, env, input);
this.thresholdMinPeers = params?.thresholdMinPeers ?? 3;
this.skipPrefixMatch = !!params?.skipPrefixMatch;
Expand All @@ -46,7 +46,7 @@ export default class MonitorAS extends Monitor {
};

filter = (message) => {
return message.type === 'announcement';
return message.type === "announcement";
};

squashAlerts = (alerts) => {
Expand All @@ -67,7 +67,7 @@ export default class MonitorAS extends Monitor {
}

if (prefixesOut.length > 1) {
return `${matchedMessages[0].originAS} is announcing some prefixes which are not in the configured list of announced prefixes: ${prefixesOut}`
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 `${matchedMessages[0].originAS} is announcing ${matchedMessages[0].prefix} but this prefix is not in the configured list of announced prefixes`;
}
Expand Down
34 changes: 11 additions & 23 deletions src/monitors/monitorPathNeighbors.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Monitor from "./monitor";

export default class MonitorPathNeighbors extends Monitor {

constructor(name, channel, params, env, input){
constructor(name, channel, params, env, input) {
super(name, channel, params, env, input);
this.thresholdMinPeers = params?.thresholdMinPeers ?? 0;
this.updateMonitoredResources();
Expand All @@ -45,7 +45,7 @@ export default class MonitorPathNeighbors extends Monitor {
};

filter = (message) => {
return message.type === 'announcement';
return message.type === "announcement";
};

squashAlerts = (alerts) => {
Expand All @@ -67,36 +67,24 @@ export default class MonitorPathNeighbors extends Monitor {
const path = message.path;

for (let monitoredAs of this.monitored) {
if (monitoredAs.upstreams || monitoredAs.downstreams) {
if (monitoredAs.upstreams !== undefined || monitoredAs.downstreams !== undefined) {
const [left, _, right] = path.getNeighbors(monitoredAs.asn);

if (!!left || !!right) {
let match = false;
let side = null;
let id = null;

if (left) {
if (monitoredAs.upstreams === null) {
side = "upstream";
id = left.getId();
match = true;
} else if (monitoredAs.upstreams && !monitoredAs.upstreams.includes(left)) {
side = "upstream";
id = left.getId();
match = true;
}
if (left && (monitoredAs.upstreams !== undefined && !monitoredAs.upstreams?.includes(left))) {
side = "upstream";
id = left.getId();
match = true;
}

if (right) {
if (monitoredAs.downstreams === null) {
side = "downstream";
id = right.getId();
match = true;
} else if (monitoredAs.downstreams && !monitoredAs.downstreams.includes(right)) {
side = "downstream";
id = right.getId();
match = true;
}
if (right && (monitoredAs.downstreams !== undefined && !monitoredAs.downstreams?.includes(right))) {
side = "downstream";
id = right.getId();
match = true;
}


Expand Down
4 changes: 2 additions & 2 deletions tests/neighbor_tests/prefixes.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
options:
monitorASns:
101:
groupd: default
group: default
upstreams:
- 100
downstreams:
- 104
80:
groupd: default
group: default
upstreams:
- 99
downstreams:
11 changes: 4 additions & 7 deletions tests/neighbor_tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

const chai = require("chai");
const fs = require("fs");
const chaiSubset = require('chai-subset');
const chaiSubset = require("chai-subset");
chai.use(chaiSubset);
const expect = chai.expect;
const volume = "volumetests/";
Expand All @@ -42,10 +42,10 @@ global.EXTERNAL_CONFIG_FILE = volume + "config.test.yml";

// Prepare test environment
if (!fs.existsSync(volume)) {
fs.mkdirSync(volume, { recursive: true });
fs.mkdirSync(volume, {recursive: true});
} else {
fs.rmdirSync(volume, { recursive: true });
fs.mkdirSync(volume, { recursive: true });
fs.rmdirSync(volume, {recursive: true});
fs.mkdirSync(volume, {recursive: true});
}
fs.copyFileSync("tests/neighbor_tests/config.test.yml", volume + "config.test.yml");
fs.copyFileSync("tests/neighbor_tests/prefixes.test.yml", volume + "prefixes.test.yml");
Expand All @@ -71,7 +71,6 @@ describe("Alerting", function () {
"matchedRule": {
"asn": [101],
"group": ["default"],
"groupd": "default",
"upstreams": [100],
"downstreams": [104]
},
Expand Down Expand Up @@ -100,7 +99,6 @@ describe("Alerting", function () {
"matchedRule": {
"asn": [80],
"group": ["default"],
"groupd": "default",
"upstreams": [99],
"downstreams": null
},
Expand Down Expand Up @@ -129,7 +127,6 @@ describe("Alerting", function () {
"matchedRule": {
"asn": [101],
"group": ["default"],
"groupd": "default",
"upstreams": [100],
"downstreams": [104]
},
Expand Down

0 comments on commit c0d0ee8

Please sign in to comment.