@5minds/node-red-contrib-processcube-elasticsearch 0.3.1 → 0.3.2
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/elastic-search-logger.html +66 -65
- package/elastic-search-logger.js +59 -114
- package/package.json +1 -1
|
@@ -1,75 +1,77 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('elastic-search-logger',{
|
|
2
|
+
RED.nodes.registerType('elastic-search-logger', {
|
|
3
3
|
category: 'config',
|
|
4
4
|
credentials: {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
username: { type: 'text' },
|
|
6
|
+
password: { type: 'password' },
|
|
7
|
+
index: { type: 'text' },
|
|
8
8
|
},
|
|
9
9
|
defaults: {
|
|
10
|
-
name: { value:
|
|
11
|
-
url: { value:
|
|
12
|
-
urlType: { value:
|
|
13
|
-
usernameType: { value:
|
|
14
|
-
passwordType: { value:
|
|
15
|
-
indexType: { value:
|
|
16
|
-
filename: { value:
|
|
17
|
-
maxsize: {
|
|
18
|
-
|
|
10
|
+
name: { value: '' },
|
|
11
|
+
url: { value: 'http://localhost:9200' },
|
|
12
|
+
urlType: { value: 'str' },
|
|
13
|
+
usernameType: { value: 'str' },
|
|
14
|
+
passwordType: { value: 'str' },
|
|
15
|
+
indexType: { value: 'str' },
|
|
16
|
+
filename: { value: 'log-elastic.log', required: true },
|
|
17
|
+
maxsize: {
|
|
18
|
+
value: 1,
|
|
19
|
+
required: true,
|
|
20
|
+
validate: function (v) {
|
|
21
|
+
return v >= 1;
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
maxfiles: {
|
|
25
|
+
value: 2,
|
|
26
|
+
required: true,
|
|
27
|
+
validate: function (v) {
|
|
28
|
+
return v >= 1;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
label: function () {
|
|
33
|
+
return this.name;
|
|
19
34
|
},
|
|
20
|
-
label: function () { return this.name; },
|
|
21
35
|
oneditprepare: function () {
|
|
22
36
|
// URL
|
|
23
|
-
$(
|
|
37
|
+
$('#node-config-input-url').typedInput({
|
|
24
38
|
type: this.urlType,
|
|
25
|
-
types: [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
typeField: "#node-config-input-urlType",
|
|
30
|
-
value: this.url
|
|
31
|
-
})
|
|
39
|
+
types: ['str', 'env'],
|
|
40
|
+
typeField: '#node-config-input-urlType',
|
|
41
|
+
value: this.url,
|
|
42
|
+
});
|
|
32
43
|
|
|
33
44
|
// Username
|
|
34
|
-
$(
|
|
45
|
+
$('#node-config-input-username').typedInput({
|
|
35
46
|
type: this.usernameType,
|
|
36
|
-
types:[
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
typeField: "#node-config-input-usernameType",
|
|
41
|
-
value: this.credentials.username
|
|
42
|
-
})
|
|
47
|
+
types: ['str', 'cred', 'env'],
|
|
48
|
+
typeField: '#node-config-input-usernameType',
|
|
49
|
+
value: this.credentials.username,
|
|
50
|
+
});
|
|
43
51
|
|
|
44
52
|
// Password
|
|
45
|
-
$(
|
|
53
|
+
$('#node-config-input-password').typedInput({
|
|
46
54
|
type: this.passwordType,
|
|
47
|
-
types:[
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
typeField: "#node-config-input-passwordType",
|
|
52
|
-
value: this.credentials.password
|
|
53
|
-
})
|
|
55
|
+
types: ['str', 'cred', 'env'],
|
|
56
|
+
typeField: '#node-config-input-passwordType',
|
|
57
|
+
value: this.credentials.password,
|
|
58
|
+
});
|
|
54
59
|
|
|
55
60
|
// Index
|
|
56
|
-
$(
|
|
61
|
+
$('#node-config-input-index').typedInput({
|
|
57
62
|
type: this.indexType,
|
|
58
|
-
types:[
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
});
|
|
63
|
+
types: ['str', 'env'],
|
|
64
|
+
typeField: '#node-config-input-indexType',
|
|
65
|
+
value: this.credentials.index,
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
});
|
|
67
69
|
</script>
|
|
68
70
|
|
|
69
71
|
<script type="text/html" data-template-name="elastic-search-logger">
|
|
70
72
|
<div class="form-row">
|
|
71
73
|
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
72
|
-
<input type="text" id="node-config-input-name" placeholder="Name"
|
|
74
|
+
<input type="text" id="node-config-input-name" placeholder="Name" />
|
|
73
75
|
</div>
|
|
74
76
|
<div id="elkfields">
|
|
75
77
|
<div class="form-row">
|
|
@@ -77,29 +79,28 @@
|
|
|
77
79
|
</div>
|
|
78
80
|
<div class="form-row" style="padding-left:20px;">
|
|
79
81
|
<label for="node-config-input-url"><i class="fa fa-plug"></i> Elastic URL</label>
|
|
80
|
-
<input type="text" id="node-config-input-url"
|
|
81
|
-
<input type="hidden" id="node-config-input-urlType"
|
|
82
|
+
<input type="text" id="node-config-input-url" />
|
|
83
|
+
<input type="hidden" id="node-config-input-urlType" />
|
|
82
84
|
</div>
|
|
83
85
|
<div class="form-row" style="padding-left:20px;">
|
|
84
86
|
<label for="node-config-input-username"><i class="fa fa-user"></i> Username</label>
|
|
85
|
-
<input type="text" id="node-config-input-username"
|
|
86
|
-
<input type="hidden" id="node-config-input-usernameType"
|
|
87
|
+
<input type="text" id="node-config-input-username" />
|
|
88
|
+
<input type="hidden" id="node-config-input-usernameType" />
|
|
87
89
|
</div>
|
|
88
90
|
<div class="form-row" style="padding-left:20px;">
|
|
89
91
|
<label for="node-config-input-password"><i class="fa fa-key"></i> Password</label>
|
|
90
|
-
<input type="
|
|
91
|
-
<input type="hidden" id="node-config-input-passwordType"
|
|
92
|
+
<input type="text" id="node-config-input-password" />
|
|
93
|
+
<input type="hidden" id="node-config-input-passwordType" />
|
|
92
94
|
</div>
|
|
93
95
|
<div class="form-row" style="padding-left:20px;">
|
|
94
96
|
<label for="node-config-input-index"><i class="fa fa-tag"></i> Index</label>
|
|
95
|
-
<input type="text" id="node-config-input-index"
|
|
96
|
-
<input type="hidden" id="node-config-input-indexType"
|
|
97
|
+
<input type="text" id="node-config-input-index" />
|
|
98
|
+
<input type="hidden" id="node-config-input-indexType" />
|
|
97
99
|
</div>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
</div>
|
|
101
|
+
</script>
|
|
102
|
+
|
|
103
|
+
<script type="text/x-red" data-help-name="elastic-search-logger">
|
|
104
|
+
<p>The configuration for the elastic-search-logger.</p>
|
|
105
|
+
<p>Configurations like the requested URL to Elastic, Username & Password and the Elastic Index.</p>
|
|
106
|
+
</script>
|
package/elastic-search-logger.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
module.exports = function (RED) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
let lock = false;
|
|
5
|
-
|
|
6
4
|
function LogElasticLoggerNode(config) {
|
|
7
5
|
let winston = require('winston');
|
|
8
6
|
let winstonElasticSearch = require('winston-elasticsearch');
|
|
@@ -11,113 +9,73 @@ module.exports = function (RED) {
|
|
|
11
9
|
this.logger = null;
|
|
12
10
|
let transports = [];
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function refresh() {
|
|
20
|
-
if (lock) return;
|
|
21
|
-
|
|
22
|
-
// Elastic settings
|
|
23
|
-
let newUrl = RED.util.evaluateNodeProperty(config.url, config.urlType, this);
|
|
24
|
-
if (newUrl == '') {
|
|
25
|
-
this.error('Elastic search url is not set');
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let newUser = RED.util.evaluateNodeProperty(this.credentials.username, config.usernameType, this);
|
|
30
|
-
if (newUser == '') {
|
|
31
|
-
this.error('Elastic search username is not set');
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let newPassword = RED.util.evaluateNodeProperty(this.credentials.password, config.passwordType, this);
|
|
36
|
-
if (newPassword == '') {
|
|
37
|
-
this.error('Elastic search password is not set');
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let newIndex = RED.util.evaluateNodeProperty(this.credentials.index, config.indexType, this);
|
|
42
|
-
if (newIndex == '') {
|
|
43
|
-
this.error('Elastic search index is not set');
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (newUrl === url && newUser === user && newPassword === password && newIndex === index) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
url = newUrl;
|
|
52
|
-
user = newUser;
|
|
53
|
-
password = newPassword;
|
|
54
|
-
index = newIndex;
|
|
55
|
-
|
|
56
|
-
index = index.toLowerCase();
|
|
57
|
-
if (url) {
|
|
58
|
-
const elasticSearchTransport = new winstonElasticSearch.ElasticsearchTransport({
|
|
59
|
-
clientOpts: {
|
|
60
|
-
node: url,
|
|
61
|
-
auth: {
|
|
62
|
-
username: user,
|
|
63
|
-
password: password,
|
|
64
|
-
},
|
|
65
|
-
ssl: {
|
|
66
|
-
// accept any
|
|
67
|
-
rejectUnauthorized: false,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
transformer: (logData) => setElasticFields(logData, this),
|
|
71
|
-
index: index,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
transports = [elasticSearchTransport];
|
|
75
|
-
|
|
76
|
-
elasticSearchTransport.on('error', (error) => {
|
|
77
|
-
this.error(`Error in elasticSearchTransport caught: ${error.message}`);
|
|
78
|
-
console.error('Error in elasticSearchTransport caught', error);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let logLevels = {
|
|
83
|
-
levels: {
|
|
84
|
-
Error: 0,
|
|
85
|
-
Warning: 1,
|
|
86
|
-
Information: 2,
|
|
87
|
-
Debug: 3,
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const newLogger = new winston.createLogger({
|
|
92
|
-
exitOnError: false,
|
|
93
|
-
level: 'Debug',
|
|
94
|
-
levels: logLevels.levels,
|
|
95
|
-
transports: transports,
|
|
96
|
-
});
|
|
12
|
+
// Elastic settings
|
|
13
|
+
let url = RED.util.evaluateNodeProperty(config.url, config.urlType, this);
|
|
14
|
+
if (url == '') {
|
|
15
|
+
this.error('Elastic search url is not set');
|
|
16
|
+
}
|
|
97
17
|
|
|
98
|
-
|
|
18
|
+
let user = RED.util.evaluateNodeProperty(this.credentials.username, config.usernameType, this);
|
|
19
|
+
if (user == '') {
|
|
20
|
+
this.error('Elastic search username is not set');
|
|
21
|
+
}
|
|
99
22
|
|
|
100
|
-
|
|
101
|
-
|
|
23
|
+
let password = RED.util.evaluateNodeProperty(this.credentials.password, config.passwordType, this);
|
|
24
|
+
if (password == '') {
|
|
25
|
+
this.error('Elastic search password is not set');
|
|
26
|
+
}
|
|
102
27
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
28
|
+
let index = RED.util.evaluateNodeProperty(this.credentials.index, config.indexType, this);
|
|
29
|
+
if (index == '') {
|
|
30
|
+
this.error('Elastic search index is not set');
|
|
31
|
+
}
|
|
107
32
|
|
|
108
|
-
|
|
109
|
-
|
|
33
|
+
index = index.toLowerCase();
|
|
34
|
+
if (url) {
|
|
35
|
+
const elasticSearchTransport = new winstonElasticSearch.ElasticsearchTransport({
|
|
36
|
+
clientOpts: {
|
|
37
|
+
node: url,
|
|
38
|
+
auth: {
|
|
39
|
+
username: user,
|
|
40
|
+
password: password,
|
|
41
|
+
},
|
|
42
|
+
ssl: {
|
|
43
|
+
// accept any
|
|
44
|
+
rejectUnauthorized: false,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
transformer: (logData) => setElasticFields(logData, this),
|
|
48
|
+
index: index,
|
|
49
|
+
});
|
|
110
50
|
|
|
111
|
-
|
|
112
|
-
const intervalId = setInterval(refresh, timeOut);
|
|
51
|
+
transports.push(elasticSearchTransport);
|
|
113
52
|
|
|
114
|
-
|
|
53
|
+
elasticSearchTransport.on('error', (error) => {
|
|
54
|
+
this.error(`Error in elasticSearchTransport caught: ${error.message}`);
|
|
55
|
+
console.error('Error in elasticSearchTransport caught', error);
|
|
56
|
+
});
|
|
115
57
|
}
|
|
116
58
|
|
|
59
|
+
let logLevels = {
|
|
60
|
+
levels: {
|
|
61
|
+
Error: 0,
|
|
62
|
+
Warning: 1,
|
|
63
|
+
Information: 2,
|
|
64
|
+
Debug: 3,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
this.logger = new winston.createLogger({
|
|
68
|
+
exitOnError: false,
|
|
69
|
+
level: 'Debug',
|
|
70
|
+
levels: logLevels.levels,
|
|
71
|
+
transports: transports,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
this.debug('elastic-search logger created');
|
|
75
|
+
|
|
117
76
|
this.on('close', function (removed, done) {
|
|
118
|
-
stopRefreshing();
|
|
119
77
|
// close logger
|
|
120
|
-
if (this.
|
|
78
|
+
if (this.loggger) {
|
|
121
79
|
this.logger.close();
|
|
122
80
|
}
|
|
123
81
|
|
|
@@ -152,20 +110,7 @@ module.exports = function (RED) {
|
|
|
152
110
|
},
|
|
153
111
|
});
|
|
154
112
|
|
|
155
|
-
LogElasticLoggerNode.prototype.addToLog = function
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const tryLog = () => {
|
|
159
|
-
if (!lock && this.logger) {
|
|
160
|
-
this.logger.log(loglevel, msg.payload.message, msg.payload.meta);
|
|
161
|
-
} else if (attempt < 5) {
|
|
162
|
-
attempt++;
|
|
163
|
-
setTimeout(tryLog, 10);
|
|
164
|
-
} else {
|
|
165
|
-
this.error('Failed to log message after multiple attempts due to logger lock.');
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
tryLog();
|
|
113
|
+
LogElasticLoggerNode.prototype.addToLog = function addTolog(loglevel, msg) {
|
|
114
|
+
this.logger.log(loglevel, msg.payload.message, msg.payload.meta);
|
|
170
115
|
};
|
|
171
116
|
};
|