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

improve checks in case cache is removed

This commit is contained in:
Massimo Candela
2020-08-03 16:19:43 +02:00
parent e2bb8d5e5a
commit 6bb271d9bd
3 changed files with 18 additions and 13 deletions

View File

@@ -19,7 +19,7 @@ The following are common parameters which it is possible to specify in the confi
|httpProxy| Defines the HTTP/HTTPS proxy server to be used by BGPalerter and its submodules (reporters/connectors/monitors). See [here](http-proxy.md) for more information. | A string | http://usr:psw@ prxy.org:8080 | No |
|volume| Defines a directory that will contain the data that needs persistence. For example, configuration files and logs will be created in such directory (default to "./"). | A string | /home/bgpalerter/ | No |
|persistStatus| If set to true, when BGPalerter is restarted the list of alerts already sent is recovered. This avoids duplicated alerts. The process must be able to write on disc inside `.cache/`. | A boolean | true | No |
|generatePrefixListEveryDays| This parameter allows to automatically re-generate the prefix list after the specified amount of days. | An integer | 2 | No |
|generatePrefixListEveryDays| This parameter allows to automatically re-generate the prefix list after the specified amount of days. Set to 0 to disable it. | An integer | 2 | No |
The following are advanced parameters, please don't touch them if you are not doing research/experiments.

View File

@@ -129,10 +129,11 @@ let config = {
channels: ["hijack", "newprefix", "visibility", "path", "misconfiguration", "rpki"]
}
],
notificationIntervalSeconds: 14400,
notificationIntervalSeconds: 86400,
alarmOnlyOnce: false,
monitoredPrefixesFiles: ["prefixes.yml"],
persistStatus: true,
generatePrefixListEveryDays: 2,
logging: {
directory: "logs",
logRotatePattern: "YYYY-MM-DD",

View File

@@ -220,7 +220,7 @@ export default class Input {
logger: null
};
if (this.config.generatePrefixListEveryDays >= 1) {
if (this.config.generatePrefixListEveryDays >= 1 && this.storage) {
return this.storage
.set(this.prefixListStorageKey, inputParameters)
.then(() => generatePrefixes(inputParameters))
@@ -252,14 +252,19 @@ export default class Input {
this.storage
.get(this.prefixListStorageKey)
.then(inputParameters => {
inputParameters.logger = (message) => {
this.logger.log({
level: 'info',
message
});
};
return generatePrefixes(inputParameters);
if (inputParameters && Object.keys(inputParameters).length > 0) {
inputParameters.logger = (message) => {
this.logger.log({
level: 'info',
message
});
};
return generatePrefixes(inputParameters);
} else {
throw new Error("The prefix list cannot be refreshed because it was not generated automatically or the cache has been deleted.");
}
})
.then(() => {
this.logger.log({
@@ -277,10 +282,9 @@ export default class Input {
};
setReGeneratePrefixList = () => {
if (this.config.generatePrefixListEveryDays >= 1) {
//const refreshTimer = Math.ceil(this.config.generatePrefixListEveryDays) * 24 * 3600 * 1000;
if (this.config.generatePrefixListEveryDays >= 1 && this.storage) {
const refreshTimer = Math.ceil(this.config.generatePrefixListEveryDays) * 24 * 3600 * 1000;
const refreshTimer = 60000;
if (this.regeneratePrefixListTimer) {
clearTimeout(this.regeneratePrefixListTimer);
}