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

Make windows drive range configurable #450

Merged
merged 1 commit into from
Oct 25, 2022
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 api/graylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func UpdateRegistration(httpClient *http.Client, checksum string, ctx *context.C

if ctx.UserConfig.SendStatus {
metrics := &graylog.MetricsRequest{
Disks75: common.GetFileSystemList75(),
Disks75: common.GetFileSystemList75(ctx.UserConfig.WindowsDriveRange),
CpuIdle: common.GetCpuIdle(),
Load1: common.GetLoad1(),
}
Expand Down
3 changes: 3 additions & 0 deletions cfgfile/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type SidecarConfig struct {
CollectorBinariesWhitelist []string `config:"collector_binaries_whitelist"`
CollectorBinariesAccesslist []string `config:"collector_binaries_accesslist"`
Tags []string `config:"tags"`
WindowsDriveRange string `config:"windows_drive_range"`
}

// Default Sidecar configuration
Expand Down Expand Up @@ -70,6 +71,7 @@ collector_binaries_accesslist:
- "/usr/bin/nxlog"
- "/opt/nxlog/bin/nxlog"
tags: []
windows_drive_range: ""
`

// Windows specific options. Gets merged over `CommonDefaults`
Expand All @@ -87,4 +89,5 @@ collector_binaries_accesslist:
- "C:\\Program Files\\Heartbeat\\heartbeat.exe"
- "C:\\Program Files\\Auditbeat\\auditbeat.exe"
- "C:\\Program Files (x86)\\nxlog\\nxlog.exe"
windows_drive_range: "CDEFGHIJKLMNOPQRSTUVWXYZ"
`
8 changes: 4 additions & 4 deletions common/sigar.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ func GetCpuIdle() float64 {
return cpu.LastCpuTimes.IdlePercent * 100
}

func GetFileSystemList75() []string {
func GetFileSystemList75(windowsDriveRange string) []string {
result := []string{}
volumes := []sigar.FileSystem{}

if runtime.GOOS == "windows" {
volumes = getWindowsDrives()
volumes = getWindowsDrives(windowsDriveRange)
} else {
fslist := sigar.FileSystemList{}
fslist.Get()
Expand Down Expand Up @@ -138,8 +138,8 @@ func GetLoad1() float64 {
return avg.One
}

func getWindowsDrives() (drives []sigar.FileSystem) {
for _, drive := range "CDEFGHIJKLMNOPQRSTUVWXYZ" {
func getWindowsDrives(windowsDriveRange string) (drives []sigar.FileSystem) {
for _, drive := range windowsDriveRange {
dirName := string(drive) + ":\\"
dirHandle, err := os.Open(dirName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why we even have to open the drive to get the metrics 🤷

defer dirHandle.Close()
Expand Down
2 changes: 1 addition & 1 deletion common/sigar_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func GetCpuIdle() float64 {
return -1
}

func GetFileSystemList75() []string {
func GetFileSystemList75(string) []string {
return []string{}
}

Expand Down
2 changes: 1 addition & 1 deletion common/sigar_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func GetCpuIdle() float64 {
return -1
}

func GetFileSystemList75() []string {
func GetFileSystemList75(string) []string {
return []string{}
}

Expand Down
7 changes: 7 additions & 0 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/url"
"os"
"path/filepath"
"regexp"
"runtime"
"time"

Expand Down Expand Up @@ -166,5 +167,11 @@ func (ctx *Ctx) LoadConfig(path *string) error {
ctx.UserConfig.CollectorBinariesAccesslist = ctx.UserConfig.CollectorBinariesWhitelist
}

// windows_drive_range
driveRangeValid, _ := regexp.MatchString("^[A-Z]*$", ctx.UserConfig.WindowsDriveRange)
if !driveRangeValid {
log.Fatal("`windows_drive_range` must only contain valid windows drive letters in the range A-Z or left empty.")
}

return nil
}
5 changes: 5 additions & 0 deletions sidecar-windows-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ send_status: <SENDSTATUS>
# Directory where the sidecar generates configurations for collectors.
#collector_configuration_directory: "C:\\Program Files\\Graylog\\sidecar\\generated"

# Range of windows drives which are checked for disk usage. If their usage extends 75% they will be reported
# in the sidecar's status report to the Graylog server. Set to "" to disable disk scanning.
# Default:
# windows_drive_range: "CDEFGHIJKLMNOPQRSTUVWXYZ"

# A list of binaries which are allowed to be executed by the Sidecar. An empty list disables the access list feature.
# Wildcards can be used, for a full pattern description see https://golang.org/pkg/path/filepath/#Match
# Example:
Expand Down