@cryptotaxi247 / CoPilot / commits / 2e731766

added velo columns for agent (#33)

* added velo columns for agent * precommit fixes

taylor_socfortress committed Jul 15, 2023 at 10:36 UTC 2e7317667bba9e5f3a466b532ad3c62b9aa1e39d
2 files changed +43
backend/app/models/agents.py
+10
@@ -24,6 +24,8 @@ class AgentMetadata(db.Model):
24 hostname: Column[String] = db.Column(db.String(100))
25 critical_asset: Column[Boolean] = db.Column(db.Boolean, default=False)
26 last_seen: Column[DateTime] = db.Column(db.DateTime)
27 + client_id: Column[String] = db.Column(db.String(100))
28 + client_last_seen: Column[DateTime] = db.Column(db.DateTime)
29
30 def __init__(
31 self,
@@ -33,6 +35,8 @@ class AgentMetadata(db.Model):
35 hostname: str,
36 critical_asset: bool,
37 last_seen: datetime,
38 + client_id: str,
39 + client_last_seen: datetime,
40 ):
41 """
42 Initialize a new instance of the AgentMetadata class.
@@ -43,6 +47,8 @@ class AgentMetadata(db.Model):
47 :param hostname: Hostname of the agent.
48 :param critical_asset: Boolean value indicating if the agent is a critical asset.
49 :param last_seen: Timestamp of when the agent was last seen.
50 + :param client_id: Unique ID for the client stored in Velociraptor.
51 + :param client_last_seen: Timestamp of when the client was last seen in Velociraptor.
52 """
53 self.agent_id = agent_id
54 self.ip_address = ip_address
@@ -50,6 +56,8 @@ class AgentMetadata(db.Model):
56 self.hostname = hostname
57 self.critical_asset = critical_asset
58 self.last_seen = last_seen
59 + self.client_id = client_id
60 + self.client_last_seen = client_last_seen
61
62 def __repr__(self) -> str:
63 """
@@ -99,6 +107,8 @@ class AgentMetadataSchema(ma.Schema):
107 "hostname",
108 "critical_asset",
109 "last_seen",
110 + "client_id",
111 + "client_last_seen",
112 )
113
114
backend/migrations/versions/8b3946f83ac5_add_client_id_and_client_last_seen_for_.py new
+33
@@ -0,0 +1,33 @@
1 +"""Add Client ID and Client Last Seen for Velo Health.
2 +
3 +Revision ID: 8b3946f83ac5
4 +Revises: cc9a9e5057ac
5 +Create Date: 2023-07-15 11:32:51.207081
6 +
7 +"""
8 +import sqlalchemy as sa
9 +from alembic import op
10 +
11 +# revision identifiers, used by Alembic.
12 +revision = "8b3946f83ac5"
13 +down_revision = "cc9a9e5057ac"
14 +branch_labels = None
15 +depends_on = None
16 +
17 +
18 +def upgrade():
19 + # ### commands auto generated by Alembic - please adjust! ###
20 + with op.batch_alter_table("agent_metadata", schema=None) as batch_op:
21 + batch_op.add_column(sa.Column("client_id", sa.String(length=100), nullable=True))
22 + batch_op.add_column(sa.Column("client_last_seen", sa.DateTime(), nullable=True))
23 +
24 + # ### end Alembic commands ###
25 +
26 +
27 +def downgrade():
28 + # ### commands auto generated by Alembic - please adjust! ###
29 + with op.batch_alter_table("agent_metadata", schema=None) as batch_op:
30 + batch_op.drop_column("client_last_seen")
31 + batch_op.drop_column("client_id")
32 +
33 + # ### end Alembic commands ###