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

tests coverate for monitorAS

This commit is contained in:
Massimo Candela
2019-11-28 15:49:06 +01:00
parent f5996819ad
commit 464a219f4d
4 changed files with 87 additions and 2 deletions

View File

@@ -95,7 +95,7 @@ describe("Composition", function() {
it("loading monitors", function () { it("loading monitors", function () {
expect(config.monitors.length).to.equal(5); expect(config.monitors.length).to.equal(6);
expect(config.monitors[0]).to expect(config.monitors[0]).to
.containSubset({ .containSubset({
@@ -133,6 +133,15 @@ describe("Composition", function() {
} }
}); });
expect(config.monitors[4]).to
.containSubset({
"channel": "misconfiguration",
"name": "asn-monitor",
"params": {
"thresholdMinPeers": 0
}
});
expect(config.monitors[config.monitors.length - 1]).to expect(config.monitors[config.monitors.length - 1]).to
.containSubset({ .containSubset({
"channel": "software-update", "channel": "software-update",
@@ -140,6 +149,7 @@ describe("Composition", function() {
"params": undefined "params": undefined
}); });
expect(config.monitors[0]).to.have expect(config.monitors[0]).to.have
.property('class') .property('class')
}); });
@@ -170,6 +180,7 @@ describe("Composition", function() {
it("loading prefixes", function () { it("loading prefixes", function () {
expect(input.prefixes.length).to.equal(12); expect(input.prefixes.length).to.equal(12);
expect(JSON.parse(JSON.stringify(input))).to expect(JSON.parse(JSON.stringify(input))).to
.containSubset({ .containSubset({
"prefixes": [ "prefixes": [
@@ -266,6 +277,7 @@ describe("Composition", function() {
] ]
}); });
expect(input.asns.length).to.equal(2);
}); });
}); });

View File

@@ -439,6 +439,65 @@ describe("Alerting", function () {
expect(Object.keys(expectedData).includes(id)).to.equal(true); expect(Object.keys(expectedData).includes(id)).to.equal(true);
expect(expectedData[id] != null).to.equal(true); expect(expectedData[id] != null).to.equal(true);
expect(message).to
.containSubset(expectedData[id]);
expect(message).to.contain
.keys([
"latest",
"earliest"
]);
delete expectedData[id];
if (Object.keys(expectedData).length === 0){
done();
}
});
}).timeout(asyncTimeout);
it("asn monitoring reporting", function (done) {
pubSub.publish("test-type", "misconfiguration");
const expectedData = {
"2914-2.2.2.2/22": {
id: '2914-2.2.2.2/22',
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'
}
}
]
}
};
pubSub.subscribe("misconfiguration", function (type, message) {
message = JSON.parse(JSON.stringify(message));
const id = message.id;
expect(Object.keys(expectedData).includes(id)).to.equal(true);
expect(expectedData[id] != null).to.equal(true);
expect(message).to expect(message).to
.containSubset(expectedData[id]); .containSubset(expectedData[id]);

View File

@@ -31,6 +31,12 @@ monitors:
params: params:
thresholdMinPeers: 0 thresholdMinPeers: 0
- file: monitorAS
channel: misconfiguration
name: asn-monitor
params:
thresholdMinPeers: 0
reports: reports:
- file: reportFile - file: reportFile
channels: channels:
@@ -38,6 +44,7 @@ reports:
- newprefix - newprefix
- visibility - visibility
- path - path
- misconfiguration
notificationIntervalSeconds: 1800 # Repeat the same alert (which keeps being triggered) after x seconds notificationIntervalSeconds: 1800 # Repeat the same alert (which keeps being triggered) after x seconds
alertOnlyOnce: false alertOnlyOnce: false

View File

@@ -82,4 +82,11 @@
path: path:
match: ".*2914$" match: ".*2914$"
minLength: 2 minLength: 2
matchDescription: test description matchDescription: test description
options:
monitorASns:
2914:
group: default
3333:
group: default