1 | const bluebird = require('bluebird'); |
||
0 ignored issues
–
show
Backwards Compatibility
introduced
by
![]() |
|||
2 | const Listener = require('Listener'); |
||
0 ignored issues
–
show
|
|||
3 | const execFile = require('child_process').execFile; |
||
0 ignored issues
–
show
|
|||
4 | var logger; |
||
5 | //private functions |
||
6 | |||
7 | |||
8 | function execAsync(command,args){ |
||
9 | return new bluebird(function(resolve,reject){ |
||
10 | return execFile(command,args,function(error,stdout,stderr){ |
||
11 | if (error){ |
||
12 | resolve(JSON.stringify(error)); |
||
13 | } |
||
14 | resolve(stdout,stderr); |
||
15 | }) |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
16 | }) |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
17 | } |
||
18 | |||
19 | function getpsAux() { |
||
20 | return execAsync('ps',['aux']); |
||
21 | } |
||
22 | |||
23 | function getFree() { |
||
24 | return execAsync('free',[]); |
||
25 | } |
||
26 | |||
27 | function getDF() { |
||
28 | return execAsync('df',[]); |
||
29 | } |
||
30 | |||
31 | function getJournalCTL() { |
||
32 | return execAsync('journalctl',['-o json']); |
||
33 | } |
||
34 | |||
35 | function getROVImageVersion(){ |
||
36 | return execAsync('cat',['/ROV-Suite-version']) |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
37 | } |
||
38 | |||
39 | class About { |
||
0 ignored issues
–
show
|
|||
40 | |||
41 | constructor(name, deps) { |
||
42 | logger = deps.logger; |
||
43 | logger.info("Loaded About plugin"); |
||
44 | |||
45 | this.globalBus = deps.globalEventLoop; // This is the server-side messaging bus. The MCU sends messages to server plugins over this |
||
46 | this.cockpitBus = deps.cockpit; // This is the server<->client messaging bus. This is how the server talks to the browser |
||
47 | this.loopDelays = []; |
||
48 | this.notifications = []; |
||
49 | this.deps=deps; |
||
50 | var self = this; |
||
51 | |||
52 | this.listeners = { |
||
53 | settings: new Listener(self.globalBus, 'settings-change.about', true, function(settings) { |
||
54 | self.settings = settings.about; |
||
55 | }), |
||
56 | |||
57 | loopDelays: new Listener(self.globalBus, 'plugin.host-diagnostics.loopDelay', false, function(delay){ |
||
58 | self.loopDelays.push({timestamp:Date.now(),delay:delay}); |
||
59 | if (self.loopDelays.length==99){ |
||
60 | self.globalBus.emit('notification','The ROV embedded computer has been struggling to process messages.'); |
||
61 | } |
||
62 | if (self.loopDelays.length==100){ |
||
63 | self.loopDelays.shift(); |
||
64 | } |
||
65 | }), |
||
66 | |||
67 | notifications: new Listener(self.globalBus, 'plugin.notification.all-notices', false, function(notices){ |
||
68 | self.notifications=notices; |
||
69 | }), |
||
70 | |||
71 | dumpReport: new Listener(self.cockpitBus, 'plugin.about.dumpReport', false, function(callback) { |
||
72 | var report={} |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
73 | getpsAux() |
||
74 | .then (function(stdout,stderr){ |
||
75 | report.ps=stdout; |
||
76 | trace("ps:"+stdout); |
||
77 | }) |
||
78 | .then (function(){ |
||
79 | report.loopDelays=self.loopDelays; |
||
80 | report.notifications = self.notifications; |
||
81 | report.config=self.deps.config; |
||
82 | }) |
||
83 | .then (getFree) |
||
84 | .then (function(stdout,stderr){ |
||
85 | report.free = stdout; |
||
86 | }) |
||
87 | .then (getDF) |
||
88 | .then (function(stdout,stderr){ |
||
89 | report.df = stdout; |
||
90 | }) |
||
91 | .then (getJournalCTL) |
||
92 | .then (function(stdout,stderr){ |
||
93 | report.journalctl = stdout; |
||
94 | }) |
||
95 | .then (getROVImageVersion) |
||
96 | .then (function(stdout,stderr){ |
||
97 | report.rovImageVersion = stdout; |
||
98 | }) |
||
99 | .then (function(){ |
||
100 | callback(JSON.stringify(report)); |
||
101 | }) |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
102 | }) |
||
103 | } |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
104 | } |
||
105 | |||
106 | start() { |
||
107 | // Enable the listeners! |
||
108 | this.listeners.settings.enable(); |
||
109 | this.listeners.loopDelays.enable(); |
||
110 | this.listeners.notifications.enable(); |
||
111 | this.listeners.dumpReport.enable(); |
||
112 | } |
||
113 | |||
114 | // This is called when the plugin is disabled |
||
115 | stop() { |
||
116 | // Disable listeners |
||
117 | this.listeners.settings.disable(); |
||
118 | this.listeners.loopDelays.disable(); |
||
119 | this.listeners.notifications.disable(); |
||
120 | this.listeners.dumpReprot.disable(); |
||
121 | } |
||
122 | |||
123 | } |
||
124 | |||
125 | module.exports = function(name, deps) { |
||
126 | return new About(name, deps); |
||
127 | }; |