Skip to content
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
10 changes: 7 additions & 3 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"golang.org/x/oauth2/clientcredentials"
)

const DefaultTimeout = 5
const DefaultTimeout = 5 * time.Second

type Client struct {
AuthConfig *clientcredentials.Config
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
4 changes: 3 additions & 1 deletion check.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"
"os"
"strings"
"time"

"github.com/NETWAYS/check_sentinelone/api"
"github.com/NETWAYS/go-check"
Expand All @@ -19,6 +20,7 @@ type Config struct {
IgnoreInProgress bool
SiteName string
ComputerName string
Timeout time.Duration
}

func BuildConfigFlags(fs *pflag.FlagSet) (config *Config) {
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"time"

"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/result"
)
Expand All @@ -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)
Expand Down