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

introduce debug mode for prefix generate + introduce historical data (#312)

This commit is contained in:
Massimo Candela
2020-07-29 19:31:16 +02:00
parent ce5b992d5a
commit 15f36cd89b
3 changed files with 48 additions and 4 deletions

View File

@@ -23,6 +23,8 @@ Below the list of possible parameters. **Remember to prepend them with a `--` in
| -s | A list of ASns to be monitored. See [monitorASns](#monitorASns) for more information | A comma separated list of integer | 2914,3333 | No |
| -m | Monitor all ASns which are origin of at least one of the monitored prefixes. This option is the same of `-s` except that the list of ASns is automatically generated by detecting the origin AS of all the monitored prefixes. See [monitorASns](#monitorASns) for more information | Nothing | | No |
| -x | HTTP/HTTPS proxy server to use | A string | http://username:password@proxy.example.org:8080 | No |
| -D | Enable debug mode. All queries executed in background will be shown. | Nothing | | No |
| -H | Use historical visibility data for generating prefix list (prefixes visible in the last week). Useful in case the prefix generation process returns an empty dataset. | Nothing | | No |
## <a name="prefixes-fields"></a>Prefixes list fields

View File

@@ -96,6 +96,14 @@ const params = yargs
.nargs('x', 1)
.describe('x', 'HTTP/HTTPS proxy to use')
.alias('D', 'debug')
.nargs('D', 0)
.describe('D', 'Provide verbose output for debugging')
.alias('H', 'historical')
.nargs('H', 0)
.describe('H', 'Use historical visibility data for generating prefix list (prefixes visible in the last week).')
.demandOption(['o']);
})
.example('$0 generate -a 2914 -o prefixes.yml', 'Generate prefixes for AS2914')
@@ -107,6 +115,8 @@ const params = yargs
switch(params._[0]) {
case "generate":
const generatePrefixes = require("./src/generatePrefixesList");
const debug = !!params.D;
const historical = !!params.H;
let prefixes = null;
let monitoredASes = false;
if (params.pf) {
@@ -140,7 +150,9 @@ switch(params._[0]) {
params.i || false,
prefixes,
monitoredASes,
params.x || null
params.x || null,
debug,
historical
);
break;

View File

@@ -5,7 +5,7 @@ import yaml from "js-yaml";
import fs from "fs";
const batchPromises = require('batch-promises');
module.exports = function generatePrefixes(asnList, outputFile, exclude, excludeDelegated, prefixes, monitoredASes, httpProxy) {
module.exports = function generatePrefixes(asnList, outputFile, exclude, excludeDelegated, prefixes, monitoredASes, httpProxy, debug, historical) {
const generateList = {};
const allOrigins = {};
let someNotValidatedPrefixes = false;
@@ -15,6 +15,10 @@ module.exports = function generatePrefixes(asnList, outputFile, exclude, exclude
axios.defaults.httpsAgent = new HttpsProxyAgent(url.parse(httpProxy));
}
if (historical) {
console.log("WARNING: you are using historical visibility data for generating the prefix list.");
}
if (!asnList && !prefixes) {
throw new Error("You need to specify at least an AS number or a list of prefixes.");
}
@@ -35,6 +39,10 @@ module.exports = function generatePrefixes(asnList, outputFile, exclude, exclude
}
});
if (debug) {
console.log("Query", url)
}
return axios({
url,
method: 'GET',
@@ -62,6 +70,10 @@ module.exports = function generatePrefixes(asnList, outputFile, exclude, exclude
}
});
if (debug) {
console.log("Query", url)
}
return axios({
url,
method: 'GET',
@@ -118,6 +130,10 @@ module.exports = function generatePrefixes(asnList, outputFile, exclude, exclude
}
});
if (debug) {
console.log("Query", url)
}
return axios({
url,
method: 'GET',
@@ -132,12 +148,22 @@ module.exports = function generatePrefixes(asnList, outputFile, exclude, exclude
.sort((a,b) => a-b)
.pop();
if (historical) {
return latest.getTime() + (3600 * 24 * 1000 * 7) > new Date().getTime();
} else {
return latest.getTime() + (3600 * 24 * 1000) > new Date().getTime();
}
})
}
return [];
})
.then(list => {
if (list.length === 0) {
console.log("WARNING: no announced prefixes were detected. If you are sure the AS provided is announcing at least one prefix, this could be an issue with the data source (RIPEstat). Try to run the generate command with the option -H.");
}
return list;
})
.then(list => list.filter(i => !exclude.includes(i.prefix)))
.then(list => {
return Promise.all(list.map(i => generateRule(i.prefix, asn, false, null, false)))
@@ -155,6 +181,10 @@ module.exports = function generatePrefixes(asnList, outputFile, exclude, exclude
}
});
if (debug) {
console.log("Query", url)
}
return axios({
url,
method: 'GET',
@@ -233,7 +263,7 @@ module.exports = function generatePrefixes(asnList, outputFile, exclude, exclude
fs.writeFileSync(outputFile, yamlContent);
if (someNotValidatedPrefixes) {
console.log("WARNING: The generated configuration is a snapshot of what is currently announced. Some of the prefixes don't have ROA objects associated or are RPKI invalid. Please, verify the config file by hand!");
console.log("WARNING: the generated configuration is a snapshot of what is currently announced. Some of the prefixes don't have ROA objects associated or are RPKI invalid. Please, verify the config file by hand!");
}
console.log("Done!");
})