mirror of
https://github.com/nttgin/BGPalerter.git
synced 2024-05-19 06:50:08 +00:00
introduced method parameter for reportHTTP (#915)
This commit is contained in:
@@ -229,6 +229,7 @@ reports:
|
||||
# - rpki
|
||||
# - roa
|
||||
# params:
|
||||
# method: post
|
||||
# templates: # See here how to write a template https://github.com/nttgin/BGPalerter/blob/main/docs/context.md
|
||||
# default: '{"text": "${summary}"}'
|
||||
# headers:
|
||||
|
@@ -1,7 +1,7 @@
|
||||
# Send alerts with POST requests
|
||||
|
||||
BGPalerter can send alerts by means of POST requests to a provided URL.
|
||||
This can be done by configuring the module reportHTTP. Read [here](configuration.md#reporthttp) to understand how.
|
||||
This can be done by configuring the module reportHTTP. Read [here](reports.md#reportHTTP) to understand how.
|
||||
|
||||
For configuring reportHTTP, essentially you need to specify two things:
|
||||
* The URL
|
||||
|
@@ -130,15 +130,16 @@ This report module sends alerts on a generic HTTP end-point.
|
||||
|
||||
Parameters for this report module:
|
||||
|
||||
|Parameter| Description|
|
||||
|---|---|
|
||||
|hooks| A dictionary containing API URLs grouped by user group (key: group, value: URL).|
|
||||
|hooks.default| The URL of the default user group.|
|
||||
|templates| A dictionary containing string templates for each channels. If a channel doesn't have a template defined, the `default` template will be used (see `config.yml.example` for more details). Read [here](context.md) how to write a template. |
|
||||
|noProxy| If there is a global proxy configuration (see [here](http-proxy.md)), this parameter if set to true allows the single module to bypass the proxy. |
|
||||
|isTemplateJSON| A boolean defining if the template provided above are JSON or plain string |
|
||||
|headers| Additional headers to use in the GET request. For example for authentication.|
|
||||
|showPaths| Amount of AS_PATHs to report in the alert (0 to disable). |
|
||||
| Parameter | Description|
|
||||
|----------------|---|
|
||||
| hooks | A dictionary containing API URLs grouped by user group (key: group, value: URL).|
|
||||
| hooks.default | The URL of the default user group.|
|
||||
| templates | A dictionary containing string templates for each channels. If a channel doesn't have a template defined, the `default` template will be used (see `config.yml.example` for more details). Read [here](context.md) how to write a template. |
|
||||
| noProxy | If there is a global proxy configuration (see [here](http-proxy.md)), this parameter if set to true allows the single module to bypass the proxy. |
|
||||
| isTemplateJSON | A boolean defining if the template provided above are JSON or plain string |
|
||||
| headers | Additional headers to use in the GET request. For example for authentication.|
|
||||
| showPaths | Amount of AS_PATHs to report in the alert (0 to disable). |
|
||||
| method | One of `post`, `put`, `patch`, `delete`. Default to `post`. |
|
||||
|
||||
[See here some examples of how to adapt reportHTTP to some common applications.](report-http.md)
|
||||
|
||||
|
@@ -39,11 +39,20 @@ export default class ReportHTTP extends Report {
|
||||
|
||||
this.name = "reportHTTP" || this.params.name;
|
||||
this.enabled = true;
|
||||
this.method = (this.params?.method ?? "post").toLowerCase();
|
||||
|
||||
if (!["post", "put", "patch", "delete"].includes(this.method)) {
|
||||
this.logger.log({
|
||||
level: 'error',
|
||||
message: `${this.name} is not enabled: the configured HTTP method is not valid`
|
||||
});
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
if (!this.getUserGroup("default")) {
|
||||
this.logger.log({
|
||||
level: 'error',
|
||||
message: `${this.name} reporting is not enabled: no default group defined`
|
||||
message: `${this.name} is not enabled: no default group defined`
|
||||
});
|
||||
this.enabled = false;
|
||||
}
|
||||
@@ -81,7 +90,7 @@ export default class ReportHTTP extends Report {
|
||||
|
||||
this.axios({
|
||||
url,
|
||||
method: "POST",
|
||||
method: this.method,
|
||||
headers: this.headers,
|
||||
data: (this.params.isTemplateJSON) ? JSON.parse(blob) : blob
|
||||
})
|
||||
|
Reference in New Issue
Block a user