-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (66 loc) · 2.26 KB
/
index.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
71
'use strict'
module.exports = getProtocols
var sys = require('util')
var exec = require('child_process').exec;
function getProtocols(callback) {
var name;
var counter = -1;
var out = [];
exec("sudo birdc show protocols all", function (error, stdout, stderr) {
var lines = stdout.split('\n');
for (var i = 0; i < lines.length; i++) {
var row = lines[i].replace(/\,|\!|\?|\;/g, '').split(' ').filter(Boolean);
if (row[2] == "master") {
name = row[0];
out.push({
"name": row[0],
"proto": row[1],
"table": row[2],
"state": row[3],
"since": row[4],
"info": row[5],
neighbor: {}
});
counter++;
}
switch (row[0]) {
case "Routes:":
out[counter].routes = {
"imported": row[1],
"filtered": row[3],
"exported": row[5],
"preferred": row[7]
};
break;
case "Neighbor":
switch (row[1]) {
case "address:":
out[counter].neighbor.address = row[2];
break;
case "AS:":
out[counter].neighbor.as = row[2];
break;
case "ID:":
out[counter].neighbor.id = row[2];
break;
}
break;
case "Source":
out[counter].sourceAddress = row[2];
break;
case "Route":
if (row[1] == "limit:") {
out[counter].routeLimit = row[2];
}
break;
case "Hold":
out[counter].holdTimer = row[2];
break;
case "Keepalive":
out[counter].keepaliveTimer = row[2];
break;
}
}
callback(out);
});
}