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

hotfix reporthttp - content of undefined on showPaths (#302)

This commit is contained in:
Massimo Candela
2020-07-23 20:56:25 +02:00
committed by GitHub
parent e7397f583f
commit da750bb3d6
10 changed files with 105 additions and 19 deletions

View File

@@ -57,7 +57,7 @@ let config = {
name: "ris",
params: {
carefulSubscription: true,
url: "wss://ris-live.ripe.net/v1/ws/",
url: "ws://ris-live.ripe.net/v1/ws/",
perMessageDeflate: true,
subscription: {
moreSpecific: true,

View File

@@ -182,9 +182,9 @@ export default class MonitorRPKI extends Monitor {
const coveringString = (covering) ? `Valid ROAs: ${covering}`: '';
if (extra.valid === null && this.params.checkUncovered) {
return `The route ${message.prefix} announced by ${message.originAS} is not covered by a ROA. Accepted with AS path: ${message.path}`;
return `The route ${message.prefix} announced by ${message.originAS} is not covered by a ROA`;
} else {
return `The route ${message.prefix} announced by ${message.originAS} is not RPKI valid. Accepted with AS path: ${message.path}. ${coveringString}`;
return `The route ${message.prefix} announced by ${message.originAS} is not RPKI valid. ${coveringString}`;
}
}
};

View File

@@ -60,18 +60,14 @@ export default class ReportHTTP extends Report {
}
}
_getMessage = (channel, content) => {
return this.parseTemplate(this.params.templates[channel] || this.params.templates["default"], this.getContext(channel, content));
};
_sendHTTPMessage = (url, channel, content) => {
content = JSON.parse(JSON.stringify(content));
if (this.params.showPaths > 0) {
content.message += `${content.message}. Top ${context.pathNumber} most used AS paths: \n ${context.paths}`;
const context = this.getContext(channel, content);
if (this.params.showPaths > 0 && context.pathNumber > 0) {
context.summary = `${context.summary}. Top ${context.pathNumber} most used AS paths: ${context.paths}`;
}
const blob = this._getMessage(channel, content);
const blob = this.parseTemplate(this.params.templates[channel] || this.params.templates["default"], context);
this.axios({
url: url,

View File

@@ -43,7 +43,7 @@ export default class reportTelegram extends ReportHTTP {
"chat_id": chatId,
"text": "${summary}",
"parse_mode": 'HTML',
"disable_web_page_preview": true,
"disable_web_page_preview": true
});
};

View File

@@ -33,7 +33,6 @@
const chai = require("chai");
const fs = require("fs");
const chaiSubset = require('chai-subset');
const Syslogd = require("syslogd");
chai.use(chaiSubset);
const expect = chai.expect;
const volume = "volumetests/";

View File

@@ -68,6 +68,22 @@ reports:
visibility: "++BGPalerter-5-${type}: ${summary}|${prefix}|${description}|${asn}|${earliest}|${latest}|${peers}"
misconfiguration: "++BGPalerter-3-${type}: ${summary}|${asn}|${prefix}|${earliest}|${latest}"
- file: reportHTTP
channels:
- hijack
- newprefix
- visibility
- path
- misconfiguration
- rpki
params:
templates: # See here how to write a template https://github.com/nttgin/BGPalerter/blob/master/docs/context.md
default: '{"text": "${summary}"}'
headers:
isTemplateJSON: true
showPaths: 5 # Amount of AS_PATHs to report in the alert
hooks:
default: http://localhost:8090/test
# The file containing the monitored prefixes. Please see monitored_prefixes_test.yml for an example
# This is an array (use new lines and dashes!)

View File

@@ -40,7 +40,7 @@ chai.use(chaiSubset);
global.EXTERNAL_VERSION_FOR_TEST = "0.0.1";
global.EXTERNAL_CONFIG_FILE = "tests/reports_tests/config.reports.test.yml";
describe("Reports", function() {
describe("Reports 1", function() {
const worker = require("../../index");
const pubSub = worker.pubSub;
@@ -62,6 +62,6 @@ describe("Reports", function() {
});
pubSub.publish("test-type", "visibility");
}).timeout(asyncTimeout);
});

View File

@@ -0,0 +1,75 @@
/*
* BSD 3-Clause License
*
* Copyright (c) 2019, NTT Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
const chai = require("chai");
const chaiSubset = require('chai-subset');
const Syslogd = require("syslogd");
const restify = require("restify");
const expect = chai.expect;
const asyncTimeout = 20000;
chai.use(chaiSubset);
const assert = chai.assert
global.EXTERNAL_VERSION_FOR_TEST = "0.0.1";
global.EXTERNAL_CONFIG_FILE = "tests/reports_tests/config.reports.test.yml";
describe("Reports 2", function() {
const worker = require("../../index");
const pubSub = worker.pubSub;
it("reportHTTP", function (done) {
const server = restify.createServer();
server.pre(restify.pre.sanitizePath());
server.use(restify.plugins.bodyParser({ mapParams: true }));
let expectedData = [
"The prefix 2a00:5884::/32 (alarig fix test) is announced by AS15563 instead of AS204092, and AS45. Top 1 most used AS paths: [2,3,15563]",
"A new prefix 2a00:5884:ffff::/48 is announced by AS208585. It should be instead 2a00:5884::/32 (alarig fix test) announced by AS204092, and AS45. Top 1 most used AS paths: [2,3,208585]",
];
pubSub.publish("test-type", "hijack");
server.post('/test', function (req, res, next) {
const text = req.body.text;
if (expectedData.includes(text)) {
expectedData = expectedData.filter(i => i !== text);
} else {
assert.fail(text, "none", "The message is not expected");
}
if (expectedData.length === 0) {
done();
}
});
server.listen(8090);
}).timeout(asyncTimeout);
});

View File

@@ -50,14 +50,14 @@ describe("RPKI monitoring 1", function() {
id: "a103_21_244_0_24-13335-false",
origin: 'rpki-monitor',
affected: '103.21.244.0/24',
message: 'The route 103.21.244.0/24 announced by AS13335 is not RPKI valid. Accepted with AS path: [1,2,3,4321,13335]. Valid ROAs: 103.21.244.0/23|AS0|maxLength:23',
message: 'The route 103.21.244.0/24 announced by AS13335 is not RPKI valid. Valid ROAs: 103.21.244.0/23|AS0|maxLength:23',
},
"a8_8_8_8_22-2914-": {
id: "a8_8_8_8_22-2914-",
origin: 'rpki-monitor',
affected: '8.8.8.8/22',
message: 'The route 8.8.8.8/22 announced by AS2914 is not covered by a ROA. Accepted with AS path: [1,2,3,4321,5060,2914]',
message: 'The route 8.8.8.8/22 announced by AS2914 is not covered by a ROA',
}
};

View File

@@ -57,7 +57,7 @@ describe("RPKI monitoring 2", function() {
id: 'a82_112_100_0_24-2914-false',
origin: 'rpki-monitor',
affected: '82.112.100.0/24',
message: 'The route 82.112.100.0/24 announced by AS2914 is not RPKI valid. Accepted with AS path: [1,2,3,4321,2914]. Valid ROAs: 82.112.100.0/24|AS1234|maxLength:24'
message: 'The route 82.112.100.0/24 announced by AS2914 is not RPKI valid. Valid ROAs: 82.112.100.0/24|AS1234|maxLength:24'
}
};