host detail fixes
This commit is contained in:
parent
a9026f037e
commit
408c86f86a
@ -5,6 +5,7 @@ const client = require('../redis');
|
|||||||
|
|
||||||
async function getInfo(data){
|
async function getInfo(data){
|
||||||
let info = await client.HGETALL('host_' + data.host);
|
let info = await client.HGETALL('host_' + data.host);
|
||||||
|
info['host'] = data.host;
|
||||||
|
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
@ -21,24 +22,19 @@ async function listAll(){
|
|||||||
|
|
||||||
|
|
||||||
async function listAllDetail(){
|
async function listAllDetail(){
|
||||||
try{
|
|
||||||
let out = [];
|
let out = [];
|
||||||
let hosts = await listAll();
|
|
||||||
|
|
||||||
for(let host of hosts){
|
for(let host of await listAll()){
|
||||||
out.push(await getInfo({host}));
|
out.push(await getInfo({host}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}catch(error){
|
|
||||||
return new Error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function add(data){
|
async function add(data){
|
||||||
|
|
||||||
try{
|
|
||||||
await client.SADD('hosts', data.host);
|
await client.SADD('hosts', data.host);
|
||||||
await client.HSET('host_' + data.host, 'ip', data.ip);
|
await client.HSET('host_' + data.host, 'ip', data.ip);
|
||||||
await client.HSET('host_' + data.host, 'updated', (new Date).getTime());
|
await client.HSET('host_' + data.host, 'updated', (new Date).getTime());
|
||||||
@ -50,11 +46,7 @@ async function add(data){
|
|||||||
if(data.targetSSL !== undefined){
|
if(data.targetSSL !== undefined){
|
||||||
await client.HSET('host_' + data.host, 'targetssl', !!data.targetSSL);
|
await client.HSET('host_' + data.host, 'targetssl', !!data.targetSSL);
|
||||||
}
|
}
|
||||||
} catch (error){
|
|
||||||
|
|
||||||
return new Error(error);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,13 +15,14 @@ router.get('/:host', async function(req, res){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/', async function(req, res){
|
router.get('/', async function(req, res, next){
|
||||||
try{
|
try{
|
||||||
return res.json({
|
return res.json({
|
||||||
hosts: req.query.detail ? await host.listAllDetail() : await Host.listAll()
|
hosts: req.query.detail ? await Host.listAllDetail() : await Host.listAll()
|
||||||
});
|
});
|
||||||
}catch(error){
|
}catch(error){
|
||||||
return res.status(500).json({message: `ERROR ${error}`});
|
res.status(500)
|
||||||
|
next(error)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user