From fc9228699887131eb7acf556a9776def20fe8d74 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Sat, 10 Aug 2024 18:57:57 +0200 Subject: [PATCH] Added agent uid to the client info so that client and agent can be correlated in prometheus/grafana. --- cmd/agent/sshauthorizedkeys.go | 1 - cmd/converge/prometheus.go | 2 ++ cmd/templaterender/render.go | 1 + pkg/models/client.go | 1 + pkg/server/converge/admin.go | 5 +++-- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/agent/sshauthorizedkeys.go b/cmd/agent/sshauthorizedkeys.go index a518e11..54a6007 100644 --- a/cmd/agent/sshauthorizedkeys.go +++ b/cmd/agent/sshauthorizedkeys.go @@ -113,7 +113,6 @@ func (pubkeys *AuthorizedPublicKeys) monitorAuthorizedKeysFile(authorizedPublicK return } base := filepath.Base(event.Name) - log.Println("CHANGE " + base + " " + authorizedPublicKeysFile + " " + filepath.Base(authorizedPublicKeysFile)) if base == filepath.Base(authorizedPublicKeysFile) { keys, errorKeys := pubkeys.Parse() for _, errorKey := range errorKeys { diff --git a/cmd/converge/prometheus.go b/cmd/converge/prometheus.go index e2cf08e..25dbeaf 100644 --- a/cmd/converge/prometheus.go +++ b/cmd/converge/prometheus.go @@ -64,6 +64,7 @@ var ( []string{"guid", "id", "agentid", + "agentguid", "sessiontype", "username", "hostname", @@ -91,6 +92,7 @@ func clientLabels(client models.Client) prometheus.Labels { "guid": client.Guid, "id": client.ClientId, "agentid": client.PublicId, + "agentguid": client.AgentGuid, "sessiontype": client.SessionType, "username": client.EnvironmentInfo.Username, "hostname": client.EnvironmentInfo.Hostname, diff --git a/cmd/templaterender/render.go b/cmd/templaterender/render.go index 9538c25..0a9d84b 100644 --- a/cmd/templaterender/render.go +++ b/cmd/templaterender/render.go @@ -97,6 +97,7 @@ func main() { client := models.Client{ Guid: strconv.Itoa(rand.Int()), PublicId: "c1", + AgentGuid: "12342342", ClientId: "3", StartTime: time.Now().In(japan), SessionType: "sftp", diff --git a/pkg/models/client.go b/pkg/models/client.go index 3b3bb68..bbd72c7 100644 --- a/pkg/models/client.go +++ b/pkg/models/client.go @@ -9,6 +9,7 @@ type Client struct { Guid string PublicId string ClientId string + AgentGuid string StartTime time.Time SessionType string EnvironmentInfo comms.EnvironmentInfo diff --git a/pkg/server/converge/admin.go b/pkg/server/converge/admin.go index dc2fde5..9ea0d76 100644 --- a/pkg/server/converge/admin.go +++ b/pkg/server/converge/admin.go @@ -44,11 +44,12 @@ func NewAgent(commChannel comms.CommChannel, publicId string, agentInfo comms.En } func NewClient(publicId string, clientConn iowrappers2.ReadWriteAddrCloser, - agentConn net.Conn) *ClientConnection { + agentConn net.Conn, agentGuid string) *ClientConnection { return &ClientConnection{ Client: models.Client{ Guid: strconv.Itoa(rand.Int()), PublicId: publicId, + AgentGuid: agentGuid, ClientId: strconv.Itoa(clientIdGenerator.IncrementAndGet()), StartTime: time.Now(), }, @@ -201,7 +202,7 @@ func (admin *Admin) addClient(publicId string, clientConn iowrappers2.ReadWriteA log.Println("Sending connection information to agent") - client := NewClient(publicId, clientConn, agentConn) + client := NewClient(publicId, clientConn, agentConn, agent.Guid) // Before using this connection for SSH we use it to send client metadata to the // agent