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 pathNotification.js
More file actions
executable file
·70 lines (65 loc) · 2.79 KB
/
Notification.js
File metadata and controls
executable file
·70 lines (65 loc) · 2.79 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
61
62
63
64
65
66
67
68
69
70
require('dotenv').config();
const { exec } = require("child_process");
const https = require("https");
const querystring = require('querystring');
const json = require('./config.json');
for(var i = 0; i < json.length; i++) {
var obj = json[i];
function PushNotification(PushTitle, PushText, API)
{
var postdata = querystring.stringify({
'ApiKey': API,
'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);
});
}
if(obj.enabled == 'y'){
const command = 'sudo docker logs --since '+obj.since+' otnode | grep '+obj.searchfor
const header = obj.nodename + ' - '+obj.header
const apiKey = obj.apikey
const os = new os_func();
function os_func() {
this.execCommand = function(command,callback) {
exec(command, (error, stdout, stderr) => {
if (error) {
return;
}else{
callback(stdout);
}
});
}
}
os.execCommand(command, function (stdout) {
PushNotification(header,stdout, apiKey);
});
}else{
console.log(obj.header+' is disabled.');
}
}