Skip to content

Commit

Permalink
Merge pull request #139 from jmpsec/identify-target-query
Browse files Browse the repository at this point in the history
Show target for on-demand query results
  • Loading branch information
javuto authored Jan 20, 2021
2 parents 8198f80 + f21eb3d commit 4402988
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
23 changes: 20 additions & 3 deletions admin/handlers/json-logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ type ReturnedQueryLogs struct {
Data []QueryLogJSON `json:"data"`
}

// QueryTargetNode to return the target of a on-demand query
type QueryTargetNode struct {
UUID string `json:"uuid"`
Name string `json:"name"`
}

// QueryLogJSON to be used to populate JSON data for a query log
type QueryLogJSON struct {
Created CreationTimes `json:"created"`
Data string `json:"data"`
Created CreationTimes `json:"created"`
Target QueryTargetNode `json:"target"`
Data string `json:"data"`
}

// JSONLogsHandler GET requests for JSON status/result logs by node and environment
Expand Down Expand Up @@ -187,13 +194,23 @@ func (h *HandlersAdmin) JSONQueryLogsHandler(w http.ResponseWriter, r *http.Requ
// Prepare data to be returned
queryLogJSON := []QueryLogJSON{}
for _, q := range queryLogs {
// Get target node
node, err := h.Nodes.GetByUUID(q.UUID)
if err != nil {
node.UUID = q.UUID
node.Localname = ""
}
_c := CreationTimes{
Display: utils.PastFutureTimes(q.CreatedAt),
Timestamp: utils.TimeTimestamp(q.CreatedAt),
}
_l := QueryLogJSON{
Created: _c,
Data: string(q.Data),
Target: QueryTargetNode{
UUID: node.UUID,
Name: node.Localname,
},
Data: string(q.Data),
}
queryLogJSON = append(queryLogJSON, _l)
}
Expand Down
15 changes: 14 additions & 1 deletion admin/templates/queries-logs.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<thead>
<tr>
<th>Created</th>
<th>Target</th>
<th>Data</th>
</tr>
</thead>
Expand Down Expand Up @@ -129,14 +130,26 @@
sort: "created.timestamp"
}
},
{"data" : "target"},
{"data" : "data"}
],
order: [[ 0, "desc" ]],
columnDefs: [
{ width: '10%', targets: 0 },
{
width: '90%',
width: '15%',
targets: 1,
render: function (data, type, row, meta) {
if (type === 'display') {
return '<a href="/node/'+data.uuid+'">' + data.name + '</a>';
} else {
return data;
}
}
},
{
width: '75%',
targets: 2,
render: function (data, type, row, meta) {
if (type === 'display') {
return '<pre>' + JSON.stringify(JSON.parse(data),null,2) + '</pre>';
Expand Down

0 comments on commit 4402988

Please sign in to comment.