@@ -118,58 +118,61 @@ async function list(){
118
118
docker . listContainers ( opts , function ( err , containers ) {
119
119
// check for changes in status (first run is populating data only)
120
120
let newConArray = [ ] ;
121
- containers . forEach ( c => {
122
- // if label_enable is false then exclude any specifically false labelled containers
123
- if ( LABEL_ENABLE == 'false' && JSON . stringify ( c . Labels ) . includes ( '"monocker.enable":"false"' ) ) {
124
- if ( isFirstRun == true ) {
125
- console . log ( ' - Excluding: ' + c . Names [ 0 ] . replace ( "/" , "" ) ) ;
126
- //send('Excluding: ' + c.Names[0].replace("/",""));
127
- messages += 'Excluding: ' + c . Names [ 0 ] . replace ( "/" , "" ) + "\r\n" ;
128
- }
129
- }
130
- else {
131
- // If label_enable is true, list the specifically included containers
132
- if ( LABEL_ENABLE == 'true' && JSON . stringify ( c . Labels ) . includes ( '"monocker.enable":"true"' ) ) {
133
- if ( isFirstRun == true ) {
134
- console . log ( ' - Monitoring: ' + c . Names [ 0 ] . replace ( "/" , "" ) ) ;
135
- //send('Monitoring: ' + c.Names[0].replace("/",""));
136
- messages += 'Monitoring: ' + c . Names [ 0 ] . replace ( "/" , "" ) + "\r\n" ;
121
+ if ( containers > 0 ) {
122
+ containers . forEach ( c => {
123
+ // if label_enable is false then exclude any specifically false labelled containers
124
+ if ( LABEL_ENABLE == 'false' && JSON . stringify ( c . Labels ) . includes ( '"monocker.enable":"false"' ) ) {
125
+ if ( isFirstRun == true ) {
126
+ console . log ( ' - Excluding: ' + c . Names [ 0 ] . replace ( "/" , "" ) ) ;
127
+ //send('Excluding: ' + c.Names[0].replace("/",""));
128
+ messages += 'Excluding: ' + c . Names [ 0 ] . replace ( "/" , "" ) + "\r\n" ;
137
129
}
138
130
}
139
- // determine if covered by healthcheck
140
- let hcStatus = "" ;
141
- if ( c . Status . includes ( "(healthy)" ) ) hcStatus = "(healthy)"
142
- if ( c . Status . includes ( "(unhealthy)" ) ) hcStatus = "(unhealthy)"
143
- if ( monContainers . includes ( c . Id + "," + c . State + "," + c . Names [ 0 ] + "," + hcStatus ) == false && monContainers . length !== 0 ) {
144
- // exclude exited status if set
145
- if ( EXCLUDE_EXITED == 'true' && c . State . toLocaleLowerCase ( ) == 'exited' ) {
146
- // ignore
131
+ else {
132
+ // If label_enable is true, list the specifically included containers
133
+ if ( LABEL_ENABLE == 'true' && JSON . stringify ( c . Labels ) . includes ( '"monocker.enable":"true"' ) ) {
134
+ if ( isFirstRun == true ) {
135
+ console . log ( ' - Monitoring: ' + c . Names [ 0 ] . replace ( "/" , "" ) ) ;
136
+ //send('Monitoring: ' + c.Names[0].replace("/",""));
137
+ messages += 'Monitoring: ' + c . Names [ 0 ] . replace ( "/" , "" ) + "\r\n" ;
138
+ }
147
139
}
148
- else {
149
- // if only offline is set, then only show state changes that are offline
150
- var output = c . Names [ 0 ] . replace ( "/" , "" ) + ": " + c . State + " " + hcStatus ;
151
- if ( SHA . toLowerCase ( ) == 'true' ) {
152
- output += " " + c . ImageID
140
+ // determine if covered by healthcheck
141
+ let hcStatus = "" ;
142
+ if ( c . Status . includes ( "(healthy)" ) ) hcStatus = "(healthy)"
143
+ if ( c . Status . includes ( "(unhealthy)" ) ) hcStatus = "(unhealthy)"
144
+ if ( monContainers . includes ( c . Id + "," + c . State + "," + c . Names [ 0 ] + "," + hcStatus ) == false && monContainers . length !== 0 ) {
145
+ // exclude exited status if set
146
+ if ( EXCLUDE_EXITED == 'true' && c . State . toLocaleLowerCase ( ) == 'exited' ) {
147
+ // ignore
153
148
}
154
- if ( ONLY_OFFLINE_STATES == 'true' ) {
155
- if ( offlineStates . includes ( c . State ) || offlineStates . includes ( c . State + " " + hcStatus ) ) {
149
+ else {
150
+ // if only offline is set, then only show state changes that are offline
151
+ var output = c . Names [ 0 ] . replace ( "/" , "" ) + ": " + c . State + " " + hcStatus ;
152
+ if ( SHA . toLowerCase ( ) == 'true' ) {
153
+ output += " " + c . ImageID
154
+ }
155
+ if ( ONLY_OFFLINE_STATES == 'true' ) {
156
+ if ( offlineStates . includes ( c . State ) || offlineStates . includes ( c . State + " " + hcStatus ) ) {
157
+ console . log ( " - " + output ) ;
158
+ //send(output);
159
+ messages += output + "\r\n" ;
160
+ }
161
+ }
162
+ else {
156
163
console . log ( " - " + output ) ;
157
164
//send(output);
165
+ console . log ( '*****' + output ) ;
158
166
messages += output + "\r\n" ;
159
167
}
160
168
}
161
- else {
162
- console . log ( " - " + output ) ;
163
- //send(output);
164
- console . log ( '*****' + output ) ;
165
- messages += output + "\r\n" ;
166
- }
167
169
}
170
+ // create new container array
171
+ newConArray . push ( c . Id + "," + c . State + "," + c . Names [ 0 ] + "," + hcStatus ) ;
168
172
}
169
- // create new container array
170
- newConArray . push ( c . Id + "," + c . State + "," + c . Names [ 0 ] + "," + hcStatus ) ;
171
173
}
172
- } ) ;
174
+ ) ;
175
+ }
173
176
if ( isFirstRun == true ) {
174
177
console . log ( " - Currently monitoring " + newConArray . length + " (running) containers" ) ;
175
178
if ( DISABLE_STARTUP_MSG . toLowerCase ( ) != 'true' ) {
0 commit comments