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

introduced support for groups in Slack reporting - not back compatible

This commit is contained in:
Massimo Candela
2019-09-17 19:19:23 +02:00
parent 0ced98a41e
commit 06585f5e1c
6 changed files with 43 additions and 20 deletions

View File

@@ -37,12 +37,23 @@ export default class ReportSlack extends Report {
constructor(channels, params, env) {
super(channels, params, env);
this.enabled = true;
if (!this.params.hooks || !Object.keys(this.params.hooks).length){
this.logger.log({
level: 'error',
message: "Slack reporting is not enabled: no group is defined"
});
this.enabled = false;
}
}
report = (message, content) => {
_sendSlackMessage = (url, content) => {
console.log("sending to", url);
axios({
url: this.params.hookUrl,
url: url,
method: "POST",
resposnseType: "json",
data: {
@@ -55,7 +66,18 @@ export default class ReportSlack extends Report {
message: error
});
})
};
report = (message, content) => {
if (this.enabled){
const groups = content.data.map(i => i.matchedRule.group);
for (let group of groups) {
if (this.params.hooks[group]) {
this._sendSlackMessage(this.params.hooks[group], content);
}
}
}
}
}