diff --git a/checks/http.go b/checks/http.go index 15a5251b6..06a8ea70d 100644 --- a/checks/http.go +++ b/checks/http.go @@ -169,9 +169,10 @@ func (c *HTTPChecker) Check(ctx *context.Context, extConfig external.Check) pkg. "code": status, "headers": resp.GetHeaders(), "elapsed": time.Since(start), - "sslAge": age, "content": body, + "sslAge": utils.Deref(age), } + if resp.IsJSON() { json, err := resp.AsJSON() if err != nil { diff --git a/fixtures/minimal/http_fail_connection.yaml b/fixtures/minimal/http_fail_connection.yaml index f75e80995..42ea94961 100644 --- a/fixtures/minimal/http_fail_connection.yaml +++ b/fixtures/minimal/http_fail_connection.yaml @@ -7,10 +7,10 @@ metadata: spec: interval: 30 http: - - connection: 'connection://http/500' + - connection: 'connection://HTTP/500' name: http fail response code check responseCodes: [200] - - connection: 'connection://http/200' + - connection: 'connection://HTTP/200' name: http fail test expr check display: expr: string(code) + " should be 500" diff --git a/fixtures/minimal/http_pass_single.yaml b/fixtures/minimal/http_pass_single.yaml index a3619f58c..2cd4f31be 100644 --- a/fixtures/minimal/http_pass_single.yaml +++ b/fixtures/minimal/http_pass_single.yaml @@ -19,6 +19,6 @@ spec: - name: http-expr-tests url: https://httpbin.demo.aws.flanksource.com/status/200 test: - expr: "code in [200,201,301] and sslAge > Duration('7d')" + expr: "code in [200,201,301] && sslAge > Duration('7d')" display: template: "code={{.code}}, age={{.sslAge}}" diff --git a/go.mod b/go.mod index d17dd69f3..4890c0dbc 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/fergusstrange/embedded-postgres v1.21.0 github.com/flanksource/commons v1.10.2 github.com/flanksource/duty v1.0.129 - github.com/flanksource/gomplate/v3 v3.20.4 + github.com/flanksource/gomplate/v3 v3.20.5 github.com/flanksource/is-healthy v0.0.0-20230713150444-ad2a5ef4bb37 github.com/flanksource/kommons v0.31.3 github.com/friendsofgo/errors v0.9.2 @@ -248,8 +248,8 @@ require ( golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20230717213848-3f92550aa753 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230717213848-3f92550aa753 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230720185612-659f7aaaa771 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771 // indirect google.golang.org/grpc v1.56.2 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect diff --git a/go.sum b/go.sum index 713d75c90..d9d56af99 100644 --- a/go.sum +++ b/go.sum @@ -882,8 +882,9 @@ github.com/flanksource/commons v1.10.2 h1:Nw9foNBAt6QVylbgfaDojRGgRUAyQAHOfBv9qk github.com/flanksource/commons v1.10.2/go.mod h1:zYEhi6E2+diQ+loVcROUHo/Bgv+Tn61W2NYmrb5MgVI= github.com/flanksource/duty v1.0.129 h1:k8aK32vh8FJENIFaTxHqn0Vdjcn+rS292ywHBmrJj9M= github.com/flanksource/duty v1.0.129/go.mod h1:RJ/kcZ7dbL8/52tem757szVIA3IomS8bOAZIK0xb4rk= -github.com/flanksource/gomplate/v3 v3.20.4 h1:8D9Tb1zcG5NniDMxMxhu6TXPgK54vIQfbDOCYYffQR4= github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc= +github.com/flanksource/gomplate/v3 v3.20.5 h1:5bNfgU6fiU13S4jutJ8XcqrQFdquEk7nbkkucp+DHpU= +github.com/flanksource/gomplate/v3 v3.20.5/go.mod h1:iwOOBsFuOmCaCWTbG9gyC2zwlFEAG1fjD7dyVWx95I4= github.com/flanksource/is-healthy v0.0.0-20230705092916-3b4cf510c5fc/go.mod h1:4pQhmF+TnVqJroQKY8wSnSp+T18oLson6YQ2M0qPHfQ= github.com/flanksource/is-healthy v0.0.0-20230713150444-ad2a5ef4bb37 h1:MHXg2Vo/oHB0rGLgsI0tkU9MGV7aDwqvO1lrbX7/shY= github.com/flanksource/is-healthy v0.0.0-20230713150444-ad2a5ef4bb37/go.mod h1:BH5gh9JyEAuuWVP6Q5y9h43VozS0RfKyjNpM9L4v4hw= @@ -2479,12 +2480,12 @@ google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 h1:Au6te5hbKUV8pIY google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130/go.mod h1:O9kGHb51iE/nOGvQaDUuadVYqovW56s5emA88lQnj6Y= google.golang.org/genproto/googleapis/api v0.0.0-20230525234020-1aefcd67740a/go.mod h1:ts19tUU+Z0ZShN1y3aPyq2+O3d5FUNNgT6FtOzmrNn8= google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= -google.golang.org/genproto/googleapis/api v0.0.0-20230717213848-3f92550aa753 h1:lCbbUxUDD+DiXx9Q6F/ttL0aAu7N2pz8XnmMm8ZW4NE= -google.golang.org/genproto/googleapis/api v0.0.0-20230717213848-3f92550aa753/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= +google.golang.org/genproto/googleapis/api v0.0.0-20230720185612-659f7aaaa771 h1:tlEtY2VFw8zKbcpukWhtzP/B/FDS9MQ9oV9nwA8i4K8= +google.golang.org/genproto/googleapis/api v0.0.0-20230720185612-659f7aaaa771/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234015-3fc162c6f38a/go.mod h1:xURIpW9ES5+/GZhnV6beoEtxQrnkRGIfP5VQG2tCBLc= google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230717213848-3f92550aa753 h1:XUODHrpzJEUeWmVo/jfNTLj0YyVveOo28oE6vkFbkO4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230717213848-3f92550aa753/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771 h1:Z8qdAF9GFsmcUuWQ5KVYIpP3PCKydn/YKORnghIalu4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index c98ae8ba4..d7b4bd614 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -70,3 +70,12 @@ func UUIDsToStrings(in []uuid.UUID) []string { func Ptr[T any](t T) *T { return &t } + +func Deref[T any](v *T) T { + if v == nil { + var zero T + return zero + } + + return *v +}