@bsb/syslog 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +75 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.js +42 -0
- package/lib/plugins/observable-syslog/index.d.ts +141 -0
- package/lib/plugins/observable-syslog/index.js +235 -0
- package/lib/plugins/service-syslog-server/index.d.ts +143 -0
- package/lib/plugins/service-syslog-server/index.js +148 -0
- package/lib/schemas/observable-syslog.json +133 -0
- package/lib/schemas/observable-syslog.plugin.json +122 -0
- package/lib/schemas/service-syslog-server.json +74 -0
- package/lib/schemas/service-syslog-server.plugin.json +42 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @bsb/syslog
|
|
2
|
+
|
|
3
|
+
Syslog server and client for BSB - receive syslog messages and send logs to syslog servers.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @bsb/syslog
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
### Syslog Server
|
|
14
|
+
- **Receive syslog messages** - UDP/TCP protocols
|
|
15
|
+
- **RFC compliance** - Supports RFC 3164 and RFC 5424
|
|
16
|
+
- **Event emission** - Emit received messages as BSB events
|
|
17
|
+
- **Client API** - Subscribe to syslog messages from other services
|
|
18
|
+
|
|
19
|
+
### Syslog Client (Observable)
|
|
20
|
+
- **Send BSB logs to syslog** - Forward application logs
|
|
21
|
+
- **Multiple protocols** - UDP, TCP, TLS support
|
|
22
|
+
- **RFC compliance** - RFC 3164 and RFC 5424
|
|
23
|
+
- **Level filtering** - Control which log levels are sent
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
### Server Configuration
|
|
28
|
+
|
|
29
|
+
```yaml
|
|
30
|
+
plugins:
|
|
31
|
+
services:
|
|
32
|
+
- plugin: "@bsb/syslog"
|
|
33
|
+
service: "SyslogServerPlugin"
|
|
34
|
+
enabled: true
|
|
35
|
+
config:
|
|
36
|
+
port: 514
|
|
37
|
+
address: "0.0.0.0"
|
|
38
|
+
exclusive: false
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Client (Observable) Configuration
|
|
42
|
+
|
|
43
|
+
```yaml
|
|
44
|
+
plugins:
|
|
45
|
+
observables:
|
|
46
|
+
- plugin: "@bsb/syslog"
|
|
47
|
+
observable: "SyslogClientPlugin"
|
|
48
|
+
enabled: true
|
|
49
|
+
config:
|
|
50
|
+
host: "localhost"
|
|
51
|
+
port: 514
|
|
52
|
+
protocol: "udp"
|
|
53
|
+
facility: 16
|
|
54
|
+
appName: "my-app"
|
|
55
|
+
rfc: "5424"
|
|
56
|
+
levels:
|
|
57
|
+
debug: true
|
|
58
|
+
info: true
|
|
59
|
+
warn: true
|
|
60
|
+
error: true
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import {
|
|
67
|
+
SyslogServerPlugin,
|
|
68
|
+
SyslogServerClient,
|
|
69
|
+
SyslogClientPlugin
|
|
70
|
+
} from "@bsb/syslog";
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
Dual-licensed under AGPL-3.0-only OR Commercial License.
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
export { SyslogMessageSchema, type SyslogMessage, SyslogServerConfigSchema, type SyslogServerConfig, Config as SyslogServerConfigClass, EventSchemas as SyslogServerEventSchemas, Plugin as SyslogServerPlugin, Client as SyslogServerClient, } from "./plugins/service-syslog-server";
|
|
28
|
+
export { SyslogClientConfigSchema, type SyslogClientConfig, Config as SyslogClientConfigClass, Plugin as SyslogClientPlugin, } from "./plugins/observable-syslog";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
8
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
12
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
13
|
+
* including the right to create derivative works that are not subject to the terms
|
|
14
|
+
* of the AGPL.
|
|
15
|
+
*
|
|
16
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
17
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
18
|
+
* will be provided upon request.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU Affero General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.SyslogClientPlugin = exports.SyslogClientConfigClass = exports.SyslogClientConfigSchema = exports.SyslogServerClient = exports.SyslogServerPlugin = exports.SyslogServerEventSchemas = exports.SyslogServerConfigClass = exports.SyslogServerConfigSchema = exports.SyslogMessageSchema = void 0;
|
|
30
|
+
// Syslog server exports (receives syslog messages)
|
|
31
|
+
var service_syslog_server_1 = require("./plugins/service-syslog-server");
|
|
32
|
+
Object.defineProperty(exports, "SyslogMessageSchema", { enumerable: true, get: function () { return service_syslog_server_1.SyslogMessageSchema; } });
|
|
33
|
+
Object.defineProperty(exports, "SyslogServerConfigSchema", { enumerable: true, get: function () { return service_syslog_server_1.SyslogServerConfigSchema; } });
|
|
34
|
+
Object.defineProperty(exports, "SyslogServerConfigClass", { enumerable: true, get: function () { return service_syslog_server_1.Config; } });
|
|
35
|
+
Object.defineProperty(exports, "SyslogServerEventSchemas", { enumerable: true, get: function () { return service_syslog_server_1.EventSchemas; } });
|
|
36
|
+
Object.defineProperty(exports, "SyslogServerPlugin", { enumerable: true, get: function () { return service_syslog_server_1.Plugin; } });
|
|
37
|
+
Object.defineProperty(exports, "SyslogServerClient", { enumerable: true, get: function () { return service_syslog_server_1.Client; } });
|
|
38
|
+
// Syslog client observable exports (sends logs to syslog)
|
|
39
|
+
var observable_syslog_1 = require("./plugins/observable-syslog");
|
|
40
|
+
Object.defineProperty(exports, "SyslogClientConfigSchema", { enumerable: true, get: function () { return observable_syslog_1.SyslogClientConfigSchema; } });
|
|
41
|
+
Object.defineProperty(exports, "SyslogClientConfigClass", { enumerable: true, get: function () { return observable_syslog_1.Config; } });
|
|
42
|
+
Object.defineProperty(exports, "SyslogClientPlugin", { enumerable: true, get: function () { return observable_syslog_1.Plugin; } });
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
import { BSBObservable, BSBObservableConstructor, BSBError } from "@bsb/base";
|
|
28
|
+
import { DTrace, LogMeta } from "@bsb/base";
|
|
29
|
+
import { z } from "zod";
|
|
30
|
+
/**
|
|
31
|
+
* Configuration schema for syslog client observable
|
|
32
|
+
*/
|
|
33
|
+
export declare const SyslogClientConfigSchema: z.ZodObject<{
|
|
34
|
+
host: z.ZodDefault<z.ZodString>;
|
|
35
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
36
|
+
protocol: z.ZodDefault<z.ZodEnum<{
|
|
37
|
+
udp: "udp";
|
|
38
|
+
tcp: "tcp";
|
|
39
|
+
tls: "tls";
|
|
40
|
+
}>>;
|
|
41
|
+
tls: z.ZodOptional<z.ZodObject<{
|
|
42
|
+
rejectUnauthorized: z.ZodDefault<z.ZodBoolean>;
|
|
43
|
+
ca: z.ZodOptional<z.ZodString>;
|
|
44
|
+
cert: z.ZodOptional<z.ZodString>;
|
|
45
|
+
key: z.ZodOptional<z.ZodString>;
|
|
46
|
+
}, z.core.$strip>>;
|
|
47
|
+
facility: z.ZodDefault<z.ZodNumber>;
|
|
48
|
+
hostname: z.ZodOptional<z.ZodString>;
|
|
49
|
+
appName: z.ZodDefault<z.ZodString>;
|
|
50
|
+
rfc: z.ZodDefault<z.ZodEnum<{
|
|
51
|
+
3164: "3164";
|
|
52
|
+
5424: "5424";
|
|
53
|
+
}>>;
|
|
54
|
+
levels: z.ZodObject<{
|
|
55
|
+
debug: z.ZodDefault<z.ZodBoolean>;
|
|
56
|
+
info: z.ZodDefault<z.ZodBoolean>;
|
|
57
|
+
warn: z.ZodDefault<z.ZodBoolean>;
|
|
58
|
+
error: z.ZodDefault<z.ZodBoolean>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
export type SyslogClientConfig = z.infer<typeof SyslogClientConfigSchema>;
|
|
62
|
+
export declare const Config: import("@bsb/base").BSBPluginConfigClass<z.ZodObject<{
|
|
63
|
+
host: z.ZodDefault<z.ZodString>;
|
|
64
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
65
|
+
protocol: z.ZodDefault<z.ZodEnum<{
|
|
66
|
+
udp: "udp";
|
|
67
|
+
tcp: "tcp";
|
|
68
|
+
tls: "tls";
|
|
69
|
+
}>>;
|
|
70
|
+
tls: z.ZodOptional<z.ZodObject<{
|
|
71
|
+
rejectUnauthorized: z.ZodDefault<z.ZodBoolean>;
|
|
72
|
+
ca: z.ZodOptional<z.ZodString>;
|
|
73
|
+
cert: z.ZodOptional<z.ZodString>;
|
|
74
|
+
key: z.ZodOptional<z.ZodString>;
|
|
75
|
+
}, z.core.$strip>>;
|
|
76
|
+
facility: z.ZodDefault<z.ZodNumber>;
|
|
77
|
+
hostname: z.ZodOptional<z.ZodString>;
|
|
78
|
+
appName: z.ZodDefault<z.ZodString>;
|
|
79
|
+
rfc: z.ZodDefault<z.ZodEnum<{
|
|
80
|
+
3164: "3164";
|
|
81
|
+
5424: "5424";
|
|
82
|
+
}>>;
|
|
83
|
+
levels: z.ZodObject<{
|
|
84
|
+
debug: z.ZodDefault<z.ZodBoolean>;
|
|
85
|
+
info: z.ZodDefault<z.ZodBoolean>;
|
|
86
|
+
warn: z.ZodDefault<z.ZodBoolean>;
|
|
87
|
+
error: z.ZodDefault<z.ZodBoolean>;
|
|
88
|
+
}, z.core.$strip>;
|
|
89
|
+
}, z.core.$strip>>;
|
|
90
|
+
/**
|
|
91
|
+
* Syslog client observable plugin - sends logs to syslog servers
|
|
92
|
+
*/
|
|
93
|
+
export declare class Plugin extends BSBObservable<InstanceType<typeof Config>> {
|
|
94
|
+
static Config: import("@bsb/base").BSBPluginConfigClass<z.ZodObject<{
|
|
95
|
+
host: z.ZodDefault<z.ZodString>;
|
|
96
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
97
|
+
protocol: z.ZodDefault<z.ZodEnum<{
|
|
98
|
+
udp: "udp";
|
|
99
|
+
tcp: "tcp";
|
|
100
|
+
tls: "tls";
|
|
101
|
+
}>>;
|
|
102
|
+
tls: z.ZodOptional<z.ZodObject<{
|
|
103
|
+
rejectUnauthorized: z.ZodDefault<z.ZodBoolean>;
|
|
104
|
+
ca: z.ZodOptional<z.ZodString>;
|
|
105
|
+
cert: z.ZodOptional<z.ZodString>;
|
|
106
|
+
key: z.ZodOptional<z.ZodString>;
|
|
107
|
+
}, z.core.$strip>>;
|
|
108
|
+
facility: z.ZodDefault<z.ZodNumber>;
|
|
109
|
+
hostname: z.ZodOptional<z.ZodString>;
|
|
110
|
+
appName: z.ZodDefault<z.ZodString>;
|
|
111
|
+
rfc: z.ZodDefault<z.ZodEnum<{
|
|
112
|
+
3164: "3164";
|
|
113
|
+
5424: "5424";
|
|
114
|
+
}>>;
|
|
115
|
+
levels: z.ZodObject<{
|
|
116
|
+
debug: z.ZodDefault<z.ZodBoolean>;
|
|
117
|
+
info: z.ZodDefault<z.ZodBoolean>;
|
|
118
|
+
warn: z.ZodDefault<z.ZodBoolean>;
|
|
119
|
+
error: z.ZodDefault<z.ZodBoolean>;
|
|
120
|
+
}, z.core.$strip>;
|
|
121
|
+
}, z.core.$strip>>;
|
|
122
|
+
private logFormatter;
|
|
123
|
+
private client;
|
|
124
|
+
private isDisposed;
|
|
125
|
+
constructor(config: BSBObservableConstructor<InstanceType<typeof Config>>);
|
|
126
|
+
init(): Promise<void>;
|
|
127
|
+
run(): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Send log to syslog server
|
|
130
|
+
*/
|
|
131
|
+
private sendLog;
|
|
132
|
+
/**
|
|
133
|
+
* Format and send log
|
|
134
|
+
*/
|
|
135
|
+
private writeLog;
|
|
136
|
+
debug(trace: DTrace, pluginName: string, message: string, meta: LogMeta<any>): void;
|
|
137
|
+
info(trace: DTrace, pluginName: string, message: string, meta: LogMeta<any>): void;
|
|
138
|
+
warn(trace: DTrace, pluginName: string, message: string, meta: LogMeta<any>): void;
|
|
139
|
+
error(trace: DTrace, pluginName: string, message: string | BSBError<any>, meta?: LogMeta<any>): void;
|
|
140
|
+
dispose(): void;
|
|
141
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
8
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
12
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
13
|
+
* including the right to create derivative works that are not subject to the terms
|
|
14
|
+
* of the AGPL.
|
|
15
|
+
*
|
|
16
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
17
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
18
|
+
* will be provided upon request.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU Affero General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(o, k2, desc);
|
|
35
|
+
}) : (function(o, m, k, k2) {
|
|
36
|
+
if (k2 === undefined) k2 = k;
|
|
37
|
+
o[k2] = m[k];
|
|
38
|
+
}));
|
|
39
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
+
}) : function(o, v) {
|
|
42
|
+
o["default"] = v;
|
|
43
|
+
});
|
|
44
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
45
|
+
var ownKeys = function(o) {
|
|
46
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
47
|
+
var ar = [];
|
|
48
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
49
|
+
return ar;
|
|
50
|
+
};
|
|
51
|
+
return ownKeys(o);
|
|
52
|
+
};
|
|
53
|
+
return function (mod) {
|
|
54
|
+
if (mod && mod.__esModule) return mod;
|
|
55
|
+
var result = {};
|
|
56
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
57
|
+
__setModuleDefault(result, mod);
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
})();
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
exports.Plugin = exports.Config = exports.SyslogClientConfigSchema = void 0;
|
|
63
|
+
const base_1 = require("@bsb/base");
|
|
64
|
+
const zod_1 = require("zod");
|
|
65
|
+
// @ts-ignore - no types available
|
|
66
|
+
const SyslogClient = __importStar(require("syslog-client"));
|
|
67
|
+
/**
|
|
68
|
+
* Configuration schema for syslog client observable
|
|
69
|
+
*/
|
|
70
|
+
exports.SyslogClientConfigSchema = zod_1.z.object({
|
|
71
|
+
host: zod_1.z.string().default("localhost"),
|
|
72
|
+
port: zod_1.z.number().int().min(1).max(65535).default(514),
|
|
73
|
+
protocol: zod_1.z.enum(["udp", "tcp", "tls"]).default("udp"),
|
|
74
|
+
tls: zod_1.z.object({
|
|
75
|
+
rejectUnauthorized: zod_1.z.boolean().default(true),
|
|
76
|
+
ca: zod_1.z.string().optional(),
|
|
77
|
+
cert: zod_1.z.string().optional(),
|
|
78
|
+
key: zod_1.z.string().optional(),
|
|
79
|
+
}).optional(),
|
|
80
|
+
facility: zod_1.z.number().int().min(0).max(23).default(16), // local0
|
|
81
|
+
hostname: zod_1.z.string().optional(),
|
|
82
|
+
appName: zod_1.z.string().default("bsb-app"),
|
|
83
|
+
rfc: zod_1.z.enum(["3164", "5424"]).default("5424"),
|
|
84
|
+
// Log level filtering
|
|
85
|
+
levels: zod_1.z.object({
|
|
86
|
+
debug: zod_1.z.boolean().default(true),
|
|
87
|
+
info: zod_1.z.boolean().default(true),
|
|
88
|
+
warn: zod_1.z.boolean().default(true),
|
|
89
|
+
error: zod_1.z.boolean().default(true),
|
|
90
|
+
}),
|
|
91
|
+
});
|
|
92
|
+
exports.Config = (0, base_1.createConfigSchema)({
|
|
93
|
+
name: 'observable-syslog',
|
|
94
|
+
description: 'Syslog client observable plugin for forwarding logs to syslog servers',
|
|
95
|
+
version: '9.0.0',
|
|
96
|
+
image: './assets/syslog-icon.png',
|
|
97
|
+
tags: ['syslog', 'logging', 'observable', 'network'],
|
|
98
|
+
}, exports.SyslogClientConfigSchema);
|
|
99
|
+
/**
|
|
100
|
+
* Convert BSB log level to syslog severity
|
|
101
|
+
*/
|
|
102
|
+
function bsbLevelToSyslogSeverity(level) {
|
|
103
|
+
const normalized = level.toLowerCase();
|
|
104
|
+
switch (normalized) {
|
|
105
|
+
case "error":
|
|
106
|
+
return SyslogClient.Severity.Error;
|
|
107
|
+
case "warn":
|
|
108
|
+
case "warning":
|
|
109
|
+
return SyslogClient.Severity.Warning;
|
|
110
|
+
case "info":
|
|
111
|
+
return SyslogClient.Severity.Informational;
|
|
112
|
+
case "debug":
|
|
113
|
+
return SyslogClient.Severity.Debug;
|
|
114
|
+
default:
|
|
115
|
+
return SyslogClient.Severity.Informational;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Syslog client observable plugin - sends logs to syslog servers
|
|
120
|
+
*/
|
|
121
|
+
class Plugin extends base_1.BSBObservable {
|
|
122
|
+
static Config = exports.Config;
|
|
123
|
+
logFormatter = new base_1.LogFormatter();
|
|
124
|
+
client = null;
|
|
125
|
+
isDisposed = false;
|
|
126
|
+
constructor(config) {
|
|
127
|
+
super(config);
|
|
128
|
+
}
|
|
129
|
+
async init() {
|
|
130
|
+
const options = {
|
|
131
|
+
syslogHostname: this.config.hostname || require("os").hostname(),
|
|
132
|
+
appName: this.config.appName,
|
|
133
|
+
facility: this.config.facility,
|
|
134
|
+
rfc: this.config.rfc === "3164" ? SyslogClient.RFC3164 : SyslogClient.RFC5424,
|
|
135
|
+
};
|
|
136
|
+
if (this.config.protocol === "tcp") {
|
|
137
|
+
options.transport = SyslogClient.Transport.Tcp;
|
|
138
|
+
}
|
|
139
|
+
else if (this.config.protocol === "tls") {
|
|
140
|
+
options.transport = SyslogClient.Transport.Tls;
|
|
141
|
+
if (this.config.tls) {
|
|
142
|
+
options.tlsOptions = {
|
|
143
|
+
rejectUnauthorized: this.config.tls.rejectUnauthorized,
|
|
144
|
+
ca: this.config.tls.ca,
|
|
145
|
+
cert: this.config.tls.cert,
|
|
146
|
+
key: this.config.tls.key,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
options.transport = SyslogClient.Transport.Udp;
|
|
152
|
+
}
|
|
153
|
+
this.client = SyslogClient.createClient(this.config.host, options);
|
|
154
|
+
// Handle connection errors
|
|
155
|
+
this.client.on("error", (err) => {
|
|
156
|
+
console.error(`[observable-syslog] Connection error: ${err.message}`);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
async run() {
|
|
160
|
+
// No runtime setup needed
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Send log to syslog server
|
|
164
|
+
*/
|
|
165
|
+
sendLog(severity, message) {
|
|
166
|
+
if (this.isDisposed || !this.client) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
this.client.log(message, { severity }, (err) => {
|
|
171
|
+
if (err) {
|
|
172
|
+
console.error(`[observable-syslog] Failed to send log: ${err.message}`);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
console.error(`[observable-syslog] Send error: ${err.message}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Format and send log
|
|
182
|
+
*/
|
|
183
|
+
writeLog(level, trace, pluginName, message, meta) {
|
|
184
|
+
if (this.isDisposed) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const formattedMessage = this.logFormatter.formatLog(trace, message, meta);
|
|
188
|
+
const fullMessage = `[${pluginName.toUpperCase()}] ${formattedMessage}`;
|
|
189
|
+
const severity = bsbLevelToSyslogSeverity(level);
|
|
190
|
+
this.sendLog(severity, fullMessage);
|
|
191
|
+
}
|
|
192
|
+
// Logging methods
|
|
193
|
+
debug(trace, pluginName, message, meta) {
|
|
194
|
+
if (this.mode === "production" || !this.config.levels.debug) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.writeLog("debug", trace, pluginName, message, meta);
|
|
198
|
+
}
|
|
199
|
+
info(trace, pluginName, message, meta) {
|
|
200
|
+
if (!this.config.levels.info) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
this.writeLog("info", trace, pluginName, message, meta);
|
|
204
|
+
}
|
|
205
|
+
warn(trace, pluginName, message, meta) {
|
|
206
|
+
if (!this.config.levels.warn) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
this.writeLog("warn", trace, pluginName, message, meta);
|
|
210
|
+
}
|
|
211
|
+
error(trace, pluginName, message, meta) {
|
|
212
|
+
if (!this.config.levels.error) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (message instanceof base_1.BSBError) {
|
|
216
|
+
if (message.raw !== null) {
|
|
217
|
+
this.writeLog("error", message.raw.trace, pluginName, message.raw.message, message.raw.meta);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
this.writeLog("error", trace, pluginName, message.message);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
this.writeLog("error", trace, pluginName, message, meta);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
dispose() {
|
|
228
|
+
this.isDisposed = true;
|
|
229
|
+
if (this.client) {
|
|
230
|
+
this.client.close();
|
|
231
|
+
this.client = null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.Plugin = Plugin;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
import { BSBService, BSBServiceConstructor, BSBServiceClient } from "@bsb/base";
|
|
28
|
+
import { Observable } from "@bsb/base";
|
|
29
|
+
import { z } from "zod";
|
|
30
|
+
/**
|
|
31
|
+
* Syslog message structure
|
|
32
|
+
*/
|
|
33
|
+
export declare const SyslogMessageSchema: z.ZodObject<{
|
|
34
|
+
gatewayTime: z.ZodNumber;
|
|
35
|
+
date: z.ZodNumber;
|
|
36
|
+
host: z.ZodString;
|
|
37
|
+
protocol: z.ZodString;
|
|
38
|
+
message: z.ZodString;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
export type SyslogMessage = z.infer<typeof SyslogMessageSchema>;
|
|
41
|
+
/**
|
|
42
|
+
* Configuration schema for syslog server
|
|
43
|
+
*/
|
|
44
|
+
export declare const SyslogServerConfigSchema: z.ZodObject<{
|
|
45
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
46
|
+
address: z.ZodDefault<z.ZodString>;
|
|
47
|
+
exclusive: z.ZodDefault<z.ZodBoolean>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
export type SyslogServerConfig = z.infer<typeof SyslogServerConfigSchema>;
|
|
50
|
+
export declare const Config: import("@bsb/base").BSBPluginConfigClass<z.ZodObject<{
|
|
51
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
52
|
+
address: z.ZodDefault<z.ZodString>;
|
|
53
|
+
exclusive: z.ZodDefault<z.ZodBoolean>;
|
|
54
|
+
}, z.core.$strip>>;
|
|
55
|
+
/**
|
|
56
|
+
* Event schemas for syslog server
|
|
57
|
+
*/
|
|
58
|
+
export declare const EventSchemas: {
|
|
59
|
+
readonly emitEvents: {
|
|
60
|
+
readonly onMessage: {
|
|
61
|
+
input: {
|
|
62
|
+
_bsb: "object";
|
|
63
|
+
properties: {
|
|
64
|
+
readonly gatewayTime: import("@bsb/base").BSBNumberType;
|
|
65
|
+
readonly date: import("@bsb/base").BSBNumberType;
|
|
66
|
+
readonly host: import("@bsb/base").BSBStringType;
|
|
67
|
+
readonly protocol: import("@bsb/base").BSBStringType;
|
|
68
|
+
readonly message: import("@bsb/base").BSBStringType;
|
|
69
|
+
};
|
|
70
|
+
required: string[];
|
|
71
|
+
description?: string;
|
|
72
|
+
optional?: boolean;
|
|
73
|
+
nullable?: boolean;
|
|
74
|
+
};
|
|
75
|
+
description?: string;
|
|
76
|
+
readonly __brand: "fire-and-forget";
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
readonly onEvents: {};
|
|
80
|
+
readonly emitReturnableEvents: {};
|
|
81
|
+
readonly onReturnableEvents: {};
|
|
82
|
+
readonly emitBroadcast: {};
|
|
83
|
+
readonly onBroadcast: {};
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Syslog server service plugin - receives syslog messages
|
|
87
|
+
*/
|
|
88
|
+
export declare class Plugin extends BSBService<InstanceType<typeof Config>, typeof EventSchemas> {
|
|
89
|
+
static Config: import("@bsb/base").BSBPluginConfigClass<z.ZodObject<{
|
|
90
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
91
|
+
address: z.ZodDefault<z.ZodString>;
|
|
92
|
+
exclusive: z.ZodDefault<z.ZodBoolean>;
|
|
93
|
+
}, z.core.$strip>>;
|
|
94
|
+
static EventSchemas: {
|
|
95
|
+
readonly emitEvents: {
|
|
96
|
+
readonly onMessage: {
|
|
97
|
+
input: {
|
|
98
|
+
_bsb: "object";
|
|
99
|
+
properties: {
|
|
100
|
+
readonly gatewayTime: import("@bsb/base").BSBNumberType;
|
|
101
|
+
readonly date: import("@bsb/base").BSBNumberType;
|
|
102
|
+
readonly host: import("@bsb/base").BSBStringType;
|
|
103
|
+
readonly protocol: import("@bsb/base").BSBStringType;
|
|
104
|
+
readonly message: import("@bsb/base").BSBStringType;
|
|
105
|
+
};
|
|
106
|
+
required: string[];
|
|
107
|
+
description?: string;
|
|
108
|
+
optional?: boolean;
|
|
109
|
+
nullable?: boolean;
|
|
110
|
+
};
|
|
111
|
+
description?: string;
|
|
112
|
+
readonly __brand: "fire-and-forget";
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
readonly onEvents: {};
|
|
116
|
+
readonly emitReturnableEvents: {};
|
|
117
|
+
readonly onReturnableEvents: {};
|
|
118
|
+
readonly emitBroadcast: {};
|
|
119
|
+
readonly onBroadcast: {};
|
|
120
|
+
};
|
|
121
|
+
initBeforePlugins?: string[] | undefined;
|
|
122
|
+
initAfterPlugins?: string[] | undefined;
|
|
123
|
+
runBeforePlugins?: string[] | undefined;
|
|
124
|
+
runAfterPlugins?: string[] | undefined;
|
|
125
|
+
private _server;
|
|
126
|
+
constructor(config: BSBServiceConstructor<InstanceType<typeof Config>, typeof EventSchemas>);
|
|
127
|
+
init(): Promise<void>;
|
|
128
|
+
run(obs: Observable): Promise<void>;
|
|
129
|
+
dispose(): void;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Syslog server client - allows other services to subscribe to syslog messages
|
|
133
|
+
*/
|
|
134
|
+
export declare class Client extends BSBServiceClient<Plugin> {
|
|
135
|
+
initBeforePlugins?: string[] | undefined;
|
|
136
|
+
initAfterPlugins?: string[] | undefined;
|
|
137
|
+
runBeforePlugins?: string[] | undefined;
|
|
138
|
+
runAfterPlugins?: string[] | undefined;
|
|
139
|
+
dispose?(): void;
|
|
140
|
+
run?(): Promise<void>;
|
|
141
|
+
readonly pluginName: string;
|
|
142
|
+
init(obs: Observable): Promise<void>;
|
|
143
|
+
}
|