-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnode_helper.js
48 lines (42 loc) · 1.2 KB
/
node_helper.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
//
// MMM-NotificationTrigger
//
"use strict"
const NodeHelper = require("node_helper")
const bodyParser = require("body-parser")
const exec = require('child_process').exec
module.exports = NodeHelper.create({
start: function() {
this.expressApp.use(bodyParser.json())
this.expressApp.use(bodyParser.urlencoded({extended: true}))
this.expressApp.post("/webhook", (req, res) => {
console.log("reqpost?", req.body)
this.sendSocketNotification("WEBHOOK", req.body)
res.status(200).send({status: 200})
})
this.expressApp.get("/webhook", (req, res) => {
console.log("reqget?", req.query)
this.sendSocketNotification("WEBHOOK", req.query)
res.status(200).send({status: 200})
})
},
socketNotificationReceived: function(noti, payload) {
if (noti == "EXEC") {
exec(payload.exec, (error, stdout, stderr)=>{
this.sendSocketNotification("EXEC_RESULT", {
"trigger": payload.trigger,
"fire": payload.fire,
"error": error,
"stdout": stdout,
"stderr": stderr
})
if (error) {
console.error(`[NOTTRG] exec error: ${error}`);
return;
}
console.log(`[NOTTRG] stdout: ${stdout}`);
console.log(`[NOTTRG] stderr: ${stderr}`);
})
}
}
})