diff --git a/agents/agent.go b/agents/agent.go index 472fa29..d3ae9aa 100644 --- a/agents/agent.go +++ b/agents/agent.go @@ -17,7 +17,7 @@ const( webServerAddr = "127.0.0.1:3333" webSocketAddr = "127.0.0.1:5555" registerURL = "http://" + webServerAddr + "/agents" - wsURL = "ws://" + webSocketAddr + "/ws" + wsURL = "ws://" + webSocketAddr + "/data" ) type Agent struct { diff --git a/gomatic.sql b/gomatic.sql index 31784ca..82da9fa 100644 --- a/gomatic.sql +++ b/gomatic.sql @@ -3,7 +3,7 @@ drop table if exists agents; create table agents ( id UUID default uuid() Primary Key, - agentId int, + agentId int unique, agentName varchar(255), IPv4Address varchar(15), initialContact timestamp, @@ -11,4 +11,4 @@ create table agents ( status Boolean ); -insert into agents (agentId, agentName, initialContact, lastContact) values ( 99, "testAgent", NOW(), NOW()); +insert into agents (IPv4Address, agentId, agentName, initialContact, lastContact) values ( '127.0.0.1', 'testAgent', NOW(), NOW()); diff --git a/main.go b/main.go index 5a7ff8b..44d50de 100644 --- a/main.go +++ b/main.go @@ -49,6 +49,8 @@ type Agent struct { AgentName string `json:"agentName"` InitialContact string `json:"initialContact"` LastContact string `json:"lastContact"` + IPv4Address string `json:"IPv4Address"` + Status string `json:"status"` } func init() { @@ -243,11 +245,12 @@ func createAgent(w http.ResponseWriter, r * http.Request) { agentName := r.FormValue("agentName") agentId := r.FormValue("agentId") + IPv4Address := r.FormValue("IPv4Address") // initalContact := r.FormValue("initialContact") // lastContact := r.FormValue("lastContact") - query := "INSERT INTO agents (agentId, agentName, initialContact, lastContact) VALUES (?, ?, NOW(), NOW())" - _, err = db.Exec(query, agentId, agentName) + query := "INSERT INTO agents (agentId, agentName, IPv4Address, initialContact, lastContact) VALUES (?, ?, ?, NOW(), NOW())" + _, err = db.Exec(query, agentId, agentName, IPv4Address) if err != nil { http.Error(w, "Failed to create agent", http.StatusInternalServerError) return @@ -266,9 +269,10 @@ func updateAgent(w http.ResponseWriter, r *http.Request, agentId string) { agentName := r.FormValue("agentName") lastContact := r.FormValue("lastContact") + IPv4Address := r.FormValue("IPv4Address") - query := "UPDATE agents SET agentName = ?, lastContact = ? where agentId = ?" - _, err = db.Exec(query, agentName, lastContact, agentId) + query := "UPDATE agents SET agentName = ?, IPv4Address= ?, lastContact = ? where agentId = ?" + _, err = db.Exec(query, agentName, IPv4Address, lastContact, agentId) if err != nil { http.Error(w, "Failed to update agent", http.StatusInternalServerError) return @@ -278,7 +282,7 @@ func updateAgent(w http.ResponseWriter, r *http.Request, agentId string) { } func getAgentsFromDB() ([]Agent, error) { - query := "SELECT agentId, agentName, initialContact, lastContact FROM agents" + query := "SELECT agentId, agentName, IPv4Address, initialContact, lastContact FROM agents" rows, err := db.Query(query) if err != nil { return nil, err @@ -288,7 +292,7 @@ func getAgentsFromDB() ([]Agent, error) { var agents []Agent for rows.Next() { var agent Agent - err := rows.Scan(&agent.AgentID, &agent.AgentName, &agent.InitialContact, &agent.LastContact) + err := rows.Scan(&agent.AgentID, &agent.AgentName, &agent.IPv4Address, &agent.InitialContact, &agent.LastContact) if err != nil { return nil, err } diff --git a/templates/index.html b/templates/index.html index b21d8e1..af79f55 100644 --- a/templates/index.html +++ b/templates/index.html @@ -40,10 +40,18 @@
+
+ + +
+
+ + +
diff --git a/templates/partials/agent_list.html b/templates/partials/agent_list.html index 6752e8a..a31202a 100644 --- a/templates/partials/agent_list.html +++ b/templates/partials/agent_list.html @@ -3,6 +3,7 @@ ID Name + IPv4 Address Initial Contact Last Contact Actions @@ -13,6 +14,7 @@ {{.AgentID}} {{.AgentName}} + {{.IPv4Address}} {{.InitialContact}} {{.LastContact}}