From 6ba32bf7f003963b65545986af09ceee673ff9d8 Mon Sep 17 00:00:00 2001 From: Andi Roveretto Date: Thu, 13 Aug 2026 13:01:45 +0200 Subject: [PATCH 1/2] Make HTTP client timeout configurable via existing -t/--timeout flag Previously the HTTP client used a hardcoded 5 second timeout, independent of the --timeout flag. This caused requests to fail whenever the SentinelOne API took longer than 5s to respond, regardless of the timeout configured by the user. --- api/client.go | 10 +++++++--- check.go | 4 +++- main.go | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/api/client.go b/api/client.go index 540ab1b..aa52081 100644 --- a/api/client.go +++ b/api/client.go @@ -9,7 +9,7 @@ import ( "golang.org/x/oauth2/clientcredentials" ) -const DefaultTimeout = 5 +const DefaultTimeout = 5 * time.Second type Client struct { AuthConfig *clientcredentials.Config @@ -18,14 +18,18 @@ type Client struct { AuthToken string } -func NewClient(url, token string) (c *Client) { +func NewClient(url, token string, timeout time.Duration) (c *Client) { c = &Client{ ManagementURL: url, AuthToken: token, } + if timeout <= 0 { + timeout = DefaultTimeout + } + c.HTTPClient = NewLoggingHTTPClient() - c.HTTPClient.Timeout = time.Duration(DefaultTimeout) * time.Second + c.HTTPClient.Timeout = timeout return } diff --git a/check.go b/check.go index 0691cd1..a106d0a 100644 --- a/check.go +++ b/check.go @@ -6,6 +6,7 @@ import ( "net/url" "os" "strings" + "time" "github.com/NETWAYS/check_sentinelone/api" "github.com/NETWAYS/go-check" @@ -19,6 +20,7 @@ type Config struct { IgnoreInProgress bool SiteName string ComputerName string + Timeout time.Duration } func BuildConfigFlags(fs *pflag.FlagSet) (config *Config) { @@ -58,7 +60,7 @@ func (c *Config) Validate() error { } func (c *Config) Run() (*result.PartialResult, error) { - client := api.NewClient(c.ManagementURL, c.AuthToken) + client := api.NewClient(c.ManagementURL, c.AuthToken, c.Timeout) values := url.Values{} values.Set("sortOrder", "desc") diff --git a/main.go b/main.go index 66bbd32..ba63667 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "time" + "github.com/NETWAYS/go-check" "github.com/NETWAYS/go-check/result" ) @@ -27,6 +29,8 @@ func main() { plugin.ParseArguments() config.SetFromEnv() + config.Timeout = time.Duration(plugin.Timeout) * time.Second + err := config.Validate() if err != nil { check.ExitError(err) From d43ce443d299bc5c4cf86d9c012b1a04cc1c8b25 Mon Sep 17 00:00:00 2001 From: Andi Roveretto Date: Thu, 13 Aug 2026 13:29:12 +0200 Subject: [PATCH 2/2] Update test to match new NewClient signature --- api/client_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/client_test.go b/api/client_test.go index fbedbfd..0c5aac8 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -16,13 +16,13 @@ func envClient(t *testing.T) *api.Client { t.Skip("SENTINELONE_URL and SENTINELONE_TOKEN must be set!") } - return api.NewClient(url, token) + return api.NewClient(url, token, 0) } func testClient() (*api.Client, func()) { httpmock.Activate() - return api.NewClient("https://euce1-test.sentinelone.net", "test"), func() { + return api.NewClient("https://euce1-test.sentinelone.net", "test", 0), func() { httpmock.DeactivateAndReset() } }