EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
Agent.js
Go to the documentation of this file.
1const db = require("../db");
2
3module.exports = {
4 createAgent,
5 updateHeartbeat,
6 getAgent,
7};
8
9/**
10 *
11 * @param root0
12 * @param root0.tenantId
13 * @param root0.version
14 * @param root0.hostname
15 * @param root0.platform
16 * @param root0.machineId
17 * @param root0.policyId
18 */
19async function createAgent({
20 tenantId,
21 version,
22 hostname,
23 platform,
24 machineId,
25 policyId
26}) {
27 const result = await db.query(
28 `INSERT INTO agents
29 (tenant_id, version, hostname, platform, machine_id, last_seen, policy_id, status)
30 VALUES ($1,$2,$3,$4,$5,NOW(),$6,'enrolled')
31 RETURNING agent_id, agent_uuid`,
32 [tenantId, version, hostname, platform, machineId, policyId]
33 );
34
35 return {
36 agentId: result.rows[0].agent_id,
37 agentUuid: result.rows[0].agent_uuid
38 };
39}
40
41/**
42 *
43 * @param agentUuid
44 */
45async function updateHeartbeat(agentUuid) {
46 await db.query(
47 `UPDATE agents SET last_seen = NOW() WHERE agent_uuid = $1`,
48 [agentUuid]
49 );
50}
51
52/**
53 *
54 * @param agentId
55 */
56async function getAgent(agentId) {
57 const result = await db.query(
58 `SELECT * FROM agents WHERE agent_id = $1`,
59 [agentId]
60 );
61 return result.rows[0];
62}