Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing query results and osctrl-admin panics #449

Merged
merged 2 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ func (r *RedisManager) SetLogs(logType, hostID, envOrName string, data []byte) e
if err := r.Client.Set(ctx, hKey, data, tExpire).Err(); err != nil {
return fmt.Errorf("%s Set: %s", logType, err)
}
// Make sure we expire the key
if err := r.Client.Expire(ctx, hKey, tExpire).Err(); err != nil {
return fmt.Errorf("%s Expire: %s", logType, err)
}
return nil
}

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