@5minds/node-red-contrib-processcube-elasticsearch 0.1.0-develop-8b9e46-m19i7dxw

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,72 @@
1
+ name: Build and Publish
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - '*'
7
+ - '*/*'
8
+
9
+ env:
10
+ CI_TOOLS_VERSION: '^4.2.0'
11
+ # NOTE: Um den Releasezyklus von Alpha nach Beta zu ändern, einfach die nachfolgend deklarierten Env Variablen switchen.
12
+ CI_TOOLS_ALPHA_BRANCH: next
13
+ CI_TOOLS_ALPHA_NPM_TAG: next
14
+ CI_TOOLS_STABLE_BRANCH: main
15
+ # CI_TOOLS_BETA_BRANCH: next
16
+ # CI_TOOLS_BETA_NPM_TAG: next
17
+ #BOX_RELEASE_TAG: 2024-1
18
+
19
+ jobs:
20
+ build_and_publish:
21
+ name: 'Build and publish sources'
22
+ runs-on: ubuntu-latest
23
+ if: "!(contains(github.actor, 'process-engine-ci') || contains(github.actor, 'admin'))"
24
+
25
+ steps:
26
+ - uses: actions/checkout@v4
27
+ with:
28
+ fetch-depth: 0
29
+ token: ${{ secrets.GH_TOKEN }}
30
+
31
+ - name: Use Node.js 20
32
+ uses: actions/setup-node@v4
33
+ with:
34
+ node-version: '20'
35
+ registry-url: 'https://registry.npmjs.org'
36
+
37
+ - name: Install CI Tools
38
+ env:
39
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
40
+ run: npm i -g @5minds/product_ci_tools@${{ env.CI_TOOLS_VERSION }}
41
+
42
+ - name: 'Install Dependencies'
43
+ env:
44
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
45
+ run: npm ci
46
+
47
+ - name: 'Prepare Version'
48
+ if: "!startsWith(github.ref_name, 'renovate')"
49
+ run: ci_tools prepare-version --allow-dirty-workdir
50
+
51
+ - name: 'Commit & Tag Version'
52
+ if: "!startsWith(github.ref_name, 'renovate')"
53
+ env:
54
+ GH_USER: ${{ secrets.GH_USER }}
55
+ GH_TOKEN: ${{ secrets.GH_TOKEN }}
56
+ run: |
57
+ ci_tools commit-and-tag-version --only-on-primary-branches
58
+ ci_tools update-github-release --only-on-primary-branches --use-title-and-text-from-git-tag
59
+
60
+ - name: 'Publish Version'
61
+ if: "!startsWith(github.ref_name, 'renovate')"
62
+ env:
63
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
64
+ run: ci_tools publish-npm-package --create-tag-from-branch-name
65
+
66
+ # - name: Add Box-Release Tag
67
+ # if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/next'
68
+ # env:
69
+ # NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
70
+ # run: |
71
+ # VERSION="$(ci_tools get-version)"
72
+ # npm dist-tag add @5minds/processcube_app_sdk@$VERSION ${{ env.BOX_RELEASE_TAG }}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 5Minds IT-Solutions GmbH & Co. KG
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,52 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('elastic-search-logger',{
3
+ category: 'config',
4
+ credentials: {
5
+ username: {type:"text"},
6
+ password: {type:"password"},
7
+ index: {type:"text"}
8
+ },
9
+ defaults: {
10
+ name: { value: "" },
11
+ url: {value:"http://localhost:9200"},
12
+ filename: { value: "log-elastic.log", required: true },
13
+ maxsize: { value: 1, required: true, validate: function(v) { return v >= 1 } },
14
+ maxfiles: { value: 2, required: true, validate: function(v) { return v >= 1 } },
15
+ },
16
+ label: function() { return this.name; },
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="elastic-search-logger">
21
+ <div class="form-row">
22
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
23
+ <input type="text" id="node-config-input-name" placeholder="Name">
24
+ </div>
25
+ <div id="elkfields">
26
+ <div class="form-row">
27
+ <label style="width:100%;"><span>ElasticSearch options</span></label>
28
+ </div>
29
+ <div class="form-row" style="padding-left:20px;">
30
+ <label for="node-config-input-url"><i class="fa fa-plug"></i> Elastic URL</label>
31
+ <input type="text" id="node-config-input-url">
32
+ </div>
33
+ <div class="form-row" style="padding-left:20px;">
34
+ <label for="node-config-input-username"><i class="fa fa-user"></i> Username</label>
35
+ <input type="text" id="node-config-input-username">
36
+ </div>
37
+ <div class="form-row" style="padding-left:20px;">
38
+ <label for="node-config-input-password"><i class="fa fa-key"></i> Password</label>
39
+ <input type="password" id="node-config-input-password">
40
+ </div>
41
+ <div class="form-row" style="padding-left:20px;">
42
+ <label for="node-config-input-index"><i class="fa fa-tag"></i> Index</label>
43
+ <input type="text" id="node-config-input-index">
44
+ </div>
45
+ </div>
46
+ </script>
47
+
48
+ <script type="text/x-red" data-help-name="elastic-search-logger">
49
+ <p>The configuration for the elastic-search-logger.</p>
50
+ <p>Configurations like the requested URL to Elastic, Username & Password and the Elastic Index.</p>
51
+ </script>
52
+
@@ -0,0 +1,201 @@
1
+ module.exports = function (RED) {
2
+ "use strict";
3
+
4
+ function LogElasticLoggerNode(config) {
5
+ let winston = require('winston');
6
+ let winstonElasticSearch = require('winston-elasticsearch');
7
+ let os = require("os");
8
+ this.hostname = os.hostname();
9
+
10
+ RED.nodes.createNode(this, config);
11
+ this.logger = null;
12
+ let transports = [];
13
+
14
+ // Elastic settings
15
+ let url = config.url;
16
+ let user = this.credentials.username || '';
17
+ let password = this.credentials.password || '';
18
+ let index = this.credentials.index || '';
19
+ if (index == '') {
20
+ this.error("Elastic search index is not set");
21
+ }
22
+ index = index.toLowerCase();
23
+ if (url) {
24
+ const elasticSearchTransport = new winstonElasticSearch.ElasticsearchTransport({
25
+ clientOpts: {
26
+ node: url,
27
+ auth: {
28
+ username: user,
29
+ password: password
30
+ },
31
+ ssl: {
32
+ // accept any
33
+ rejectUnauthorized: false
34
+ }
35
+ },
36
+ transformer: (logData) => setElasticFields(logData, this),
37
+ index: index
38
+ })
39
+
40
+ transports.push(elasticSearchTransport);
41
+
42
+ elasticSearchTransport.on('error', (error) => {
43
+ this.error(`Error in elasticSearchTransport caught: ${error.message}`);
44
+ console.error('Error in elasticSearchTransport caught', error);
45
+ });
46
+ }
47
+
48
+ let logLevels = {
49
+ levels: {
50
+ Error: 0,
51
+ Warning: 1,
52
+ Information: 2,
53
+ Debug: 3
54
+ }
55
+ }
56
+ this.logger = new winston.createLogger({
57
+ exitOnError: false,
58
+ level: 'Debug',
59
+ levels: logLevels.levels,
60
+ transports: transports
61
+ });
62
+
63
+ this.debug("elastic-search logger created");
64
+
65
+ this.on('close', function (removed, done) {
66
+ // close logger
67
+ if (this.loggger) {
68
+ this.logger.close();
69
+ }
70
+
71
+ this.debug("elastic-search logger closed");
72
+
73
+ if (done) done();
74
+ });
75
+ }
76
+
77
+ function setElasticFields(logData, node) {
78
+ logData = mergeFieldsIntoMessage(logData, node);
79
+
80
+ let { ElasticsearchTransformer } = require('winston-elasticsearch');
81
+ const transformed = ElasticsearchTransformer(logData);
82
+ transformed['@timestamp'] = logData.timestamp ? logData.timestamp : new Date().toISOString();
83
+ transformed.message = logData.message;
84
+ transformed.messageTemplate = logData.messageTemplate;
85
+ transformed.severity = logData.level;
86
+ transformed.level = logData.level;
87
+ transformed.fields = logData.meta;
88
+
89
+ if (logData.meta['transaction.id']) transformed.transaction = { id: logData.meta['transaction.id'] };
90
+ if (logData.meta['trace.id']) transformed.trace = { id: logData.meta['trace.id'] };
91
+ if (logData.meta['span.id']) transformed.span = { id: logData.meta['span.id'] };
92
+
93
+ return transformed;
94
+ };
95
+
96
+ RED.nodes.registerType("elastic-search-logger", LogElasticLoggerNode,
97
+ {
98
+ credentials: {
99
+ username: { type: "text" },
100
+ password: { type: "password" },
101
+ index: { type: "text" }
102
+ }
103
+ });
104
+
105
+ LogElasticLoggerNode.prototype.addToLog = function addTolog(loglevel, msg) {
106
+ this.logger.log(loglevel, msg.payload.message, msg.payload.meta);
107
+ }
108
+
109
+ // Extract {fields} from message and add them to meta.
110
+ // Store original message in messageTemplate.
111
+ // Replace {fields} with values in message.
112
+ function mergeFieldsIntoMessage(logData, node) {
113
+ try {
114
+ if (logData.message == null) {
115
+ node.error("Message is null");
116
+ return logData;
117
+ }
118
+
119
+ var fieldNames = extractAllFieldNames(logData);
120
+ addAllFieldsToMeta(logData, fieldNames);
121
+ replaceFieldsInMessage(logData, fieldNames);
122
+ addFixedFieldsToLogData(logData, node);
123
+ } catch (error) {
124
+ const serializedLogData = serializeData(logData);
125
+ node.error(`Error merging fields into message: ${error.message}\nlogData: ${serializedLogData}\nStack trace: ${error.stack}`);
126
+ }
127
+
128
+ return logData;
129
+ }
130
+
131
+ function extractAllFieldNames(logData) {
132
+ var fieldNames = [];
133
+ var message = logData.message;
134
+
135
+ var index = 0;
136
+ while (index != -1 && fieldNames.length < logData.meta?.fields?.length) {
137
+ index = message.indexOf("{", index);
138
+ if (index != -1) {
139
+ var endIndex = message.indexOf("}", index);
140
+ var fieldName = message.substring(index + 1, endIndex);
141
+ fieldNames.push(fieldName);
142
+ index = endIndex;
143
+ }
144
+ }
145
+
146
+ return fieldNames;
147
+ }
148
+
149
+ function addAllFieldsToMeta(logData, fieldNames) {
150
+ for (var i = 0; i < fieldNames.length; i++) {
151
+ var fieldName = fieldNames[i];
152
+ var fieldValue = logData.meta.fields[i];
153
+
154
+ if (typeof fieldValue === 'string') {
155
+ if (fieldValue.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)) {
156
+ logData.meta[fieldName + "_Guid"] = fieldValue;
157
+ } else {
158
+ logData.meta[fieldName + "_String"] = fieldValue;
159
+ }
160
+ } else if (typeof fieldValue === 'number') {
161
+ logData.meta[fieldName + "_Number"] = fieldValue;
162
+ } else if (typeof fieldValue === 'boolean') {
163
+ logData.meta[fieldName + "_Boolean"] = fieldValue;
164
+ } else if (typeof fieldValue === 'object' && fieldValue instanceof Date) {
165
+ logData.meta[fieldName + "_DateTime"] = fieldValue;
166
+ } else {
167
+ logData.meta[fieldName] = fieldValue;
168
+ }
169
+ }
170
+ }
171
+
172
+ function replaceFieldsInMessage(logData, fieldNames) {
173
+ // Replace all field names in message with values from fields
174
+ logData.messageTemplate = logData.message.slice();
175
+ for (var i = 0; i < fieldNames.length; i++) {
176
+ var fieldName = fieldNames[i];
177
+ var fieldValue = logData.meta.fields[i];
178
+ var replacement = typeof fieldValue === 'string' ? "'" + fieldValue + "'" : fieldValue;
179
+ logData.message = logData.message.replace("{" + fieldName + "}", replacement);
180
+ }
181
+
182
+ // Remove fields from meta
183
+ delete logData.meta.fields;
184
+ }
185
+
186
+ function addFixedFieldsToLogData(logData, node) {
187
+ logData.meta['Origin_String'] = 'Node-RED';
188
+ logData.meta['MachineName_String'] = node.hostname;
189
+ }
190
+
191
+ function serializeData(data) {
192
+ return JSON.stringify(data, (key, value) => {
193
+ if (typeof value === 'object' && value !== null && value !== undefined) {
194
+ if (value instanceof Date) {
195
+ return value.toISOString();
196
+ }
197
+ }
198
+ return value;
199
+ }, 2);
200
+ }
201
+ };
@@ -0,0 +1,114 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('elastic-search', {
3
+ category: 'Custom Nodes',
4
+ color: '#E9967A',
5
+ defaults: {
6
+ name: {
7
+ value: ""
8
+ },
9
+ logger: { value: "", type: "elastic-search-logger" },
10
+ complete: {
11
+ value: "false",
12
+ required: true
13
+ },
14
+ loglevel: {
15
+ value: "Debug",
16
+ required: true
17
+ }
18
+ },
19
+ inputs: 1,
20
+ outputs: 0,
21
+ icon: "file.svg",
22
+ align: "right",
23
+ label: function () {
24
+ return this.name || "elastic-search";
25
+ },
26
+ oneditprepare: function () {
27
+ // message
28
+ $("#node-input-typed-complete").typedInput({
29
+ types: ['msg']
30
+ });
31
+
32
+ $("#node-input-typed-complete").typedInput('type', 'msg');
33
+ $("#node-input-typed-complete").typedInput('value', "payload");
34
+ $("#node-input-typed-complete").on('change', function () {
35
+ if ($("#node-input-typed-complete").typedInput('type') === 'msg' &&
36
+ $("#node-input-typed-complete").typedInput('value') === ''
37
+ ) {
38
+ $("#node-input-typed-complete").typedInput('value', 'payload');
39
+ }
40
+ });
41
+
42
+ // loglevel
43
+ $("#node-input-typed-loglevel").typedInput({
44
+ types: [
45
+ 'msg',
46
+ {
47
+ value: "level",
48
+ label: "level",
49
+ options: ["Error", "Warning", "Information", "Debug"]
50
+ }
51
+ ]
52
+ });
53
+
54
+ if (this.loglevel === "Error" ||
55
+ this.loglevel === "Warning" ||
56
+ this.loglevel === "Information" ||
57
+ this.loglevel === "Debug") {
58
+ // fixed level
59
+ $("#node-input-typed-loglevel").typedInput('type', 'level');
60
+ $("#node-input-typed-loglevel").typedInput('value', this.loglevel);
61
+ } else {
62
+ $("#node-input-typed-loglevel").typedInput('type', 'msg');
63
+ $("#node-input-typed-loglevel").typedInput('value', this.loglevel);
64
+ }
65
+ $("#node-input-typed-loglevel").on('change', function () {
66
+ if ($("#node-input-typed-loglevel").typedInput('type') === 'msg') {
67
+ var value = $("#node-input-typed-loglevel").typedInput('value')
68
+ if (value === "Error" || value === "Warning" || value === "Information" || value === "Debug") {
69
+ $("#node-input-typed-loglevel").typedInput('value', 'loglevel');
70
+ }
71
+ }
72
+ });
73
+ },
74
+ oneditsave: function () {
75
+ $("#node-input-complete").val($("#node-input-typed-complete").typedInput('value'));
76
+
77
+ $("#node-input-loglevel").val($("#node-input-typed-loglevel").typedInput('value'));
78
+ }
79
+ });
80
+ </script>
81
+
82
+ <script type="text/x-red" data-template-name="elastic-search">
83
+ <div class="form-row">
84
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
85
+ <input type="text" id="node-input-name" placeholder="Name">
86
+ </div>
87
+ <div class="form-row">
88
+ <label for="node-input-logger"><i class="fa fa-random"></i> Logger</label>
89
+ <input type="text" id="node-input-logger" >
90
+ </div>
91
+ <div class="form-row">
92
+ <label for="node-input-typed-loglevel"><i class="fa fa-list"></i> Log Level</label>
93
+ <input id="node-input-typed-loglevel" type="text">
94
+ <input id="node-input-loglevel" type="hidden">
95
+ </div>
96
+ <div class="form-row">
97
+ <label for="node-input-typed-complete"><i class="fa fa-list"></i> Output</label>
98
+ <input id="node-input-typed-complete" type="text">
99
+ <input id="node-input-complete" type="hidden">
100
+ </div>
101
+ </script>
102
+
103
+ <script type="text/x-red" data-help-name="elastic-search">
104
+ <p>A logging node for Elastic Search using the winston and winston-elastic logging libraries</p>
105
+ <h3>Details</h3>
106
+ <p>Output <code>msg.payload</code> (or <code>msg.&lt;custom path&gt;</code>) or complete <code>msg</code> is used as input of the logged message.</p>
107
+ <p>The Log Level (Error, Warning, Information, Debug) used can be configured in the node or can be set
108
+ by <code>msg.loglevel</code> (or <code>msg.&lt;custom path&gt;</code>).
109
+ If the content is not one of ('Error', 'Warning', 'Information', 'Debug'), 'Debug' will be used as fallback</p>
110
+ <p>If <code>msg.meta</code> is set, the meta info Object will be added to the file and ElasticSearch output as a JSON string.</p>
111
+
112
+ <h3>References</h3>
113
+ <p>This node is based on parts of node-red-contrib-advance-logger</p>
114
+ </script>
@@ -0,0 +1,44 @@
1
+ module.exports = function (RED) {
2
+ "use strict";
3
+
4
+ const Error = "Error"
5
+ const Warning = "Warning"
6
+ const Information = "Information"
7
+ const Debug = "Debug"
8
+
9
+ function LogElasticNode(config) {
10
+ RED.nodes.createNode(this, config);
11
+ const node = this;
12
+
13
+ this.logger = RED.nodes.getNode(config.logger);
14
+
15
+ let loglevel = config.loglevel || "";
16
+
17
+ this.on('input', function (msg, send, done) {
18
+ if (node.logger) {
19
+ let level;
20
+ if (loglevel === Error || loglevel === Warning || loglevel === Information || loglevel === Debug) {
21
+ // fixed level
22
+ level = loglevel;
23
+ } else {
24
+ // get loglevel from message
25
+ try { level = RED.util.getMessageProperty(msg, loglevel); }
26
+ catch (err) {
27
+ level = Debug;
28
+ }
29
+
30
+ if (!(level === Error || level === Warning || level === Information || level === Debug)) {
31
+ // invalid log level, default to debug
32
+ level = Debug;
33
+ }
34
+ }
35
+
36
+ node.logger.addToLog(level, msg);
37
+ }
38
+
39
+ if (done) done();
40
+ });
41
+ }
42
+
43
+ RED.nodes.registerType("elastic-search", LogElasticNode);
44
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@5minds/node-red-contrib-processcube-elasticsearch",
3
+ "version": "0.1.0-develop-8b9e46-m19i7dxw",
4
+ "license": "MIT",
5
+ "description": "Node-RED nodes for Elasticsearch",
6
+ "scripts": {
7
+ "lint": "prettier --write --config ./.prettierrc.json \"**/*.{html,js}\""
8
+ },
9
+ "authors": [
10
+ {
11
+ "name": "Robin Lenz",
12
+ "email": "Robin.Lenz@5Minds.de"
13
+ }
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/5minds/node-red-contrib-processcube-elasticsearch"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/5minds/node-red-contrib-processcube-elasticsearch/issues",
21
+ "email": "processcube@5minds.de"
22
+ },
23
+ "engines": {
24
+ "node": ">=14",
25
+ "npm": ">=8.0.0"
26
+ },
27
+ "node-red": {
28
+ "version": ">=3.1.9",
29
+ "nodes": {
30
+ "elastic-search": "elastic-search.js",
31
+ "elastic-search-logger": "elastic-search-logger.js"
32
+ },
33
+ "examples": "examples"
34
+ },
35
+ "dependencies": {
36
+ "winston": "^3.8.2",
37
+ "winston-elasticsearch": "^0.15.9"
38
+ },
39
+ "keywords": [
40
+ "node-red",
41
+ "processcube",
42
+ "low-code",
43
+ "elasticsearch"
44
+ ]
45
+ }