mirror of
https://github.com/nttgin/BGPalerter.git
synced 2024-05-19 06:50:08 +00:00
fixed missing rpki metadata and fixed tests
This commit is contained in:
5
.github/workflows/main.yml
vendored
5
.github/workflows/main.yml
vendored
@@ -80,10 +80,7 @@ jobs:
|
||||
|
||||
- name: Tests RPKI
|
||||
run: |
|
||||
rm -f -R .cache/
|
||||
./node_modules/.bin/mocha --exit tests/rpki_tests/tests.default.js --require @babel/register
|
||||
./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external.js --require @babel/register
|
||||
rm -f -R .cache/ && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external-roas.js --require @babel/register
|
||||
npm run test-rpki
|
||||
|
||||
- name: Tests Proxy
|
||||
run: |
|
||||
|
@@ -15,7 +15,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"babel": "./node_modules/.bin/babel",
|
||||
"test": "npm run test-core && npm run test-generate && npm run test-reports && npm run test-rpki && npm run test-neighbor",
|
||||
"test": "rm -rf .cache/ && npm run test-core && npm run test-generate && npm run test-reports && npm run test-rpki && npm run test-neighbor",
|
||||
"test-core": "rm -rf volumetests/ && ./node_modules/.bin/mocha --exit tests/*.js --require @babel/register && rm -rf volumetests/",
|
||||
"test-reports": "./node_modules/.bin/mocha --exit tests/reports_tests/testReportSyslog.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/reports_tests/testsReportHttp.js --require @babel/register",
|
||||
"test-proxy": "./node_modules/.bin/mocha --exit tests/proxy_tests/*.js --require @babel/register",
|
||||
@@ -24,7 +24,7 @@
|
||||
"test-neighbor": "./node_modules/.bin/mocha --exit tests/neighbor_tests/*.js --require @babel/register",
|
||||
"test-npm": "./node_modules/.bin/mocha --exit tests/npm_tests/*.js --require @babel/register",
|
||||
"test-dump": "rm -rf volumetests/ && ./node_modules/.bin/mocha --exit tests/dump_tests/*.js --require @babel/register",
|
||||
"test-rpki": "./node_modules/.bin/mocha --exit tests/rpki_tests/tests.default.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external-missing-roas.js --require @babel/register && rm -f -R .cache/ && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external-roas.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.api.js --require @babel/register",
|
||||
"test-rpki": "rm -f -R .cache/ && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.default.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external-missing-roas.js --require @babel/register && rm -f -R .cache/ && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external-roas.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.api.js --require @babel/register",
|
||||
"build": "./build.sh",
|
||||
"compile": "rm -rf dist/ && ./node_modules/.bin/babel index.js -d dist && ./node_modules/.bin/babel src -d dist/src && cp package.json dist/package.json && cp README.md dist/README.md && cp .npm* dist/",
|
||||
"serve": "babel-node index.js",
|
||||
|
@@ -35,14 +35,19 @@ export default class MonitorROAS extends Monitor {
|
||||
setInterval(this._diffVrps, 30 * 1000);
|
||||
}
|
||||
if (this.enableExpirationAlerts || this.enableExpirationCheckTA) {
|
||||
setInterval(() => {
|
||||
|
||||
(global.EXTERNAL_ROA_EXPIRATION_TEST ? setTimeout : setInterval)(() => {
|
||||
this.rpki._getVrpIndex()
|
||||
.then(index => {
|
||||
this._verifyExpiration(index, this.roaExpirationAlertHours);
|
||||
this._verifyExpiration(index, this.roaExpirationAlertHours); // Verify expiration with enrichment
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
this._verifyExpiration(null, 2, false);
|
||||
.catch((error) => {
|
||||
this.logger.log({
|
||||
level: 'error',
|
||||
message: error
|
||||
});
|
||||
|
||||
this._verifyExpiration(null, this.roaExpirationAlertHours); // Verify expiration without enrichment
|
||||
});
|
||||
}, global.EXTERNAL_ROA_EXPIRATION_TEST || 600000);
|
||||
}
|
||||
@@ -66,24 +71,28 @@ export default class MonitorROAS extends Monitor {
|
||||
|
||||
_checkDeletedRoasTAs = (vrps) => {
|
||||
const sizes = this._calculateSizes(vrps);
|
||||
const metadata = this.rpki.getMetadata();
|
||||
|
||||
for (let ta in sizes) {
|
||||
if (this.timesDeletedTAs[ta]) {
|
||||
const min = Math.min(this.timesDeletedTAs[ta], sizes[ta]);
|
||||
const max = Math.max(this.timesDeletedTAs[ta], sizes[ta]);
|
||||
const diff = max - min;
|
||||
const percentage = 100 / max * diff;
|
||||
const oldSize = this.timesDeletedTAs[ta];
|
||||
const newSize = sizes[ta];
|
||||
|
||||
if (percentage > this.toleranceDeletedRoasTA) {
|
||||
const message = `Possible TA malfunction or incomplete VRP file: ${percentage.toFixed(2)}% of the ROAs disappeared from ${ta}`;
|
||||
if (oldSize > newSize) {
|
||||
const min = Math.min(newSize, oldSize);
|
||||
const max = Math.max(newSize, oldSize);
|
||||
const diff = max - min;
|
||||
const percentage = 100 / max * diff;
|
||||
|
||||
this.publishAlert(`disappeared-${ta}`, // The hash will prevent alert duplications in case multiple ASes/prefixes are involved
|
||||
ta,
|
||||
{
|
||||
group: "default"
|
||||
},
|
||||
message,
|
||||
{subType: "ta-malfunction"});
|
||||
if (percentage > this.toleranceDeletedRoasTA) {
|
||||
const message = `Possible TA malfunction or incomplete VRP file: ${percentage.toFixed(2)}% of the ROAs disappeared from ${ta}`;
|
||||
|
||||
this.publishAlert(`disappeared-${ta}`, // The hash will prevent alert duplications in case multiple ASes/prefixes are involved
|
||||
ta,
|
||||
{group: "default"},
|
||||
message,
|
||||
{rpkiMetadata: metadata, subType: "ta-malfunction", vrpCountBefore: oldSize, vrpCountAfter: newSize, disappearedPercentage: percentage, ta});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,7 +119,7 @@ export default class MonitorROAS extends Monitor {
|
||||
ta,
|
||||
{group: "default"},
|
||||
message,
|
||||
extra);
|
||||
{...extra, subType: "ta-expire", expiredPercentage: percentage, ta, vrpCount: sizes[ta], expiringVrps: expiringSizes[ta]});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -191,7 +200,7 @@ export default class MonitorROAS extends Monitor {
|
||||
matchedRule.prefix,
|
||||
matchedRule,
|
||||
message,
|
||||
{...extra, rpkiMetadata: metadata, subType: "roa-expire"});
|
||||
{...extra, roaExpirationHours: roaExpirationAlertHours, rpkiMetadata: metadata, subType: "roa-expire"});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +232,7 @@ export default class MonitorROAS extends Monitor {
|
||||
matchedRule.asn.getId(),
|
||||
matchedRule,
|
||||
message,
|
||||
{...extra, rpkiMetadata: metadata, subType: "roa-expire"});
|
||||
{...extra, vrps, roaExpirationHours: roaExpirationAlertHours, rpkiMetadata: metadata, subType: "roa-expire"});
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -38,6 +38,7 @@ const fs = require('fs');
|
||||
chai.use(chaiSubset);
|
||||
const expect = chai.expect;
|
||||
const volume = "volumetests/";
|
||||
const asyncTimeout = 120000;
|
||||
|
||||
global.EXTERNAL_VERSION_FOR_TEST = "0.0.1";
|
||||
global.EXTERNAL_CONFIG_FILE = volume + "config.test.yml";
|
||||
@@ -385,7 +386,7 @@ describe("Core functions", function() {
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
}).timeout(20000);
|
||||
|
||||
it("reports logging on the right file", function (done) {
|
||||
const message = "Test message";
|
||||
@@ -403,7 +404,7 @@ describe("Core functions", function() {
|
||||
expect(lineMessage).to.equal(message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}).timeout(20000);
|
||||
|
||||
it("write pid file", function (done) {
|
||||
const file = config.pidFile;
|
||||
|
@@ -568,15 +568,19 @@ describe("Alerting", function () {
|
||||
|
||||
it("pull API alerting", function (done) {
|
||||
|
||||
axios({
|
||||
url: "http://localhost:8011/alerts/8e402e65f393ba4812df5da0db7605e9",
|
||||
responseType: "json",
|
||||
method: "GET"
|
||||
})
|
||||
.then(a => {
|
||||
expect(a.data.data[0].hash).to.equal("8e402e65f393ba4812df5da0db7605e9");
|
||||
done();
|
||||
setTimeout(() => {
|
||||
axios({
|
||||
url: "http://localhost:8011/alerts/8e402e65f393ba4812df5da0db7605e9",
|
||||
responseType: "json",
|
||||
method: "GET"
|
||||
})
|
||||
.then(a => {
|
||||
expect(a.data.data[0].hash).to.equal("8e402e65f393ba4812df5da0db7605e9");
|
||||
done();
|
||||
});
|
||||
}, 10000);
|
||||
|
||||
|
||||
}).timeout(asyncTimeout);
|
||||
});
|
||||
|
||||
|
@@ -38,7 +38,7 @@ const asyncTimeout = 200000;
|
||||
chai.use(chaiSubset);
|
||||
|
||||
global.EXTERNAL_CONFIG_FILE = "tests/rpki_tests/config.rpki.test.external-roas.yml";
|
||||
global.EXTERNAL_ROA_EXPIRATION_TEST = 5000;
|
||||
global.EXTERNAL_ROA_EXPIRATION_TEST = 10000;
|
||||
|
||||
// ROAs before
|
||||
fs.copyFileSync("tests/rpki_tests/roas.before.json", "tests/rpki_tests/roas.json");
|
||||
@@ -117,7 +117,6 @@ describe("RPKI monitoring external", function() {
|
||||
|
||||
let rpkiTestCompletedExternal = false;
|
||||
pubSub.subscribe("roa", function (message, type) {
|
||||
|
||||
try {
|
||||
if (!rpkiTestCompletedExternal) {
|
||||
message = JSON.parse(JSON.stringify(message));
|
||||
|
Reference in New Issue
Block a user