-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
executable file
·59 lines (55 loc) · 1.31 KB
/
server.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
#!/usr/bin/env node
"use strict"
var os = require('os')
var net = require('net')
var carrier = require('carrier')
var m = new (require('./main'))()
var server = net.createServer(function(conn) {
conn.on("error", function(err) {})
carrier.carry(conn, function parser(line) {
var args = line.split(' ')
var cmd = args.shift()
switch(cmd) {
case 'cap':
conn.write('cap dirtyconfig\n')
break
case 'list':
m.list(function(err, list) {
if(err) {
conn.write('\n')
return
}
conn.write(list.join(' ') + '\n')
})
break
case 'nodes':
conn.write(os.hostname() + '\n.\n')
break
case 'config':
if(args.length < 1) {
conn.write('# Unknown service\n.\n')
break
}
m.config(args[0], function(err, stat) {
if(err) {
conn.write('# Error\n.\n')
return
}
conn.write(stat.join('\n') + '\n.\n')
})
break
case 'fetch':
conn.write('# this node requires the use of the dirtyconfig protocol extension\n.\n')
break
case 'version':
conn.write('munins node on ' + os.hostname() + ' version: mellorimon-0.2\n')
break
case 'quit':
conn.end()
break
default:
conn.write('# Unknown command. Try cap, list, nodes, config, fetch, version or quit\n')
}
})
conn.write('# munin node at ' + os.hostname() + '\n')
}).listen(4949, '::')