mirror of
https://github.com/nttgin/BGPalerter.git
synced 2024-05-19 06:50:08 +00:00
deprecation of resource_templates for reportAlerta
This commit is contained in:
@@ -55,7 +55,9 @@ export default class ReportAlerta extends Report {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.headers = {};
|
this.headers = {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
};
|
||||||
if (this.params.key){
|
if (this.params.key){
|
||||||
this.headers.Authorization = "Key " + this.params.key;
|
this.headers.Authorization = "Key " + this.params.key;
|
||||||
}
|
}
|
||||||
@@ -65,21 +67,33 @@ export default class ReportAlerta extends Report {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_createAlertaAlert = (url, message, content) => {
|
_createAlertaAlert = (url, channel, content) => {
|
||||||
|
|
||||||
const severity = (this.params && this.params.severity && this.params.severity[message])
|
const severity = (this.params && this.params.severity && this.params.severity[channel])
|
||||||
? this.params.severity[message]
|
? this.params.severity[channel]
|
||||||
: "informational"; // informational level
|
: "informational"; // informational level
|
||||||
const context = this.getContext(message, content);
|
const context = this.getContext(channel, content);
|
||||||
|
|
||||||
|
if (this.params.resource_templates) {
|
||||||
|
this.logger.log({
|
||||||
|
level: 'info',
|
||||||
|
message: "The resource_templates parameter will be soon deprecated in favour of resourceTemplates. Please update your config.yml file accordingly."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const resource = this.params.resourceTemplates[channel] ||
|
||||||
|
this.params.resource_templates[channel] ||
|
||||||
|
this.params.resourceTemplates["default"] ||
|
||||||
|
this.params.resource_templates["default"];
|
||||||
|
|
||||||
axios({
|
axios({
|
||||||
url: url + "/alert",
|
url: url + "/alert",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
resposnseType: "json",
|
responseType: "json",
|
||||||
data: {
|
data: {
|
||||||
event: message,
|
event: channel,
|
||||||
resource: this.parseTemplate(this.params.resourceTemplates[message] || this.params.resourceTemplates["default"], context),
|
resource: this.parseTemplate(resource, context),
|
||||||
text: content.message,
|
text: content.message,
|
||||||
service: ["BGPalerter"],
|
service: ["BGPalerter"],
|
||||||
attributes: context,
|
attributes: context,
|
||||||
@@ -95,7 +109,7 @@ export default class ReportAlerta extends Report {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
report = (message, content) => {
|
report = (channel, content) => {
|
||||||
if (this.enabled){
|
if (this.enabled){
|
||||||
let groups = content.data.map(i => i.matchedRule.group).filter(i => i != null);
|
let groups = content.data.map(i => i.matchedRule.group).filter(i => i != null);
|
||||||
|
|
||||||
@@ -103,7 +117,7 @@ export default class ReportAlerta extends Report {
|
|||||||
|
|
||||||
for (let group of groups) {
|
for (let group of groups) {
|
||||||
if (this.params.urls[group]) {
|
if (this.params.urls[group]) {
|
||||||
this._createAlertaAlert(this.params.urls[group], message, content);
|
this._createAlertaAlert(this.params.urls[group], channel, content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user