-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInspect.js
52 lines (47 loc) · 1.87 KB
/
Inspect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var noContainer=/Error: No such image or container/;
module.exports = function(RED) {
var child_process=require("child_process");
var StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder('utf8');
function InspectNode(config) {
RED.nodes.createNode(this,config);
var node = this;
this.on('input', function(msg) {
var container=msg.payload.Service.toLowerCase()+"_"+msg.payload.S_Tag+"_"+msg.payload.C_Tag;
cmd="docker inspect " +container;
console.log(cmd);
var strOutcome="";
child_process.exec(cmd,function(error,stdout,stderr){
if(error!=null){
console.log(stderr);
strOutcome=stderr;
}else{
console.log(stdout);
strOutcome=stdout;
}
console.log("----------");
console.log(strOutcome);
console.log("----------");
if(noContainer.test(strOutcome)){
console.log("didn't exist");
msg.payload.container="None";
}else{
console.log("did exist");
var jsonOutcome=JSON.parse(strOutcome);
var Running=jsonOutcome[0].State.Running;
console.log(jsonOutcome);
if(msg.payload.fullStatus==true){
msg.payload.status=jsonOutcome;
}
if(Running)
msg.payload.container="Running";
else
msg.payload.container="Stopped";
console.log(Running);
}
node.send(msg);
});
});
}
RED.nodes.registerType("inspect",InspectNode);
}