Skip to content

Commit c0d0ee8

Browse files
fixed ambiguity on neighbor monitoring activation
1 parent c64848c commit c0d0ee8

File tree

4 files changed

+20
-35
lines changed

4 files changed

+20
-35
lines changed

src/monitors/monitorAS.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Monitor from "./monitor";
3434

3535
export default class MonitorAS extends Monitor {
3636

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

4848
filter = (message) => {
49-
return message.type === 'announcement';
49+
return message.type === "announcement";
5050
};
5151

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

6969
if (prefixesOut.length > 1) {
70-
return `${matchedMessages[0].originAS} is announcing some prefixes which are not in the configured list of announced prefixes: ${prefixesOut}`
70+
return `${matchedMessages[0].originAS} is announcing some prefixes which are not in the configured list of announced prefixes: ${prefixesOut}`;
7171
} else if (prefixesOut.length === 1) {
7272
return `${matchedMessages[0].originAS} is announcing ${matchedMessages[0].prefix} but this prefix is not in the configured list of announced prefixes`;
7373
}

src/monitors/monitorPathNeighbors.js

+11-23
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Monitor from "./monitor";
3434

3535
export default class MonitorPathNeighbors extends Monitor {
3636

37-
constructor(name, channel, params, env, input){
37+
constructor(name, channel, params, env, input) {
3838
super(name, channel, params, env, input);
3939
this.thresholdMinPeers = params?.thresholdMinPeers ?? 0;
4040
this.updateMonitoredResources();
@@ -45,7 +45,7 @@ export default class MonitorPathNeighbors extends Monitor {
4545
};
4646

4747
filter = (message) => {
48-
return message.type === 'announcement';
48+
return message.type === "announcement";
4949
};
5050

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

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

7373
if (!!left || !!right) {
7474
let match = false;
7575
let side = null;
7676
let id = null;
7777

78-
if (left) {
79-
if (monitoredAs.upstreams === null) {
80-
side = "upstream";
81-
id = left.getId();
82-
match = true;
83-
} else if (monitoredAs.upstreams && !monitoredAs.upstreams.includes(left)) {
84-
side = "upstream";
85-
id = left.getId();
86-
match = true;
87-
}
78+
if (left && (monitoredAs.upstreams !== undefined && !monitoredAs.upstreams?.includes(left))) {
79+
side = "upstream";
80+
id = left.getId();
81+
match = true;
8882
}
8983

90-
if (right) {
91-
if (monitoredAs.downstreams === null) {
92-
side = "downstream";
93-
id = right.getId();
94-
match = true;
95-
} else if (monitoredAs.downstreams && !monitoredAs.downstreams.includes(right)) {
96-
side = "downstream";
97-
id = right.getId();
98-
match = true;
99-
}
84+
if (right && (monitoredAs.downstreams !== undefined && !monitoredAs.downstreams?.includes(right))) {
85+
side = "downstream";
86+
id = right.getId();
87+
match = true;
10088
}
10189

10290

tests/neighbor_tests/prefixes.test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
options:
1212
monitorASns:
1313
101:
14-
groupd: default
14+
group: default
1515
upstreams:
1616
- 100
1717
downstreams:
1818
- 104
1919
80:
20-
groupd: default
20+
group: default
2121
upstreams:
2222
- 99
2323
downstreams:

tests/neighbor_tests/tests.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
const chai = require("chai");
3434
const fs = require("fs");
35-
const chaiSubset = require('chai-subset');
35+
const chaiSubset = require("chai-subset");
3636
chai.use(chaiSubset);
3737
const expect = chai.expect;
3838
const volume = "volumetests/";
@@ -42,10 +42,10 @@ global.EXTERNAL_CONFIG_FILE = volume + "config.test.yml";
4242

4343
// Prepare test environment
4444
if (!fs.existsSync(volume)) {
45-
fs.mkdirSync(volume, { recursive: true });
45+
fs.mkdirSync(volume, {recursive: true});
4646
} else {
47-
fs.rmdirSync(volume, { recursive: true });
48-
fs.mkdirSync(volume, { recursive: true });
47+
fs.rmdirSync(volume, {recursive: true});
48+
fs.mkdirSync(volume, {recursive: true});
4949
}
5050
fs.copyFileSync("tests/neighbor_tests/config.test.yml", volume + "config.test.yml");
5151
fs.copyFileSync("tests/neighbor_tests/prefixes.test.yml", volume + "prefixes.test.yml");
@@ -71,7 +71,6 @@ describe("Alerting", function () {
7171
"matchedRule": {
7272
"asn": [101],
7373
"group": ["default"],
74-
"groupd": "default",
7574
"upstreams": [100],
7675
"downstreams": [104]
7776
},
@@ -100,7 +99,6 @@ describe("Alerting", function () {
10099
"matchedRule": {
101100
"asn": [80],
102101
"group": ["default"],
103-
"groupd": "default",
104102
"upstreams": [99],
105103
"downstreams": null
106104
},
@@ -129,7 +127,6 @@ describe("Alerting", function () {
129127
"matchedRule": {
130128
"asn": [101],
131129
"group": ["default"],
132-
"groupd": "default",
133130
"upstreams": [100],
134131
"downstreams": [104]
135132
},

0 commit comments

Comments
 (0)