@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.
@@ -0,0 +1,148 @@
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.Client = exports.Plugin = exports.EventSchemas = exports.Config = exports.SyslogServerConfigSchema = exports.SyslogMessageSchema = void 0;
30
+ const SyslogServer = require("syslog-server");
31
+ const base_1 = require("@bsb/base");
32
+ const zod_1 = require("zod");
33
+ const base_2 = require("@bsb/base");
34
+ /**
35
+ * Syslog message structure
36
+ */
37
+ exports.SyslogMessageSchema = zod_1.z.object({
38
+ gatewayTime: zod_1.z.number(),
39
+ date: zod_1.z.number(),
40
+ host: zod_1.z.string(),
41
+ protocol: zod_1.z.string(),
42
+ message: zod_1.z.string(),
43
+ });
44
+ /**
45
+ * Configuration schema for syslog server
46
+ */
47
+ exports.SyslogServerConfigSchema = zod_1.z.object({
48
+ port: zod_1.z.number().int().min(1).max(65535).default(514),
49
+ address: zod_1.z.string().default("0.0.0.0"),
50
+ exclusive: zod_1.z.boolean().default(false),
51
+ });
52
+ exports.Config = (0, base_1.createConfigSchema)({
53
+ name: 'service-syslog-server',
54
+ description: 'Syslog server service plugin that receives messages and emits events',
55
+ version: '9.0.0',
56
+ image: './assets/syslog-icon.png',
57
+ tags: ['syslog', 'server', 'service', 'events'],
58
+ }, exports.SyslogServerConfigSchema);
59
+ /**
60
+ * Event schemas for syslog server
61
+ */
62
+ exports.EventSchemas = {
63
+ emitEvents: {
64
+ onMessage: (0, base_2.createFireAndForgetEvent)(base_1.bsb.object({
65
+ gatewayTime: base_1.bsb.number({ description: "Gateway timestamp (epoch ms)" }),
66
+ date: base_1.bsb.number({ description: "Original syslog timestamp (epoch ms)" }),
67
+ host: base_1.bsb.string({ description: "Source host" }),
68
+ protocol: base_1.bsb.string({ description: "Transport protocol" }),
69
+ message: base_1.bsb.string({ description: "Syslog message content" }),
70
+ }, "Syslog message payload"), "Syslog message received from client"),
71
+ },
72
+ onEvents: {},
73
+ emitReturnableEvents: {},
74
+ onReturnableEvents: {},
75
+ emitBroadcast: {},
76
+ onBroadcast: {},
77
+ };
78
+ /**
79
+ * Syslog server service plugin - receives syslog messages
80
+ */
81
+ class Plugin extends base_1.BSBService {
82
+ static Config = exports.Config;
83
+ static EventSchemas = exports.EventSchemas;
84
+ initBeforePlugins;
85
+ initAfterPlugins;
86
+ runBeforePlugins;
87
+ runAfterPlugins;
88
+ _server;
89
+ constructor(config) {
90
+ super({
91
+ ...config,
92
+ eventSchemas: exports.EventSchemas,
93
+ });
94
+ }
95
+ async init() {
96
+ // No initialization needed
97
+ }
98
+ async run(obs) {
99
+ this._server = new SyslogServer();
100
+ this._server.on("message", (value) => {
101
+ obs.log.info("Syslog message from {host}: {message}", {
102
+ host: value.host,
103
+ message: value.message,
104
+ });
105
+ this.events.emitEvent("onMessage", obs, {
106
+ gatewayTime: Date.now(),
107
+ date: new Date(value.date).getTime(),
108
+ host: value.host,
109
+ protocol: value.protocol,
110
+ message: value.message,
111
+ });
112
+ });
113
+ this._server.start({
114
+ port: this.config.port,
115
+ address: this.config.address,
116
+ exclusive: this.config.exclusive,
117
+ });
118
+ obs.log.info("Syslog server listening on {address}:{port}", {
119
+ address: this.config.address,
120
+ port: this.config.port.toString(),
121
+ });
122
+ }
123
+ dispose() {
124
+ if (this._server) {
125
+ this._server.stop();
126
+ this._server = null;
127
+ }
128
+ }
129
+ }
130
+ exports.Plugin = Plugin;
131
+ /**
132
+ * Syslog server client - allows other services to subscribe to syslog messages
133
+ */
134
+ class Client extends base_1.BSBServiceClient {
135
+ initBeforePlugins;
136
+ initAfterPlugins;
137
+ runBeforePlugins;
138
+ runAfterPlugins;
139
+ pluginName = "service-syslog-server";
140
+ async init(obs) {
141
+ // Clients can subscribe to onMessage event to receive syslog messages
142
+ // Example:
143
+ // this.events.onEvent("onMessage", obs, async (obs, message) => {
144
+ // obs.log.info("Received syslog: {message}", { message: message.message });
145
+ // });
146
+ }
147
+ }
148
+ exports.Client = Client;
@@ -0,0 +1,133 @@
1
+ {
2
+ "pluginName": "observable-syslog",
3
+ "version": "9.0.0",
4
+ "events": {},
5
+ "configSchema": {
6
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
7
+ "type": "object",
8
+ "properties": {
9
+ "host": {
10
+ "default": "localhost",
11
+ "type": "string"
12
+ },
13
+ "port": {
14
+ "default": 514,
15
+ "type": "integer",
16
+ "minimum": 1,
17
+ "maximum": 65535
18
+ },
19
+ "protocol": {
20
+ "default": "udp",
21
+ "type": "string",
22
+ "enum": [
23
+ "udp",
24
+ "tcp",
25
+ "tls"
26
+ ]
27
+ },
28
+ "tls": {
29
+ "type": "object",
30
+ "properties": {
31
+ "rejectUnauthorized": {
32
+ "default": true,
33
+ "type": "boolean"
34
+ },
35
+ "ca": {
36
+ "type": "string"
37
+ },
38
+ "cert": {
39
+ "type": "string"
40
+ },
41
+ "key": {
42
+ "type": "string"
43
+ }
44
+ },
45
+ "required": [
46
+ "rejectUnauthorized"
47
+ ],
48
+ "additionalProperties": false
49
+ },
50
+ "facility": {
51
+ "default": 16,
52
+ "type": "integer",
53
+ "minimum": 0,
54
+ "maximum": 23
55
+ },
56
+ "hostname": {
57
+ "type": "string"
58
+ },
59
+ "appName": {
60
+ "default": "bsb-app",
61
+ "type": "string"
62
+ },
63
+ "rfc": {
64
+ "default": "5424",
65
+ "type": "string",
66
+ "enum": [
67
+ "3164",
68
+ "5424"
69
+ ]
70
+ },
71
+ "levels": {
72
+ "type": "object",
73
+ "properties": {
74
+ "debug": {
75
+ "default": true,
76
+ "type": "boolean"
77
+ },
78
+ "info": {
79
+ "default": true,
80
+ "type": "boolean"
81
+ },
82
+ "warn": {
83
+ "default": true,
84
+ "type": "boolean"
85
+ },
86
+ "error": {
87
+ "default": true,
88
+ "type": "boolean"
89
+ }
90
+ },
91
+ "required": [
92
+ "debug",
93
+ "info",
94
+ "warn",
95
+ "error"
96
+ ],
97
+ "additionalProperties": false
98
+ }
99
+ },
100
+ "required": [
101
+ "host",
102
+ "port",
103
+ "protocol",
104
+ "facility",
105
+ "appName",
106
+ "rfc",
107
+ "levels"
108
+ ],
109
+ "additionalProperties": false
110
+ },
111
+ "pluginType": "observable",
112
+ "capabilities": {
113
+ "logging": {
114
+ "debug": true,
115
+ "info": true,
116
+ "warn": true,
117
+ "error": true
118
+ },
119
+ "metrics": {
120
+ "createCounter": false,
121
+ "createGauge": false,
122
+ "createHistogram": false,
123
+ "incrementCounter": false,
124
+ "setGauge": false,
125
+ "observeHistogram": false
126
+ },
127
+ "tracing": {
128
+ "spanStart": false,
129
+ "spanEnd": false,
130
+ "spanError": false
131
+ }
132
+ }
133
+ }
@@ -0,0 +1,122 @@
1
+ {
2
+ "id": "observable-syslog",
3
+ "name": "observable-syslog",
4
+ "version": "9.0.0",
5
+ "description": "Syslog client observable plugin for forwarding logs to syslog servers",
6
+ "category": "observable",
7
+ "tags": [
8
+ "syslog",
9
+ "logging",
10
+ "observable",
11
+ "network"
12
+ ],
13
+ "documentation": [],
14
+ "dependencies": [],
15
+ "image": "./assets/syslog-icon.png",
16
+ "configSchema": {
17
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
18
+ "type": "object",
19
+ "properties": {
20
+ "host": {
21
+ "default": "localhost",
22
+ "type": "string"
23
+ },
24
+ "port": {
25
+ "default": 514,
26
+ "type": "integer",
27
+ "minimum": 1,
28
+ "maximum": 65535
29
+ },
30
+ "protocol": {
31
+ "default": "udp",
32
+ "type": "string",
33
+ "enum": [
34
+ "udp",
35
+ "tcp",
36
+ "tls"
37
+ ]
38
+ },
39
+ "tls": {
40
+ "type": "object",
41
+ "properties": {
42
+ "rejectUnauthorized": {
43
+ "default": true,
44
+ "type": "boolean"
45
+ },
46
+ "ca": {
47
+ "type": "string"
48
+ },
49
+ "cert": {
50
+ "type": "string"
51
+ },
52
+ "key": {
53
+ "type": "string"
54
+ }
55
+ },
56
+ "required": [
57
+ "rejectUnauthorized"
58
+ ],
59
+ "additionalProperties": false
60
+ },
61
+ "facility": {
62
+ "default": 16,
63
+ "type": "integer",
64
+ "minimum": 0,
65
+ "maximum": 23
66
+ },
67
+ "hostname": {
68
+ "type": "string"
69
+ },
70
+ "appName": {
71
+ "default": "bsb-app",
72
+ "type": "string"
73
+ },
74
+ "rfc": {
75
+ "default": "5424",
76
+ "type": "string",
77
+ "enum": [
78
+ "3164",
79
+ "5424"
80
+ ]
81
+ },
82
+ "levels": {
83
+ "type": "object",
84
+ "properties": {
85
+ "debug": {
86
+ "default": true,
87
+ "type": "boolean"
88
+ },
89
+ "info": {
90
+ "default": true,
91
+ "type": "boolean"
92
+ },
93
+ "warn": {
94
+ "default": true,
95
+ "type": "boolean"
96
+ },
97
+ "error": {
98
+ "default": true,
99
+ "type": "boolean"
100
+ }
101
+ },
102
+ "required": [
103
+ "debug",
104
+ "info",
105
+ "warn",
106
+ "error"
107
+ ],
108
+ "additionalProperties": false
109
+ }
110
+ },
111
+ "required": [
112
+ "host",
113
+ "port",
114
+ "protocol",
115
+ "facility",
116
+ "appName",
117
+ "rfc",
118
+ "levels"
119
+ ],
120
+ "additionalProperties": false
121
+ }
122
+ }
@@ -0,0 +1,74 @@
1
+ {
2
+ "pluginName": "service-syslog-server",
3
+ "version": "9.0.0",
4
+ "events": {
5
+ "onMessage": {
6
+ "type": "fire-and-forget",
7
+ "category": "emitEvents",
8
+ "description": "Syslog message received from client",
9
+ "inputSchema": {
10
+ "description": "Syslog message payload",
11
+ "type": "object",
12
+ "properties": {
13
+ "gatewayTime": {
14
+ "description": "Gateway timestamp (epoch ms)",
15
+ "type": "number",
16
+ "format": "double"
17
+ },
18
+ "date": {
19
+ "description": "Original syslog timestamp (epoch ms)",
20
+ "type": "number",
21
+ "format": "double"
22
+ },
23
+ "host": {
24
+ "description": "Source host",
25
+ "type": "string"
26
+ },
27
+ "protocol": {
28
+ "description": "Transport protocol",
29
+ "type": "string"
30
+ },
31
+ "message": {
32
+ "description": "Syslog message content",
33
+ "type": "string"
34
+ }
35
+ },
36
+ "required": [
37
+ "gatewayTime",
38
+ "date",
39
+ "host",
40
+ "protocol",
41
+ "message"
42
+ ]
43
+ },
44
+ "outputSchema": null
45
+ }
46
+ },
47
+ "configSchema": {
48
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
49
+ "type": "object",
50
+ "properties": {
51
+ "port": {
52
+ "default": 514,
53
+ "type": "integer",
54
+ "minimum": 1,
55
+ "maximum": 65535
56
+ },
57
+ "address": {
58
+ "default": "0.0.0.0",
59
+ "type": "string"
60
+ },
61
+ "exclusive": {
62
+ "default": false,
63
+ "type": "boolean"
64
+ }
65
+ },
66
+ "required": [
67
+ "port",
68
+ "address",
69
+ "exclusive"
70
+ ],
71
+ "additionalProperties": false
72
+ },
73
+ "pluginType": "service"
74
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "id": "service-syslog-server",
3
+ "name": "service-syslog-server",
4
+ "version": "9.0.0",
5
+ "description": "Syslog server service plugin that receives messages and emits events",
6
+ "category": "service",
7
+ "tags": [
8
+ "syslog",
9
+ "server",
10
+ "service",
11
+ "events"
12
+ ],
13
+ "documentation": [],
14
+ "dependencies": [],
15
+ "image": "./assets/syslog-icon.png",
16
+ "configSchema": {
17
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
18
+ "type": "object",
19
+ "properties": {
20
+ "port": {
21
+ "default": 514,
22
+ "type": "integer",
23
+ "minimum": 1,
24
+ "maximum": 65535
25
+ },
26
+ "address": {
27
+ "default": "0.0.0.0",
28
+ "type": "string"
29
+ },
30
+ "exclusive": {
31
+ "default": false,
32
+ "type": "boolean"
33
+ }
34
+ },
35
+ "required": [
36
+ "port",
37
+ "address",
38
+ "exclusive"
39
+ ],
40
+ "additionalProperties": false
41
+ }
42
+ }
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@bsb/syslog",
3
+ "version": "9.0.0",
4
+ "license": "(AGPL-3.0-only OR Commercial)",
5
+ "author": {
6
+ "name": "BetterCorp (PTY) Ltd",
7
+ "email": "nick@bettercorp.dev",
8
+ "url": "https://bettercorp.dev/"
9
+ },
10
+ "description": "Syslog server and client for BSB - receive syslog messages and send logs to syslog servers",
11
+ "keywords": [
12
+ "bsb",
13
+ "syslog",
14
+ "server",
15
+ "client",
16
+ "observable",
17
+ "rfc5424"
18
+ ],
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/BetterCorp/better-service-base.git",
22
+ "directory": "plugins/nodejs/syslog"
23
+ },
24
+ "main": "lib/index.js",
25
+ "types": "lib/index.d.ts",
26
+ "files": [
27
+ "lib/**/*",
28
+ "README.md",
29
+ "LICENSE"
30
+ ],
31
+ "scripts": {
32
+ "clean": "bsb-plugin-cli clean",
33
+ "build": "bsb-plugin-cli build",
34
+ "start": "bsb-plugin-cli start",
35
+ "dev": "bsb-plugin-cli dev",
36
+ "test": "bsb-plugin-cli test",
37
+ "publish:client": "bsb client publish",
38
+ "prepublishOnly": "npm run build"
39
+ },
40
+ "peerDependencies": {
41
+ "@bsb/base": "^9.0.0"
42
+ },
43
+ "dependencies": {
44
+ "syslog-client": "^1.1.1",
45
+ "syslog-server": "^1.0.1",
46
+ "zod": "^4.3.6"
47
+ },
48
+ "devDependencies": {
49
+ "@bsb/base": "file:../../../nodejs",
50
+ "@types/node": "^25.0.0",
51
+ "mocha": "^11.0.0",
52
+ "typescript": "^5.9.0"
53
+ },
54
+ "engines": {
55
+ "node": ">=23.0.0",
56
+ "npm": ">=11.0.0"
57
+ },
58
+ "homepage": "https://io.bsbcode.dev/plugins/bsb/syslog"
59
+ }
60
+