-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMMM-ServerStatus.js
70 lines (58 loc) · 1.43 KB
/
MMM-ServerStatus.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Module.register("MMM-ServerStatus", {
defaults: {
pingInterval: 15, // 15 second intervals
loadDelay: 0,
hosts: [
{
name: "localhost",
ip: "127.0.0.1"
}
],
templateName: "default",
group: "default",
tableClass: "small",
upText: "UP",
downText: "DOWN"
},
// Storage for ping results
pingResults: null,
// Define required scripts.
getStyles: function () {
return ["font-awesome.css", this.file("templates/" + this.config.templateName + ".css")];
},
start: function () {
// Schedule first ping(s)
setTimeout(() => {
this.getPings();
}, this.config.loadDelay * 1000);
},
getPings() {
this.sendSocket
// Send notification and config to request pings from node helper
this.sendSocketNotification("MMM-SERVERSTATUS_GET_PINGS", {
group: this.config.group,
hosts: this.config.hosts,
})
// Schedule next update
setTimeout(() => {
this.getPings();
}, this.config.pingInterval * 1000);
},
socketNotificationReceived: function (notification, data) {
// On receiving pings, show the results (if they're for this group)
if (notification === "MMM-SERVERSTATUS_PINGS_" + this.config.group) {
this.pingResults = data.pingResults;
// Refresh module display
this.updateDom();
}
},
getTemplate: function () {
return `templates/${this.config.templateName}.njk`;
},
getTemplateData: function () {
return {
config: this.config,
pingResults: this.pingResults
};
}
});