Skip to content

Commit 457e40d

Browse files
authoredOct 25, 2022
Make windows drive range configurable (#450)
1 parent 6561509 commit 457e40d

File tree

7 files changed

+22
-7
lines changed

7 files changed

+22
-7
lines changed
 

‎api/graylog.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func UpdateRegistration(httpClient *http.Client, checksum string, ctx *context.C
168168

169169
if ctx.UserConfig.SendStatus {
170170
metrics := &graylog.MetricsRequest{
171-
Disks75: common.GetFileSystemList75(),
171+
Disks75: common.GetFileSystemList75(ctx.UserConfig.WindowsDriveRange),
172172
CpuIdle: common.GetCpuIdle(),
173173
Load1: common.GetLoad1(),
174174
}

‎cfgfile/schema.go

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type SidecarConfig struct {
3737
CollectorBinariesWhitelist []string `config:"collector_binaries_whitelist"`
3838
CollectorBinariesAccesslist []string `config:"collector_binaries_accesslist"`
3939
Tags []string `config:"tags"`
40+
WindowsDriveRange string `config:"windows_drive_range"`
4041
}
4142

4243
// Default Sidecar configuration
@@ -70,6 +71,7 @@ collector_binaries_accesslist:
7071
- "/usr/bin/nxlog"
7172
- "/opt/nxlog/bin/nxlog"
7273
tags: []
74+
windows_drive_range: ""
7375
`
7476

7577
// Windows specific options. Gets merged over `CommonDefaults`
@@ -87,4 +89,5 @@ collector_binaries_accesslist:
8789
- "C:\\Program Files\\Heartbeat\\heartbeat.exe"
8890
- "C:\\Program Files\\Auditbeat\\auditbeat.exe"
8991
- "C:\\Program Files (x86)\\nxlog\\nxlog.exe"
92+
windows_drive_range: "CDEFGHIJKLMNOPQRSTUVWXYZ"
9093
`

‎common/sigar.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ func GetCpuIdle() float64 {
100100
return cpu.LastCpuTimes.IdlePercent * 100
101101
}
102102

103-
func GetFileSystemList75() []string {
103+
func GetFileSystemList75(windowsDriveRange string) []string {
104104
result := []string{}
105105
volumes := []sigar.FileSystem{}
106106

107107
if runtime.GOOS == "windows" {
108-
volumes = getWindowsDrives()
108+
volumes = getWindowsDrives(windowsDriveRange)
109109
} else {
110110
fslist := sigar.FileSystemList{}
111111
fslist.Get()
@@ -138,8 +138,8 @@ func GetLoad1() float64 {
138138
return avg.One
139139
}
140140

141-
func getWindowsDrives() (drives []sigar.FileSystem) {
142-
for _, drive := range "CDEFGHIJKLMNOPQRSTUVWXYZ" {
141+
func getWindowsDrives(windowsDriveRange string) (drives []sigar.FileSystem) {
142+
for _, drive := range windowsDriveRange {
143143
dirName := string(drive) + ":\\"
144144
dirHandle, err := os.Open(dirName)
145145
defer dirHandle.Close()

‎common/sigar_darwin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func GetCpuIdle() float64 {
1919
return -1
2020
}
2121

22-
func GetFileSystemList75() []string {
22+
func GetFileSystemList75(string) []string {
2323
return []string{}
2424
}
2525

‎common/sigar_freebsd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func GetCpuIdle() float64 {
1919
return -1
2020
}
2121

22-
func GetFileSystemList75() []string {
22+
func GetFileSystemList75(string) []string {
2323
return []string{}
2424
}
2525

‎context/context.go

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"net/url"
2121
"os"
2222
"path/filepath"
23+
"regexp"
2324
"runtime"
2425
"time"
2526

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

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

‎sidecar-windows-example.yml

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ send_status: <SENDSTATUS>
6767
# Directory where the sidecar generates configurations for collectors.
6868
#collector_configuration_directory: "C:\\Program Files\\Graylog\\sidecar\\generated"
6969

70+
# Range of windows drives which are checked for disk usage. If their usage extends 75% they will be reported
71+
# in the sidecar's status report to the Graylog server. Set to "" to disable disk scanning.
72+
# Default:
73+
# windows_drive_range: "CDEFGHIJKLMNOPQRSTUVWXYZ"
74+
7075
# A list of binaries which are allowed to be executed by the Sidecar. An empty list disables the access list feature.
7176
# Wildcards can be used, for a full pattern description see https://golang.org/pkg/path/filepath/#Match
7277
# Example:

0 commit comments

Comments
 (0)