Last active
October 29, 2015 12:47
-
-
Save ivan-loh/5589abb80ba36c8a5b68 to your computer and use it in GitHub Desktop.
pretty print my server listing
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
'use strict'; | |
const lodash = require('lodash'); | |
const moment = require('moment'); | |
const Table = require('cli-table'); | |
const client = require('servers').client; | |
const config = { | |
port: 44444, | |
key: '', | |
host: '', | |
name: '' | |
}; | |
const servers = new Table({ | |
chars: { | |
'top': '═', 'top-mid': '╤', 'top-left': '╔', 'top-right': '╗', | |
'bottom': '═', 'bottom-mid': '╧', 'bottom-left': '╚', 'bottom-right': '╝', | |
'left': '║', 'left-mid': '╟', | |
'mid': '─', 'mid-mid': '┼', | |
'right': '║', 'right-mid': '╢', | |
'middle': '│' | |
}, | |
head: ['name', 'ip.addr', 'lastseen'], | |
colWidths: [20, 20, 20] | |
}); | |
client(config) | |
.get(function (err, result) { | |
if (err) { return console.error(err); } | |
lodash.chain(result) | |
.sortBy('name') | |
.map(function (e) { | |
e.meta = parseInt(e.meta, 10); | |
e.meta = new Date(e.meta); | |
e.meta = moment(e.meta).fromNow(); | |
e.ip = e.ip.substr(7); | |
return e; | |
}) | |
.forEach(function (e) { | |
servers.push([e.name, e.ip, e.meta]); | |
}) | |
.value(); | |
console.log(servers.toString()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment