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

moved generation options to prefixes.yml for portability

This commit is contained in:
Massimo Candela
2020-08-08 19:25:04 +02:00
parent 80bd106e1e
commit c02aff7860
5 changed files with 105 additions and 103 deletions

View File

@@ -156,14 +156,14 @@ switch(params._[0]) {
const inputParameters = {
asnList: (params.a) ? params.a.toString().split(",") : null,
outputFile: params.o,
exclude: (params.e || "").split(","),
exclude: (params.e) ? params.e.toString().split(",") : null,
excludeDelegated: params.i || false,
prefixes,
monitoredASes,
httpProxy: params.x || null,
debug,
historical,
group: params.g,
group: params.g || null,
append: !!params.A,
logger: null,
getCurrentPrefixesList: () => {

View File

@@ -257,7 +257,6 @@ export default class ConnectorRIS extends Connector {
};
_onInputChange = (input) => {
this.subscribed = {};
this.connect()
.then(() => this.subscribe(input))
.then(() => {

View File

@@ -25,6 +25,7 @@ module.exports = function generatePrefixes(inputParameters) {
enriched
} = inputParameters;
exclude = exclude || [];
logger = logger || console.log;
const generateList = {};
@@ -194,7 +195,6 @@ module.exports = function generatePrefixes(inputParameters) {
return latest.getTime() + (3600 * 24 * 1000) > new Date().getTime();
}
})
}
return [];
})
@@ -216,8 +216,6 @@ module.exports = function generatePrefixes(inputParameters) {
};
const validatePrefix = (asn, prefix) => {
return rpki
.validate(prefix, asn, false)
.then(isValid => {
@@ -345,6 +343,16 @@ module.exports = function generatePrefixes(inputParameters) {
})
.then(list => {
logger("Done!");
const options = {
asnList,
exclude,
excludeDelegated,
prefixes,
monitoredASes,
historical,
group
};
list.options = Object.assign({}, list.options, { generate: options });
return list;
})
.catch((e) => {

View File

@@ -225,13 +225,7 @@ export default class Input {
}
};
if (this.config.generatePrefixListEveryDays >= 1 && this.storage) {
return this.storage
.set(this.prefixListStorageKey, inputParameters)
.then(() => generatePrefixes(inputParameters));
} else {
return generatePrefixes(inputParameters);
}
});
} else {
@@ -255,11 +249,14 @@ export default class Input {
this.setReGeneratePrefixList();
this.storage
.get(this.prefixListStorageKey)
.then(inputParameters => {
return this.retrieve()
.then(oldPrefixList => {
const inputParameters = oldPrefixList.options.generate;
if (!inputParameters) {
throw new Error("The prefix list cannot be refreshed because it was not generated automatically or the cache has been deleted.");
}
if (inputParameters && Object.keys(inputParameters).length > 0) {
inputParameters.logger = (message) => {
this.logger.log({
level: 'info',
@@ -267,8 +264,6 @@ export default class Input {
});
};
return this.retrieve()
.then(oldPrefixList => {
return generatePrefixes(inputParameters)
.then(newPrefixList => {
@@ -306,12 +301,6 @@ export default class Input {
return newPrefixList;
});
});
} else {
throw new Error("The prefix list cannot be refreshed because it was not generated automatically or the cache has been deleted.");
}
})
.then(this.save)
.then(() => {
@@ -329,7 +318,7 @@ export default class Input {
};
setReGeneratePrefixList = () => {
if (this.config.generatePrefixListEveryDays >= 1 && this.storage) {
if (this.config.generatePrefixListEveryDays >= 1) {
const refreshTimer = Math.ceil(this.config.generatePrefixListEveryDays) * 24 * 3600 * 1000;
if (this.regeneratePrefixListTimer) {

View File

@@ -46,6 +46,8 @@ export default class InputYml extends Input {
if (!this.config.monitoredPrefixesFiles || this.config.monitoredPrefixesFiles.length === 0) {
throw new Error("The monitoredPrefixesFiles key is missing in the config file");
}
this.watcherSet = false;
};
loadPrefixes = () => {
@@ -59,6 +61,8 @@ export default class InputYml extends Input {
};
_watchPrefixFile = (file) => {
if (!this.watcherSet) {
this.watcherSet = true;
fs.watchFile(file, () => {
this.prefixes = [];
this.asns = [];
@@ -74,6 +78,7 @@ export default class InputYml extends Input {
process.exit();
});
});
}
};
_loadPrefixes = () =>
@@ -101,8 +106,11 @@ export default class InputYml extends Input {
}
if (this.validate(monitoredPrefixesFile)) {
if (monitoredPrefixesFile.options) {
if (monitoredPrefixesFile.options && monitoredPrefixesFile.options.monitorASns) {
this.options = monitoredPrefixesFile.options;
if (monitoredPrefixesFile.options.monitorASns) {
this.asns = Object
.keys(monitoredPrefixesFile.options.monitorASns)
.map(asn => {
@@ -116,6 +124,7 @@ export default class InputYml extends Input {
}, monitoredPrefixesFile.options.monitorASns[asn]);
});
}
}
const monitoredPrefixes = Object
.keys(monitoredPrefixesFile)
@@ -292,19 +301,16 @@ export default class InputYml extends Input {
if (rule.includeMonitors.length) prefixes[prefix].includeMonitors = rule.includeMonitors;
}
const options = {
options: {
monitorASns: {
}
}
};
const monitorASns = {};
for (let asnRule of this.asns) {
options.options.monitorASns[asnRule.asn.getValue()] = {
monitorASns[asnRule.asn.getValue()] = {
group: asnRule.group
};
}
resolve({ ...prefixes, ...options });
const options = Object.assign({}, this.options, { monitorASns });
resolve(JSON.parse(JSON.stringify({ ...prefixes, options })));
});
}