Skip to content

Commit

Permalink
introduced method parameter for reportHTTP (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
massimocandela committed Feb 13, 2023
1 parent c6c536e commit 76fcdbc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/report-http.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 10 additions & 9 deletions docs/reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 11 additions & 2 deletions src/reports/reportHTTP.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
})
Expand Down

0 comments on commit 76fcdbc

Please sign in to comment.