From 207a2d31c0ce9938c41905155b8d7731c52556d9 Mon Sep 17 00:00:00 2001 From: Elfranne Date: Tue, 6 Feb 2024 12:36:14 +0100 Subject: [PATCH] do not check cert if not used --- main.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 8f3d841..202e3fb 100644 --- a/main.go +++ b/main.go @@ -83,22 +83,22 @@ func main() { } func checkArgs(event *corev2.Event) (int, error) { + if len(plugin.CertFile) > 0 || len(plugin.KeyFile) > 0 || len(plugin.TrustedCAFile) > 0{ + if _, err := os.Stat(plugin.CertFile); errors.Is(err, os.ErrNotExist) { + fmt.Printf("could not load certificate(%s): %v", plugin.CertFile, err) + return sensu.CheckStateCritical, nil + } - if _, err := os.Stat(plugin.CertFile); errors.Is(err, os.ErrNotExist) { - fmt.Printf("could not load certificate(%s): %v", plugin.CertFile, err) - return sensu.CheckStateCritical, nil - } - - if _, err := os.Stat(plugin.KeyFile); errors.Is(err, os.ErrNotExist) { - fmt.Printf("could not load certificate key(%s): %v", plugin.KeyFile, err) - return sensu.CheckStateCritical, nil - } + if _, err := os.Stat(plugin.KeyFile); errors.Is(err, os.ErrNotExist) { + fmt.Printf("could not load certificate key(%s): %v", plugin.KeyFile, err) + return sensu.CheckStateCritical, nil + } - if _, err := os.Stat(plugin.TrustedCAFile); errors.Is(err, os.ErrNotExist) { - fmt.Printf("could not load CA(%s): %v", plugin.TrustedCAFile, err) - return sensu.CheckStateCritical, nil + if _, err := os.Stat(plugin.TrustedCAFile); errors.Is(err, os.ErrNotExist) { + fmt.Printf("could not load CA(%s): %v", plugin.TrustedCAFile, err) + return sensu.CheckStateCritical, nil + } } - return sensu.CheckStateOK, nil }