Skip to content

Commit

Permalink
Fix for #438 panic retrieving logs
Browse files Browse the repository at this point in the history
  • Loading branch information
javuto committed Jul 6, 2024
1 parent aa310b4 commit 2b89d74
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 42 deletions.
2 changes: 1 addition & 1 deletion admin/handlers/json-logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (h *HandlersAdmin) JSONQueryLogsHandler(w http.ResponseWriter, r *http.Requ
// Iterate through targets to get logs
queryLogJSON := []QueryLogJSON{}
// Get logs
if h.RedisCache != nil {
if h.DBLogger != nil {
queryLogs, err := h.DBLogger.QueryLogs(name)
if err != nil {
log.Printf("error getting logs %v", err)
Expand Down
42 changes: 22 additions & 20 deletions admin/handlers/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,14 +722,15 @@ func (h *HandlersAdmin) QueryLogsHandler(w http.ResponseWriter, r *http.Request)
}
// Prepare template data
templateData := QueryLogsTemplateData{
Title: "Query logs " + query.Name,
EnvUUID: env.UUID,
Metadata: h.TemplateMetadata(ctx, h.ServiceVersion),
LeftMetadata: leftMetadata,
Environments: h.allowedEnvironments(ctx[sessions.CtxUser], envAll),
Platforms: platforms,
Query: query,
QueryTargets: targets,
Title: "Query logs " + query.Name,
EnvUUID: env.UUID,
Metadata: h.TemplateMetadata(ctx, h.ServiceVersion),
LeftMetadata: leftMetadata,
Environments: h.allowedEnvironments(ctx[sessions.CtxUser], envAll),
Platforms: platforms,
Query: query,
QueryTargets: targets,
ServiceConfig: *h.AdminConfig,
}
if err := t.Execute(w, templateData); err != nil {
h.Inc(metricAdminErr)
Expand Down Expand Up @@ -1115,18 +1116,19 @@ func (h *HandlersAdmin) NodeHandler(w http.ResponseWriter, r *http.Request) {
}
// Prepare template data
templateData := NodeTemplateData{
Title: "Node View " + node.Hostname,
EnvUUID: env.UUID,
Metadata: h.TemplateMetadata(ctx, h.ServiceVersion),
LeftMetadata: leftMetadata,
Node: node,
NodeTags: nodeTags,
TagsForNode: tags,
Environments: h.allowedEnvironments(ctx[sessions.CtxUser], envAll),
Platforms: platforms,
Dashboard: dashboardEnabled,
Packs: packs,
Schedule: schedule,
Title: "Node View " + node.Hostname,
EnvUUID: env.UUID,
Metadata: h.TemplateMetadata(ctx, h.ServiceVersion),
LeftMetadata: leftMetadata,
Node: node,
NodeTags: nodeTags,
TagsForNode: tags,
Environments: h.allowedEnvironments(ctx[sessions.CtxUser], envAll),
Platforms: platforms,
Dashboard: dashboardEnabled,
Packs: packs,
Schedule: schedule,
ServiceConfig: *h.AdminConfig,
}
if err := t.Execute(w, templateData); err != nil {
h.Inc(metricAdminErr)
Expand Down
42 changes: 22 additions & 20 deletions admin/handlers/types-templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ type CarvesDetailsTemplateData struct {

// QueryLogsTemplateData for passing data to the query template
type QueryLogsTemplateData struct {
Title string
EnvUUID string
Environments []environments.TLSEnvironment
Platforms []string
Query queries.DistributedQuery
QueryTargets []queries.DistributedQueryTarget
Metadata TemplateMetadata
LeftMetadata AsideLeftMetadata
Title string
EnvUUID string
Environments []environments.TLSEnvironment
Platforms []string
Query queries.DistributedQuery
QueryTargets []queries.DistributedQueryTarget
Metadata TemplateMetadata
LeftMetadata AsideLeftMetadata
ServiceConfig types.JSONConfigurationAdmin
}

// EnvironmentsTemplateData for passing data to the environments template
Expand Down Expand Up @@ -216,16 +217,17 @@ type TagsTemplateData struct {

// NodeTemplateData for passing data to the query template
type NodeTemplateData struct {
Title string
EnvUUID string
Node nodes.OsqueryNode
NodeTags []tags.AdminTag
TagsForNode []tags.AdminTagForNode
Environments []environments.TLSEnvironment
Platforms []string
Metadata TemplateMetadata
LeftMetadata AsideLeftMetadata
Dashboard bool
Schedule environments.ScheduleConf
Packs environments.PacksEntries
Title string
EnvUUID string
Node nodes.OsqueryNode
NodeTags []tags.AdminTag
TagsForNode []tags.AdminTagForNode
Environments []environments.TLSEnvironment
Platforms []string
Metadata TemplateMetadata
LeftMetadata AsideLeftMetadata
Dashboard bool
Schedule environments.ScheduleConf
Packs environments.PacksEntries
ServiceConfig types.JSONConfigurationAdmin
}
6 changes: 6 additions & 0 deletions admin/handlers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ func toJSONConfigurationService(values []settings.SettingValue) types.JSONConfig
if v.Name == settings.JSONAuth {
cfg.Auth = v.String
}
if v.Name == settings.JSONLogger {
cfg.Logger = v.String
}
if v.Name == settings.JSONCarver {
cfg.Carver = v.String
}
if v.Name == settings.JSONSessionKey {
cfg.SessionKey = v.String
}
Expand Down
13 changes: 13 additions & 0 deletions admin/templates/node.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html lang="en">

{{ $metadata := .Metadata }}
{{ $serviceConfig := .ServiceConfig }}

{{ template "page-head" . }}

Expand Down Expand Up @@ -390,6 +391,7 @@
</button>
</div>
</div>
{{ if eq $serviceConfig.Logger "db" }}
<div id="status-table" class="card-body table-responsive">
<table id="tableStatusLogs" class="table table-bordered table-striped" style="width:100%">
<input type="hidden" id="status_refresh_value" value="yes">
Expand All @@ -402,6 +404,11 @@
</thead>
</table>
</div>
{{ else }}
<div class="alert alert-warning" role="alert">
<i class="fas fa-exclamation-triangle"></i> The logger is set to <b>{{ $serviceConfig.Logger }}</b> in the service configuration. No logs to display.
</div>
{{ end }}
</div>
</div>

Expand Down Expand Up @@ -429,6 +436,7 @@
</button>
</div>
</div>
{{ if eq $serviceConfig.Logger "db" }}
<div id="results-table" class="card-body table-responsive">
<table id="tableResultLogs" class="table table-bordered table-striped" style="width:100%">
<input type="hidden" id="result_refresh_value" value="yes">
Expand All @@ -441,6 +449,11 @@
</thead>
</table>
</div>
{{ else }}
<div class="alert alert-warning" role="alert">
<i class="fas fa-exclamation-triangle"></i> The logger is set to <b>{{ $serviceConfig.Logger }}</b> in the service configuration. No logs to display.
</div>
{{ end }}
</div>
</div>

Expand Down
7 changes: 7 additions & 0 deletions admin/templates/queries-logs.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html lang="en">

{{ $metadata := .Metadata }}
{{ $serviceConfig := .ServiceConfig }}

{{ template "page-head" . }}

Expand Down Expand Up @@ -71,6 +72,7 @@
</tbody>
</table>
<br>
{{ if eq $serviceConfig.Logger "db" }}
<table id="tableQueryLogs" class="table table-bordered table-striped" style="width:100%">
<input type="hidden" id="refresh_value" value="yes">
<thead>
Expand All @@ -81,6 +83,11 @@
</tr>
</thead>
</table>
{{ else }}
<div class="alert alert-warning" role="alert">
<i class="fas fa-exclamation-triangle"></i> The logger is set to <b>{{ $serviceConfig.Logger }}</b> in the service configuration.
</div>
{{ end }}

</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (conf *Settings) SetAdminJSON(cfg types.JSONConfigurationAdmin, envID uint)
if err := conf.SetJSON(ServiceAdmin, JSONAuth, cfg.Auth, envID); err != nil {
return err
}
if err := conf.SetJSON(ServiceTLS, JSONLogger, cfg.Logger, envID); err != nil {
if err := conf.SetJSON(ServiceAdmin, JSONLogger, cfg.Logger, envID); err != nil {
return err
}
if err := conf.SetJSON(ServiceAdmin, JSONSessionKey, cfg.SessionKey, envID); err != nil {
Expand Down

0 comments on commit 2b89d74

Please sign in to comment.