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

added reportSyslog

This commit is contained in:
Massimo Candela
2019-12-11 01:41:26 +01:00
parent d4c1d001b7
commit 87a6239fe5
6 changed files with 148 additions and 3 deletions

View File

@@ -47,6 +47,7 @@ Please uncomment the related section and configure according to your needs.
- [reportEmail](docs/configuration.md#reportemail) - [reportEmail](docs/configuration.md#reportemail)
- [reportSlack](docs/configuration.md#reportslack) - [reportSlack](docs/configuration.md#reportslack)
- [reportKafka](docs/configuration.md#reportkafka) - [reportKafka](docs/configuration.md#reportkafka)
- [reportSyslog](docs/configuration.md#reportsyslog)
- [Uptime monitoring](docs/uptime-monitor.md) - [Uptime monitoring](docs/uptime-monitor.md)
- [More information for developers](docs/develop.md) - [More information for developers](docs/develop.md)
- [All npm commands](docs/develop.md#all-npm-commands) - [All npm commands](docs/develop.md#all-npm-commands)

View File

@@ -106,10 +106,29 @@ reports:
# - path # - path
# - misconfiguration # - misconfiguration
# params: # params:
# host: localhost:9092 # host: localhost
# port: 9092
# topics: # topics:
# default: bgpalerter # default: bgpalerter
# - file: reportSyslog
# channels:
# - hijack
# - newprefix
# - visibility
# - path
# - asn-monitor
# - misconfiguration
# params:
# host: localhost
# port: 514
# templates:
# default: "++BGPalerter-3-${type}: ${summary}|${earliest}|${latest}"
# hijack: "++BGPalerter-5-${type}: ${summary}|${prefix}|${description}|${asn}|${newprefix}|${neworigin}|${earliest}|${latest}|${peers}"
# newprefix: "++BGPalerter-4-${type}: ${summary}|${prefix}|${description}|${asn}|${newprefix}|${neworigin}|${earliest}|${latest}|${peers}"
# visibility: "++BGPalerter-5-${type}: ${summary}|${prefix}|${description}|${asn}|${earliest}|${latest}|${peers}"
############################ ############################
# Notification settings: # Notification settings:

View File

@@ -268,6 +268,20 @@ Parameters for this report module:
|Parameter| Description| |Parameter| Description|
|---|---| |---|---|
|host| Host and port of the Kafka instance/broker (e.g. localhost:9092).| |host| Host of the Kafka instance/broker (e.g. localhost).|
|port| Port of the Kafka instance/broker (e.g. 9092).|
|topics| A dictionary containing a mapping from BGPalerter channels to Kafka topics (e.g. `hijack: hijack-topic`). By default all channels are sent to the topic `bgpalerter` (`default: bgpalerter`) | |topics| A dictionary containing a mapping from BGPalerter channels to Kafka topics (e.g. `hijack: hijack-topic`). By default all channels are sent to the topic `bgpalerter` (`default: bgpalerter`) |
#### reportSyslog
This report module sends the alerts on Syslog.
Parameters for this report module:
|Parameter| Description|
|---|---|
|showPaths| Amount of AS_PATHs to report in the alert (0 to disable). |
|host| Host of the Syslog server (e.g. localhost).|
|port| Port of the Syslog server (e.g. 514).|
|templates| A dictionary containing string templates for each BGPalerter channels. If a channel doesn't have a template defined, the `default` template will be used (see `config.yml.example` for more details). |

View File

@@ -44,6 +44,7 @@
"resnap": "^1.0.1", "resnap": "^1.0.1",
"restify": "^8.5.0", "restify": "^8.5.0",
"restify-errors": "^8.0.1", "restify-errors": "^8.0.1",
"syslog-client": "^1.1.1",
"websocket-stream": "^5.5.0", "websocket-stream": "^5.5.0",
"winston": "^3.2.1", "winston": "^3.2.1",
"winston-daily-rotate-file": "^4.3.1", "winston-daily-rotate-file": "^4.3.1",

105
src/reports/reportSyslog.js Normal file
View File

@@ -0,0 +1,105 @@
/*
* 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 Report from "./report";
import syslog from "syslog-client";
export default class ReportSyslog extends Report {
constructor(channels, params, env) {
super(channels, params, env);
this.client = null;
this.connected = false;
this.connecting = null;
this.host = [ params.hostname || "localhost", params.port ].filter(i => i != null).join(":");
this.options = {
syslogHostname: params.hostname,
transport: syslog.Transport.Udp,
port: params.port
};
}
_getMessage = (channel, content) => {
return this.parseTemplate(this.params.templates[channel] || this.params.templates["default"], this.getContext(channel, content));
};
_connectToSyslog = () => {
if (!this.connecting) {
this.connecting = new Promise((resolve, reject) => {
if (this.connected) {
resolve(true);
} else {
console.log("connecting");
this.client = syslog.createClient(this.host, this.options);
this.connected = true;
this.client.on("close", function () {
this.logger.log({
level: 'error',
message: 'Syslog disconnected: ' + error
});
});
this.client.on("error", function () {
this.logger.log({
level: 'error',
message: 'Syslog: ' + error
});
});
resolve(true);
}
});
}
return this.connecting;
};
report = (channel, content) => {
return this._connectToSyslog()
.then(() => {
const message = this._getMessage(channel, content);
console.log(message);
this.client.log(message, {}, error => {
if (error) {
this.logger.log({
level: 'error',
message: 'Syslog: ' + error
});
}
});
});
};
}

View File

@@ -4811,6 +4811,11 @@ supports-color@^7.1.0:
dependencies: dependencies:
has-flag "^4.0.0" has-flag "^4.0.0"
syslog-client@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/syslog-client/-/syslog-client-1.1.1.tgz#bdb28de3b5b7eb28a11352ec3eb78e55aed2ab6b"
integrity sha1-vbKN47W36yihE1LsPreOVa7Sq2s=
tar-fs@^2.0.0: tar-fs@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.0.0.tgz#677700fc0c8b337a78bee3623fdc235f21d7afad" resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.0.0.tgz#677700fc0c8b337a78bee3623fdc235f21d7afad"