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

merge dev

This commit is contained in:
Massimo Candela
2023-02-13 22:48:07 +01:00
10 changed files with 698 additions and 6520 deletions

View File

@@ -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:

View File

@@ -1,11 +1,11 @@
# Send alerts with POST requests
# Send alerts with HTTP 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.
BGPalerter can send alerts by means of HTTP requests to a provided URL.
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
* A template of the POST request.
* A template of the request.
If you are using [user groups](usergroups.md), you can specify a URL for every user group. This can be done inside `hooks`, a dictionary containing API URLs grouped by user group (key: group, value: URL).
The default user group is mandatory.
@@ -256,4 +256,4 @@ reports:
default: _API_URL_
```
Thanks [@momorientes](https://github.com/nttgin/BGPalerter/pull/923) and [@PacketVis](https://github.com/nttgin/BGPalerter/pull/1026).
Thanks [@momorientes](https://github.com/nttgin/BGPalerter/pull/923) and [@PacketVis](https://github.com/nttgin/BGPalerter/pull/1026).

View File

@@ -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)

7157
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -56,7 +56,7 @@ export default class MonitorNewPrefix extends Monitor {
const message = alerts[0].matchedMessage;
const matchedRule = alerts[0].matchedRule;
return `Possible change of configuration. A new prefix ${message.prefix} is announced by ${message.originAS}. It is a more specific of ${matchedRule.prefix} (${matchedRule.description})`;
return `A new prefix ${message.prefix} is announced by ${message.originAS}. It is a more specific of ${matchedRule.prefix} (${matchedRule.description}). Maybe you need to update your BGPalerter prefix list.`;
}
return false;

View File

@@ -42,7 +42,7 @@ export default class ReportAlerta extends Report {
if (!this.getUserGroup("default")) {
this.logger.log({
level: 'error',
message: "Alerta reporting is not enabled: no default group defined"
message: "Alerta is not enabled: no default group defined"
});
this.enabled = false;
}

View File

@@ -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
})

View File

@@ -57,7 +57,7 @@ export default class reportTelegram extends ReportHTTP {
if (!params.botUrl) {
this.logger.log({
level: 'error',
message: `${this.name} reporting is not enabled: no botUrl provided`
message: `${this.name} is not enabled: no botUrl provided`
});
this.enabled = false;
}
@@ -65,7 +65,7 @@ export default class reportTelegram extends ReportHTTP {
if (!params.chatIds || !params.chatIds["default"]) {
this.logger.log({
level: 'error',
message: `${this.name} reporting is not enabled: no default chat id provided`
message: `${this.name} is not enabled: no default chat id provided`
});
this.enabled = false;
}

View File

@@ -41,7 +41,7 @@ export default class ReportWebex extends Report {
if (!this.getUserGroup("default")) {
this.logger.log({
level: 'error',
message: `Webex reporting is not enabled: no default group defined`
message: `Webex is not enabled: no default group defined`
});
this.enabled = false;
}

View File

@@ -228,7 +228,7 @@ describe("Alerting", function () {
id: '1234-175.254.205.0/25',
origin: 'prefix-detection',
affected: 1234,
message: 'Possible change of configuration. A new prefix 175.254.205.0/25 is announced by AS1234. It is a more specific of 175.254.205.0/24 (include exclude test)',
message: 'A new prefix 175.254.205.0/25 is announced by AS1234. It is a more specific of 175.254.205.0/24 (include exclude test). Maybe you need to update your BGPalerter prefix list.',
data: [
{
extra: {},
@@ -256,7 +256,7 @@ describe("Alerting", function () {
id: '1234-170.254.205.0/25',
origin: 'prefix-detection',
affected: 1234,
message: 'Possible change of configuration. A new prefix 170.254.205.0/25 is announced by AS1234. It is a more specific of 170.254.205.0/24 (include exclude test)',
message: 'A new prefix 170.254.205.0/25 is announced by AS1234. It is a more specific of 170.254.205.0/24 (include exclude test). Maybe you need to update your BGPalerter prefix list.',
data: [
{
extra: {},
@@ -285,7 +285,7 @@ describe("Alerting", function () {
id: '15562-165.254.255.0/25',
origin: 'prefix-detection',
affected: 15562,
message: 'Possible change of configuration. A new prefix 165.254.255.0/25 is announced by AS15562. It is a more specific of 165.254.255.0/24 (description 2)',
message: 'A new prefix 165.254.255.0/25 is announced by AS15562. It is a more specific of 165.254.255.0/24 (description 2). Maybe you need to update your BGPalerter prefix list.',
data: [
{
extra: {},
@@ -311,7 +311,7 @@ describe("Alerting", function () {
id: '204092-2a00:5884:ffff::/48',
origin: 'prefix-detection',
affected: "204092-45",
message: 'Possible change of configuration. A new prefix 2a00:5884:ffff::/48 is announced by AS204092. It is a more specific of 2a00:5884::/32 (alarig fix test)',
message: 'A new prefix 2a00:5884:ffff::/48 is announced by AS204092. It is a more specific of 2a00:5884::/32 (alarig fix test). Maybe you need to update your BGPalerter prefix list.',
data: [
{
extra: {},