@@ -17,7 +17,7 @@ const server = http.createServer(requestListener);
17
17
server . listen ( port , host , ( ) => { } ) ;
18
18
19
19
// main program
20
- let docker = new Docker ( ) ;
20
+ let docker = new Docker ( { socketPath : '/var/run/docker.sock' } ) ;
21
21
// var docker = new Docker({
22
22
// protocol: 'http', //you can enforce a protocol
23
23
// host: '192.168.1.135',
@@ -103,7 +103,7 @@ async function send(message) {
103
103
104
104
async function list ( ) {
105
105
let opts ;
106
-
106
+ let messages = "" ;
107
107
if ( LABEL_ENABLE == 'true' ) {
108
108
opts = {
109
109
"filters" : '{"label": ["monocker.enable=true"]}'
@@ -123,15 +123,17 @@ async function list(){
123
123
if ( LABEL_ENABLE == 'false' && JSON . stringify ( c . Labels ) . includes ( '"monocker.enable":"false"' ) ) {
124
124
if ( isFirstRun == true ) {
125
125
console . log ( ' - Excluding: ' + c . Names [ 0 ] . replace ( "/" , "" ) ) ;
126
- send ( 'Excluding: ' + c . Names [ 0 ] . replace ( "/" , "" ) ) ;
126
+ //send('Excluding: ' + c.Names[0].replace("/",""));
127
+ messages += 'Excluding: ' + c . Names [ 0 ] . replace ( "/" , "" ) + "\r\n" ;
127
128
}
128
129
}
129
130
else {
130
131
// If label_enable is true, list the specifically included containers
131
132
if ( LABEL_ENABLE == 'true' && JSON . stringify ( c . Labels ) . includes ( '"monocker.enable":"true"' ) ) {
132
133
if ( isFirstRun == true ) {
133
134
console . log ( ' - Monitoring: ' + c . Names [ 0 ] . replace ( "/" , "" ) ) ;
134
- send ( 'Monitoring: ' + c . Names [ 0 ] . replace ( "/" , "" ) ) ;
135
+ //send('Monitoring: ' + c.Names[0].replace("/",""));
136
+ messages += 'Monitoring: ' + c . Names [ 0 ] . replace ( "/" , "" ) + "\r\n" ;
135
137
}
136
138
}
137
139
// determine if covered by healthcheck
@@ -152,12 +154,15 @@ async function list(){
152
154
if ( ONLY_OFFLINE_STATES == 'true' ) {
153
155
if ( offlineStates . includes ( c . State ) || offlineStates . includes ( c . State + " " + hcStatus ) ) {
154
156
console . log ( " - " + output ) ;
155
- send ( output ) ;
157
+ //send(output);
158
+ messages += output + "\r\n" ;
156
159
}
157
160
}
158
161
else {
159
162
console . log ( " - " + output ) ;
160
- send ( output ) ;
163
+ //send(output);
164
+ console . log ( '*****' + output ) ;
165
+ messages += output + "\r\n" ;
161
166
}
162
167
}
163
168
}
@@ -168,7 +173,8 @@ async function list(){
168
173
if ( isFirstRun == true ) {
169
174
console . log ( " - Currently monitoring " + newConArray . length + " (running) containers" ) ;
170
175
if ( DISABLE_STARTUP_MSG . toLowerCase ( ) != 'true' ) {
171
- send ( "Currently monitoring " + newConArray . length + " (running) containers" ) ;
176
+ //send("Currently monitoring " + newConArray.length + " (running) containers");
177
+ messages += "Currently monitoring " + newConArray . length + " (running) containers" + "\r\n" ;
172
178
}
173
179
isFirstRun = false ;
174
180
}
@@ -184,11 +190,19 @@ async function list(){
184
190
output += " " + c . ImageID
185
191
}
186
192
console . log ( " - " + output ) ;
187
- send ( output )
193
+ //send(output)
194
+ messages += output + "\r\n" ;
188
195
}
189
196
} ) ;
190
197
}
191
198
199
+ // do final send of any messages generated
200
+ //send(messages.length);
201
+ if ( messages . length != 0 ) {
202
+ send ( messages ) ;
203
+ }
204
+ // let now = new Date();
205
+ // send('tick: ' + now.toLocaleString());
192
206
// assign new array to be current array state
193
207
monContainers = newConArray ;
194
208
} , Promise . resolve ( 0 ) ) ;
@@ -203,6 +217,7 @@ async function run(){
203
217
runClock = setInterval ( run , ( PERIOD * 1000 ) ) ;
204
218
}
205
219
220
+
206
221
console . log ( `Monitoring started
207
222
- Messaging platform: ` + MESSAGE_PLATFORM . split ( "@" ) [ 0 ] + `
208
223
- Polling period: ` + PERIOD + ` seconds
@@ -215,12 +230,13 @@ console.log(`Monitoring started
215
230
console . log ( )
216
231
if ( DISABLE_STARTUP_MSG . toLowerCase ( ) != 'true' ) {
217
232
send ( `Monitoring started
218
- - Messaging platform: ` + MESSAGE_PLATFORM . split ( "@" ) [ 0 ] + `
219
- - Only offline state monitoring: ` + ONLY_OFFLINE_STATES + `
220
- - Only include labelled containers: ` + LABEL_ENABLE + `
221
- - Do not monitor 'Exited': ` + EXCLUDE_EXITED + `
222
- - Disable Startup Messages: ` + DISABLE_STARTUP_MSG + `
223
- - Display SHA ID: ` + SHA ) ;
233
+ -- Messaging platform: ` + MESSAGE_PLATFORM . split ( "@" ) [ 0 ] + `
234
+ -- Polling period: ` + PERIOD + ` seconds` + `
235
+ -- Only offline state monitoring: ` + ONLY_OFFLINE_STATES + `
236
+ -- Only include labelled containers: ` + LABEL_ENABLE + `
237
+ -- Do not monitor 'Exited': ` + EXCLUDE_EXITED + `
238
+ -- Disable Startup Messages: ` + DISABLE_STARTUP_MSG + `
239
+ -- Display SHA ID: ` + SHA ) ;
224
240
}
225
241
226
242
// start processing
0 commit comments