Created
August 8, 2017 23:56
-
-
Save rikkuness/af5c92091585160f2bea6a665bb1e978 to your computer and use it in GitHub Desktop.
Service Status Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dns = require('dns') | |
const net = require('net') | |
let checks = [ | |
{ name: 'NA Login Servers', dns: 'auth1.101.arenanetworks.com', port: 6112 }, | |
{ name: 'EU Login Servers', dns: 'auth2.101.arenanetworks.com', port: 6112 }, | |
] | |
const getStatus = (item) => { | |
return new Promise((resolve, reject) => { | |
dns.resolve4(item.dns, (err, ips) => { | |
Promise.all(ips.map(x => { | |
return new Promise((resolve, reject) => { | |
let s = new net.Socket() | |
s.setTimeout(2000,() => { | |
s.destroy() | |
resolve({ip:x,status:'timeout'}) | |
}) | |
s.connect(item.port, x, () => { | |
s.end() | |
resolve({ip:x,status:'up'}) | |
}) | |
s.on('error', (err) => { | |
s.destroy() | |
resolve({ip:x,status:'error'}) | |
}) | |
}) | |
})).then(results => { | |
item.results = results | |
resolve(item) | |
}).catch(console.error) | |
}) | |
}) | |
} | |
Promise.all(checks.map(x => { return getStatus(x) })).then(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment