-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NPM-3662] Add sestatus to agent flare (#32068)
- Loading branch information
Showing
6 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2024-present Datadog, Inc. | ||
|
||
//go:build linux | ||
|
||
// Package debug contains handlers for debug information global to all of system-probe | ||
package debug | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"os/exec" | ||
"time" | ||
) | ||
|
||
// HandleSelinuxSestatus reports the output of sestatus as an http result | ||
func HandleSelinuxSestatus(w http.ResponseWriter, r *http.Request) { | ||
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) | ||
defer cancel() | ||
|
||
cmd := exec.CommandContext(ctx, "sestatus") | ||
output, err := cmd.CombinedOutput() | ||
|
||
var execError *exec.Error | ||
var exitErr *exec.ExitError | ||
|
||
if err != nil { | ||
// don't 500 for ExitErrors etc, to report "normal" failures to the selinux_sestatus.log file | ||
if !errors.As(err, &execError) && !errors.As(err, &exitErr) { | ||
w.WriteHeader(500) | ||
} | ||
fmt.Fprintf(w, "command failed: %s\n%s", err, output) | ||
return | ||
} | ||
|
||
w.Write(output) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2024-present Datadog, Inc. | ||
|
||
//go:build !linux | ||
|
||
// Package debug contains handlers for debug information global to all of system-probe | ||
package debug | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
) | ||
|
||
// HandleSelinuxSestatus is not supported | ||
func HandleSelinuxSestatus(w http.ResponseWriter, _ *http.Request) { | ||
w.WriteHeader(500) | ||
io.WriteString(w, "HandleSelinuxSestatus is not supported on this platform") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
releasenotes/notes/agent-flare-sestatus-5820cfc79ec91d1f.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Each section from every release note are combined when the | ||
# CHANGELOG.rst is rendered. So the text needs to be worded so that | ||
# it does not depend on any information only available in another | ||
# section. This may mean repeating some details, but each section | ||
# must be readable independently of the other. | ||
# | ||
# Each section note must be formatted as reStructuredText. | ||
--- | ||
enhancements: | ||
- | | ||
Added the output of ``sestatus`` into the Agent flare. This information will appear in ``system-probe/selinux_sestatus.log``. |