Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add reportMatrix module #1043

Merged
merged 6 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,24 @@ reports:
# params:
# maxAlertsAmount: 25

# - file: reportMatrix
# channels:
# - hijack
# - newprefix
# - visibility
# - path
# - misconfiguration
# - rpki
# - roa
# params:
# showPaths: 0 # Amount of AS_PATHs to report in the alert
# homeserverUrl: https://matrix.org
# accessToken: _ACCESS_TOKEN_
# roomIds:
# default: "_ROOM_ID_"
# noc: "_ROOM_ID_"
NickBouwhuis marked this conversation as resolved.
Show resolved Hide resolved


############################
# Notification settings:
# - notificationIntervalSeconds
Expand Down
2 changes: 2 additions & 0 deletions docs/friends.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ Please, let me know so I can add your company name here.
* Rechenzentrum Haßfurt GmbH (AS44973)
* obe.net (AS3399)
* IT-Total (AS8769)
* Speakup (AS49627)
* Nick Bouwhuis (AS202585)
19 changes: 18 additions & 1 deletion docs/reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This will generate fake alerts. [Read more here](installation.md#bgpalerter-para
- [reportHTTP](reports.md#reportHTTP)
- [reportTelegram](reports.md#reportTelegram)
- [reportPullAPI](reports.md#reportPullAPI)
- [reportMatrix](reports.md#reportMatrix)

## reportFile

Expand Down Expand Up @@ -172,10 +173,26 @@ This report module creates a REST API reachable at `http://host:port/alerts/`. T

The REST API uses the generic `rest` configuration in `config.yml`. Read [here](configuration.md) or see `config.yml.example` for more information.


Parameters for this report module:

|Parameter| Description|
|---|---|
|maxAlertsAmount| The maximum amount of alerts the API will return. By default set to 100. Don't exagerate with the number, the greater this value is the more memory BGPalerter will use. |
|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. |

## reportMatrix

This report module sends alerts directly to a specific Matrix room.
To send alert to Matrix you need an access token and a room ID.
NickBouwhuis marked this conversation as resolved.
Show resolved Hide resolved

Parameters for this report module:

|Parameter| Description|
|---|---|
|showPaths| Amount of AS_PATHs to report in the alert (0 to disable). |
|homeserverUrl:| URL of your Matrix homeserver (for example: `https://matrix.org` |
|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. |
|roomIds| A dictionary containing chat IDs grouped by user group (key: group, value: room ID).|
|roomIds.default| The room ID of the default room.|


87 changes: 87 additions & 0 deletions src/reports/reportMatrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* BSD 3-Clause License
*
* Copyright (c) 2019, NTT Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import ReportHTTP from "./reportHTTP";

export default class reportMatrix extends ReportHTTP {

constructor(channels, params, env) {
const hooks = {};
const transactionId = Math.random().toString(36).substring(2, 15);
NickBouwhuis marked this conversation as resolved.
Show resolved Hide resolved

for (let userGroup in params.roomIds) {
hooks[userGroup] = params.homeserverUrl + "/_matrix/client/v3/rooms/" + encodeURIComponent(params.roomIds[userGroup]) + "/send/m.room.message/" + transactionId;
}
hooks["default"] = params.homeserverUrl + "/_matrix/client/v3/rooms/" + encodeURIComponent(params.roomIds["default"]) + "/send/m.room.message/" + transactionId;


const matrixParams = {
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + params.accessToken
},
isTemplateJSON: true,
showPaths: params.showPaths,
hooks: hooks,
name: "reportMatrix",
method: "put",
templates: {}
};

super(channels, matrixParams, env);
this.roomIds = params.roomIds;

if (!params.homeserverUrl || !params.accessToken) {
this.logger.log({
level: 'error',
message: `${this.name} reporting is not enabled: homeserverUrl and accessToken are required`
});
this.enabled = false;
}

if (!params.roomIds || !params.roomIds["default"]) {
this.logger.log({
level: 'error',
message: `${this.name} reporting is not enabled: no default room id provided`
});
this.enabled = false;
}
};

getTemplate = (group, channel, content) => {
return JSON.stringify({
"msgtype": "m.text",
"body": "${summary}${markDownUrl}",
});
};
}