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:
@@ -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,21 +61,24 @@ export default class InputYml extends Input {
|
||||
};
|
||||
|
||||
_watchPrefixFile = (file) => {
|
||||
fs.watchFile(file, () => {
|
||||
this.prefixes = [];
|
||||
this.asns = [];
|
||||
this._loadPrefixes()
|
||||
.then(() => {
|
||||
return this._change();
|
||||
})
|
||||
.catch(error => {
|
||||
this.logger.log({
|
||||
level: 'error',
|
||||
message: error
|
||||
if (!this.watcherSet) {
|
||||
this.watcherSet = true;
|
||||
fs.watchFile(file, () => {
|
||||
this.prefixes = [];
|
||||
this.asns = [];
|
||||
this._loadPrefixes()
|
||||
.then(() => {
|
||||
return this._change();
|
||||
})
|
||||
.catch(error => {
|
||||
this.logger.log({
|
||||
level: 'error',
|
||||
message: error
|
||||
});
|
||||
process.exit();
|
||||
});
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
_loadPrefixes = () =>
|
||||
@@ -101,20 +106,24 @@ export default class InputYml extends Input {
|
||||
}
|
||||
|
||||
if (this.validate(monitoredPrefixesFile)) {
|
||||
if (monitoredPrefixesFile.options) {
|
||||
|
||||
if (monitoredPrefixesFile.options && monitoredPrefixesFile.options.monitorASns) {
|
||||
this.asns = Object
|
||||
.keys(monitoredPrefixesFile.options.monitorASns)
|
||||
.map(asn => {
|
||||
if (uniqueAsns[asn]) {
|
||||
throw new Error("Duplicate entry for monitored AS " + asn);
|
||||
}
|
||||
uniqueAsns[asn] = true;
|
||||
return Object.assign({
|
||||
asn: new AS(asn),
|
||||
group: 'default'
|
||||
}, monitoredPrefixesFile.options.monitorASns[asn]);
|
||||
});
|
||||
this.options = monitoredPrefixesFile.options;
|
||||
|
||||
if (monitoredPrefixesFile.options.monitorASns) {
|
||||
this.asns = Object
|
||||
.keys(monitoredPrefixesFile.options.monitorASns)
|
||||
.map(asn => {
|
||||
if (uniqueAsns[asn]) {
|
||||
throw new Error("Duplicate entry for monitored AS " + asn);
|
||||
}
|
||||
uniqueAsns[asn] = true;
|
||||
return Object.assign({
|
||||
asn: new AS(asn),
|
||||
group: 'default'
|
||||
}, monitoredPrefixesFile.options.monitorASns[asn]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const monitoredPrefixes = Object
|
||||
@@ -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 })));
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user