This repository was archived by the owner on Feb 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.js
More file actions
executable file
·60 lines (57 loc) · 2.27 KB
/
status.js
File metadata and controls
executable file
·60 lines (57 loc) · 2.27 KB
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
53
54
55
56
57
58
59
60
const { exec } = require("child_process");
require('dotenv').config();
var https = require("https");
var querystring = require('querystring');
var nodeCheck = "sudo docker ps --quiet"
var statPull = "sudo docker stats --no-stream otnode"
function PushNotification(PushTitle, PushText)
{
var apiKey = process.env.APIKEY
var postdata = querystring.stringify({
'ApiKey': apiKey,
'PushTitle': PushTitle,
'PushText': PushText,
});
var options = {
hostname: 'www.notifymydevice.com',
port: 443,
path: '/push?',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postdata.length
}
};
callback = function (response) {
var str = '';
//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been recieved, so we just print it out here
response.on('end', function () {
console.log('Response: ' + str);
});
}
var req = https.request(options, callback);
req.write(postdata);
req.end();
req.on('error', function (e) {
Log(e);
});
}
exec(nodeCheck, (error, found, stderr) => {
if(found){
exec(statPull, (error, stats, stderr) => {
if(error){
PushNotification(process.env.NODENAME + " status check failed.","Failed to pull stats.");
}else{
PushNotification(process.env.NODENAME + " status check.",stats);
}
});
}else if(error){
PushNotification(process.env.NODENAME + " status check failed.","Failed to get running state.");
}else{
PushNotification(process.env.NODENAME + " status check.","Container is not running.");
}
});