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

introduced -t option to test the configuration by generating fake BGP updates

This commit is contained in:
Massimo Candela
2020-07-25 15:59:45 +02:00
parent dd5f46387e
commit 6167fbed70
6 changed files with 33 additions and 7 deletions

View File

@@ -45,6 +45,10 @@ const params = yargs
.nargs('c', 1)
.describe('c', 'Config file to load')
.alias('t', 'test')
.nargs('t', 0)
.describe('v', 'Test the configuration with fake BGP updates')
.alias('d', 'data-volume')
.nargs('d', 1)
.describe('d', 'A directory where configuration and data is persisted')
@@ -68,7 +72,6 @@ const params = yargs
.nargs('e', 1)
.describe('e', 'Comma-separated list of prefixes to exclude')
.alias('p', 'prefixes')
.nargs('p', 1)
.describe('p', 'Comma-separated list of prefixes to include')
@@ -143,6 +146,7 @@ switch(params._[0]) {
break;
default: // Run monitor
global.DRY_RUN = !!params.t;
const Worker = require("./src/worker").default;
module.exports = new Worker(params.c, params.d);
}

View File

@@ -41,6 +41,8 @@ export default class ConnectorTest extends Connector{
clearInterval(this.timer);
this.subscribe({type: message});
});
this.subscribe({type: params.testType});
}
connect = () => {

View File

@@ -172,6 +172,25 @@ if (fs.existsSync(vector.configFile)) {
})
}
if (global.DRY_RUN) {
config.connectors = [{
file: "connectorTest",
name: "tes",
params: {
testType: "hijack"
}
}];
config.monitors = [{
file: "monitorPassthrough",
channel: "hijack",
name: "monitor-passthrough",
params: {
showPaths: 0,
thresholdMinPeers: 0
}
}];
}
config.volume = config.volume || global.EXTERNAL_VOLUME_DIRECTORY || "./";
if (config.volume.slice(-1) !== "/") {
@@ -285,7 +304,6 @@ if (!!config.persistStatus) {
}, config);
}
const input = new Input(config);
vector.config = config;

View File

@@ -69,7 +69,6 @@ export default class MonitorAS extends Monitor {
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`;
}
return false;

View File

@@ -16,7 +16,8 @@ export default class monitorPassthrough extends Monitor {
};
squashAlerts = (alerts) => {
return JSON.stringify(alerts[0]);
const item = alerts[0].matchedMessage;
return `type:${item.type} timestamp:${alerts[0].timestamp} prefix:${item.prefix} peer:${item.peer} path:${item.path} nextHop:${item.nextHop} aggregator:${item.aggregator}`;
};
monitor = (message) =>
@@ -24,7 +25,11 @@ export default class monitorPassthrough extends Monitor {
const prefix = message.prefix;
this.publishAlert(this.count,
prefix,
{},
{
prefix: "0.0.0.0/0",
asn: "1234",
description: "test",
},
message,
{});

View File

@@ -66,9 +66,7 @@ export default class ReportHTTP extends Report {
if (this.params.showPaths > 0 && context.pathNumber > 0) {
context.summary = `${context.summary}. Top ${context.pathNumber} most used AS paths: ${context.paths}`;
}
const blob = this.parseTemplate(this.params.templates[channel] || this.params.templates["default"], context);
this.axios({
url: url,
method: "POST",