From ac95b764eba9ddca1a4d3a6f2981cc6f3e4658c3 Mon Sep 17 00:00:00 2001 From: Victor Vrantchan Date: Mon, 23 Jan 2017 12:37:03 -0500 Subject: [PATCH] add host_hostname field to distributed query results row (#1081) Add a hostname field to every distributed query result row in websocket response. By doing this calculation on the server, we're hoping to improve the rendering on the frontend client, which currently does the same calculation. Closes #1079 --- server/service/service_campaigns.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/service/service_campaigns.go b/server/service/service_campaigns.go index ff5761d0e5..83e908d0a6 100644 --- a/server/service/service_campaigns.go +++ b/server/service/service_campaigns.go @@ -124,6 +124,14 @@ func (svc service) StreamCampaignResults(ctx context.Context, conn *websocket.Co lastStatus := status.Status + // to improve performance of the frontend rendering the results table, we + // add the "host_hostname" field to every row. + mapHostnameRows := func(hostname string, rows []map[string]string) { + for _, row := range rows { + row["host_hostname"] = hostname + } + } + // Loop, pushing updates to results and expected totals for { select { @@ -131,9 +139,10 @@ func (svc service) StreamCampaignResults(ctx context.Context, conn *websocket.Co // Receive a result and push it over the websocket switch res := res.(type) { case kolide.DistributedQueryResult: + mapHostnameRows(res.Host.HostName, res.Rows) err = conn.WriteJSONMessage("result", res) if err != nil { - fmt.Println("error writing to channel") + svc.logger.Log("msg", "error writing to channel", "err", err) } status.ActualResults++ }