@5minds/node-red-contrib-processcube-elasticsearch 0.3.3-feature-ed2d61-m66bsfzh → 0.3.3-feature-6d666d-m66j64bn
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/.processcube/nodered/.config.nodes.json +460 -0
- package/.processcube/nodered/.config.nodes.json.backup +460 -0
- package/.processcube/nodered/.config.runtime.json +3 -0
- package/.processcube/nodered/.config.runtime.json.backup +4 -0
- package/.processcube/nodered/.config.users.json +38 -0
- package/.processcube/nodered/.config.users.json.backup +35 -0
- package/.processcube/nodered/.flows.json.backup +566 -0
- package/.processcube/nodered/.flows_cred.json.backup +3 -0
- package/.processcube/nodered/.sessions.json +1 -0
- package/.processcube/nodered/config.js +20 -0
- package/.processcube/nodered/flows.json +566 -0
- package/.processcube/nodered/flows_cred.json +3 -0
- package/.processcube/nodered/node-red-contrib-processcube-flows.json +0 -0
- package/.processcube/nodered/package.json +13 -0
- package/.processcube/nodered/settings.js +593 -0
- package/Dockerfile +15 -0
- package/docker-compose.yml +38 -0
- package/elastic-search-logger.js +83 -52
- package/elastic-search.html +2 -2
- package/elastic-search.js +6 -4
- package/package.json +1 -1
package/elastic-search-logger.js
CHANGED
|
@@ -1,36 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const winston = require('winston');
|
|
4
|
+
const winstonElasticSearch = require('winston-elasticsearch');
|
|
5
|
+
const { ElasticsearchTransformer } = require('winston-elasticsearch');
|
|
6
|
+
|
|
7
|
+
const logLevels = {
|
|
8
|
+
levels: {
|
|
9
|
+
Error: 0,
|
|
10
|
+
Warning: 1,
|
|
11
|
+
Information: 2,
|
|
12
|
+
Debug: 3
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function setElasticFields(logData) {
|
|
17
|
+
const transformed = ElasticsearchTransformer(logData);
|
|
18
|
+
|
|
19
|
+
transformed['@timestamp'] = logData.timestamp ? logData.timestamp : new Date().toISOString();
|
|
20
|
+
transformed.message = logData.message;
|
|
21
|
+
transformed.messageTemplate = logData.messageTemplate;
|
|
22
|
+
transformed.severity = logData.level;
|
|
23
|
+
transformed.level = logData.level;
|
|
24
|
+
transformed.fields = logData.meta;
|
|
25
|
+
|
|
26
|
+
if (logData.meta['transaction.id']) {
|
|
27
|
+
transformed.transaction = { id: logData.meta['transaction.id'] };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (logData.meta['trace.id']) {
|
|
31
|
+
transformed.trace = {
|
|
32
|
+
id: logData.meta['trace.id']
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (logData.meta['span.id']) {
|
|
37
|
+
transformed.span = {
|
|
38
|
+
id: logData.meta['span.id']
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return transformed;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
1
46
|
module.exports = function (RED) {
|
|
2
|
-
'use strict';
|
|
3
47
|
|
|
4
48
|
function LogElasticLoggerNode(config) {
|
|
5
|
-
let winston = require('winston');
|
|
6
|
-
let winstonElasticSearch = require('winston-elasticsearch');
|
|
7
|
-
|
|
8
49
|
RED.nodes.createNode(this, config);
|
|
9
|
-
|
|
10
|
-
|
|
50
|
+
const node = this;
|
|
51
|
+
|
|
52
|
+
node.logger = null;
|
|
11
53
|
|
|
12
54
|
// Elastic settings
|
|
13
|
-
|
|
55
|
+
const url = RED.util.evaluateNodeProperty(config.url, config.urlType, node);
|
|
14
56
|
if (url == '') {
|
|
15
|
-
|
|
57
|
+
node.error('Elastic search url is not set', {});
|
|
16
58
|
}
|
|
17
59
|
|
|
18
|
-
|
|
60
|
+
const user = RED.util.evaluateNodeProperty(this.credentials.username, config.usernameType, node);
|
|
19
61
|
if (user == '') {
|
|
20
|
-
|
|
62
|
+
node.error('Elastic search username is not set', {});
|
|
21
63
|
}
|
|
22
64
|
|
|
23
|
-
|
|
65
|
+
const password = RED.util.evaluateNodeProperty(this.credentials.password, config.passwordType, node);
|
|
24
66
|
if (password == '') {
|
|
25
|
-
|
|
67
|
+
node.error('Elastic search password is not set', {});
|
|
26
68
|
}
|
|
27
69
|
|
|
28
|
-
let index = RED.util.evaluateNodeProperty(this.credentials.index, config.indexType,
|
|
70
|
+
let index = RED.util.evaluateNodeProperty(this.credentials.index, config.indexType, node);
|
|
29
71
|
if (index == '') {
|
|
30
|
-
|
|
72
|
+
node.error('Elastic search index is not set', {});
|
|
73
|
+
} else {
|
|
74
|
+
index = index.toLowerCase();
|
|
31
75
|
}
|
|
32
76
|
|
|
33
|
-
|
|
77
|
+
let transports = [];
|
|
78
|
+
|
|
34
79
|
if (url) {
|
|
35
80
|
const elasticSearchTransport = new winstonElasticSearch.ElasticsearchTransport({
|
|
36
81
|
clientOpts: {
|
|
@@ -44,26 +89,23 @@ module.exports = function (RED) {
|
|
|
44
89
|
rejectUnauthorized: false,
|
|
45
90
|
},
|
|
46
91
|
},
|
|
47
|
-
transformer: (logData) =>
|
|
92
|
+
transformer: (logData) => {
|
|
93
|
+
try {
|
|
94
|
+
setElasticFields(logData);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
node.error(error, {});
|
|
97
|
+
}
|
|
98
|
+
},
|
|
48
99
|
index: index,
|
|
49
100
|
});
|
|
50
101
|
|
|
51
102
|
transports.push(elasticSearchTransport);
|
|
52
103
|
|
|
53
104
|
elasticSearchTransport.on('error', (error) => {
|
|
54
|
-
|
|
55
|
-
console.error('Error in elasticSearchTransport caught', error);
|
|
105
|
+
node.error(`Error in elasticSearchTransport caught: ${error.message}`, {});
|
|
56
106
|
});
|
|
57
107
|
}
|
|
58
108
|
|
|
59
|
-
let logLevels = {
|
|
60
|
-
levels: {
|
|
61
|
-
Error: 0,
|
|
62
|
-
Warning: 1,
|
|
63
|
-
Information: 2,
|
|
64
|
-
Debug: 3,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
109
|
this.logger = new winston.createLogger({
|
|
68
110
|
exitOnError: false,
|
|
69
111
|
level: 'Debug',
|
|
@@ -71,36 +113,29 @@ module.exports = function (RED) {
|
|
|
71
113
|
transports: transports,
|
|
72
114
|
});
|
|
73
115
|
|
|
116
|
+
this.logger.on('error', (error) => {
|
|
117
|
+
node.error(error, {});
|
|
118
|
+
});
|
|
119
|
+
|
|
74
120
|
this.debug('elastic-search logger created');
|
|
75
121
|
|
|
76
|
-
this.on('close', function (
|
|
122
|
+
this.on('close', function () {
|
|
77
123
|
// close logger
|
|
78
|
-
if (
|
|
79
|
-
|
|
124
|
+
if (node.logger) {
|
|
125
|
+
node.logger.close();
|
|
80
126
|
}
|
|
81
127
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (done) done();
|
|
128
|
+
node.debug('elastic-search logger closed');
|
|
85
129
|
});
|
|
86
130
|
}
|
|
87
131
|
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
transformed.level = logData.level;
|
|
96
|
-
transformed.fields = logData.meta;
|
|
97
|
-
|
|
98
|
-
if (logData.meta['transaction.id']) transformed.transaction = { id: logData.meta['transaction.id'] };
|
|
99
|
-
if (logData.meta['trace.id']) transformed.trace = { id: logData.meta['trace.id'] };
|
|
100
|
-
if (logData.meta['span.id']) transformed.span = { id: logData.meta['span.id'] };
|
|
101
|
-
|
|
102
|
-
return transformed;
|
|
103
|
-
}
|
|
132
|
+
LogElasticLoggerNode.prototype.addToLog = function addTolog(loglevel, msg) {
|
|
133
|
+
try {
|
|
134
|
+
this.logger.log(loglevel, msg.payload.message, msg.payload.meta);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
this.error(error, msg);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
104
139
|
|
|
105
140
|
RED.nodes.registerType('elastic-search-logger', LogElasticLoggerNode, {
|
|
106
141
|
credentials: {
|
|
@@ -109,8 +144,4 @@ module.exports = function (RED) {
|
|
|
109
144
|
index: { type: 'text' },
|
|
110
145
|
},
|
|
111
146
|
});
|
|
112
|
-
|
|
113
|
-
LogElasticLoggerNode.prototype.addToLog = function addTolog(loglevel, msg) {
|
|
114
|
-
this.logger.log(loglevel, msg.payload.message, msg.payload.meta);
|
|
115
|
-
};
|
|
116
147
|
};
|
package/elastic-search.html
CHANGED
package/elastic-search.js
CHANGED
|
@@ -10,7 +10,7 @@ module.exports = function (RED) {
|
|
|
10
10
|
RED.nodes.createNode(this, config);
|
|
11
11
|
const node = this;
|
|
12
12
|
|
|
13
|
-
this.on('input', function (msg
|
|
13
|
+
this.on('input', function (msg) {
|
|
14
14
|
node.logger = RED.nodes.getNode(config.logger);
|
|
15
15
|
|
|
16
16
|
let loglevel = config.loglevel || '';
|
|
@@ -34,10 +34,12 @@ module.exports = function (RED) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
try {
|
|
38
|
+
node.logger.addToLog(level, msg);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
node.error(err);
|
|
41
|
+
}
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
if (done) done();
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
45
|
|
package/package.json
CHANGED