|
|
|
@ -1,13 +1,16 @@ |
|
|
|
|
const moment = require('moment') |
|
|
|
|
|
|
|
|
|
const Agents = () => { |
|
|
|
|
const obj = {} |
|
|
|
|
obj.agents = [] |
|
|
|
|
|
|
|
|
|
obj.addAgent = (os, ip, profile) => { |
|
|
|
|
obj.addAgent = (os, ip, profile, interval) => { |
|
|
|
|
const agent = {} |
|
|
|
|
agent.id = obj.agents.length + 1 |
|
|
|
|
agent.os = os |
|
|
|
|
agent.ip = ip |
|
|
|
|
agent.profile = profile |
|
|
|
|
agent.interval = parseInterval(interval) |
|
|
|
|
agent.last_beacon_date = new Date(Date.now()).toLocaleString() |
|
|
|
|
agent.status = true |
|
|
|
|
obj.agents.push(agent) |
|
|
|
@ -16,9 +19,16 @@ const Agents = () => { |
|
|
|
|
|
|
|
|
|
obj.getAgentById = (agentId) => { |
|
|
|
|
const agent = obj.agents.find(a => a.id === agentId) |
|
|
|
|
return agent |
|
|
|
|
? agent |
|
|
|
|
: null |
|
|
|
|
if (!agent) { |
|
|
|
|
return null |
|
|
|
|
} else { |
|
|
|
|
const lbd = moment(agent.last_beacon_date) |
|
|
|
|
const diff = (lbd.diff(moment(), 'second') * -1) |
|
|
|
|
if (diff > agent.interval) { |
|
|
|
|
agent.status = false |
|
|
|
|
} |
|
|
|
|
return agent |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
obj.updateAgentBeaconTime = (agentId) => { |
|
|
|
@ -51,7 +61,16 @@ const Agents = () => { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
obj.getAllAgents = () => obj.agents |
|
|
|
|
obj.getAllAgents = () => { |
|
|
|
|
obj.agents.forEach(agent => { |
|
|
|
|
const lbd = moment(agent.last_beacon_date) |
|
|
|
|
const diff = (lbd.diff(moment(), 'second') * -1) |
|
|
|
|
if (diff > agent.interval) { |
|
|
|
|
agent.status = false |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
return obj.agents |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return obj |
|
|
|
|
} |
|
|
|
|