-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold_cleanup.js
86 lines (67 loc) · 2.54 KB
/
old_cleanup.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var http = require('http')
var seraServers = [];
function httpRequest(callback, host, port, path){
return http.get({
host: host,
port: port,
path: path
}, function(response){
var body = '';
response.on('data', function(d){
body += d;
});
response.on('end', function(){
var parsed = JSON.parse(body);
callback(parsed)
});
response.on('error', function(e){
callback('error = ' +e)
});
});
};
function getTimedOutServers(response){
var timedOutEvents = response.filter(function(e){
return e.check.name == 'keepalive'
});
for (var i = 0; i < timedOutEvents.length; i++){
httpRequest(getSeraServer, 'localhost', '6789', '/api/v1/servers?hostname=' + timedOutEvents[i].client.address);
};
};
function getSeraServer(response){
console.log(response)
seraServers.push(response);
}
//httpRequest(getTimedOutServers, 'localhost', '4567', '/events')
var sensuEvents = {
host: 'localhost',
port: '6969',
path: '/sensu.json'
}
http.get(sensuEvents, function(response){
var body = '';
response.on('data', function(data){
body += data;
});
response.on('end', function(){
var timedOutEvents = JSON.parse(body).filter(function(e){
return e.check.name == 'keepalive'
});
timedOutEvents.forEach(function(server){
var sera = {
host: 'localhost',
port: '6789',
path: '/api/v1/servers?hostname=' + server.client.address
}
console.log("HELLO event for SERVER: " + server.client.address)
http.get(sera, function(response){
var body = '';
response.on('data', function(data){
body += data;
});
response.on('end', function(){
console.log(body)
})
})
})
})
})