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:
6
index.js
6
index.js
@@ -45,6 +45,10 @@ const params = yargs
|
|||||||
.nargs('c', 1)
|
.nargs('c', 1)
|
||||||
.describe('c', 'Config file to load')
|
.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')
|
.alias('d', 'data-volume')
|
||||||
.nargs('d', 1)
|
.nargs('d', 1)
|
||||||
.describe('d', 'A directory where configuration and data is persisted')
|
.describe('d', 'A directory where configuration and data is persisted')
|
||||||
@@ -68,7 +72,6 @@ const params = yargs
|
|||||||
.nargs('e', 1)
|
.nargs('e', 1)
|
||||||
.describe('e', 'Comma-separated list of prefixes to exclude')
|
.describe('e', 'Comma-separated list of prefixes to exclude')
|
||||||
|
|
||||||
|
|
||||||
.alias('p', 'prefixes')
|
.alias('p', 'prefixes')
|
||||||
.nargs('p', 1)
|
.nargs('p', 1)
|
||||||
.describe('p', 'Comma-separated list of prefixes to include')
|
.describe('p', 'Comma-separated list of prefixes to include')
|
||||||
@@ -143,6 +146,7 @@ switch(params._[0]) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default: // Run monitor
|
default: // Run monitor
|
||||||
|
global.DRY_RUN = !!params.t;
|
||||||
const Worker = require("./src/worker").default;
|
const Worker = require("./src/worker").default;
|
||||||
module.exports = new Worker(params.c, params.d);
|
module.exports = new Worker(params.c, params.d);
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,8 @@ export default class ConnectorTest extends Connector{
|
|||||||
clearInterval(this.timer);
|
clearInterval(this.timer);
|
||||||
this.subscribe({type: message});
|
this.subscribe({type: message});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.subscribe({type: params.testType});
|
||||||
}
|
}
|
||||||
|
|
||||||
connect = () => {
|
connect = () => {
|
||||||
|
20
src/env.js
20
src/env.js
@@ -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 || "./";
|
config.volume = config.volume || global.EXTERNAL_VOLUME_DIRECTORY || "./";
|
||||||
|
|
||||||
if (config.volume.slice(-1) !== "/") {
|
if (config.volume.slice(-1) !== "/") {
|
||||||
@@ -285,7 +304,6 @@ if (!!config.persistStatus) {
|
|||||||
}, config);
|
}, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const input = new Input(config);
|
const input = new Input(config);
|
||||||
|
|
||||||
vector.config = config;
|
vector.config = config;
|
||||||
|
@@ -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}`
|
return `${matchedMessages[0].originAS} is announcing some prefixes which are not in the configured list of announced prefixes: ${prefixesOut}`
|
||||||
} else if (prefixesOut.length === 1) {
|
} 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 `${matchedMessages[0].originAS} is announcing ${matchedMessages[0].prefix} but this prefix is not in the configured list of announced prefixes`;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@@ -16,7 +16,8 @@ export default class monitorPassthrough extends Monitor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
squashAlerts = (alerts) => {
|
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) =>
|
monitor = (message) =>
|
||||||
@@ -24,7 +25,11 @@ export default class monitorPassthrough extends Monitor {
|
|||||||
const prefix = message.prefix;
|
const prefix = message.prefix;
|
||||||
this.publishAlert(this.count,
|
this.publishAlert(this.count,
|
||||||
prefix,
|
prefix,
|
||||||
{},
|
{
|
||||||
|
prefix: "0.0.0.0/0",
|
||||||
|
asn: "1234",
|
||||||
|
description: "test",
|
||||||
|
},
|
||||||
message,
|
message,
|
||||||
{});
|
{});
|
||||||
|
|
||||||
|
@@ -66,9 +66,7 @@ export default class ReportHTTP extends Report {
|
|||||||
if (this.params.showPaths > 0 && context.pathNumber > 0) {
|
if (this.params.showPaths > 0 && context.pathNumber > 0) {
|
||||||
context.summary = `${context.summary}. Top ${context.pathNumber} most used AS paths: ${context.paths}`;
|
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);
|
const blob = this.parseTemplate(this.params.templates[channel] || this.params.templates["default"], context);
|
||||||
|
|
||||||
this.axios({
|
this.axios({
|
||||||
url: url,
|
url: url,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
Reference in New Issue
Block a user