Name: "probe_http_version",
Help: "Returns the version of HTTP of the probe response",
})
+
+ probeFailedDueToRegex = prometheus.NewGauge(prometheus.GaugeOpts{
+ Name: "probe_failed_due_to_regex",
+ Help: "Indicates if probe failed due to regex",
+ })
)
registry.MustRegister(contentLengthGauge)
registry.MustRegister(isSSLGauge)
registry.MustRegister(statusCodeGauge)
registry.MustRegister(probeHTTPVersionGauge)
+ registry.MustRegister(probeFailedDueToRegex)
httpConfig := module.HTTP
if success && (len(httpConfig.FailIfMatchesRegexp) > 0 || len(httpConfig.FailIfNotMatchesRegexp) > 0) {
success = matchRegularExpressions(resp.Body, httpConfig)
+ if success {
+ probeFailedDueToRegex.Set(0)
+ } else {
+ probeFailedDueToRegex.Set(1)
+ }
}
var httpVersionNumber float64
if result {
t.Fatalf("Regexp test succeeded unexpectedly, got %s", body)
}
+ mfs, err := registry.Gather()
+ if err != nil {
+ t.Fatal(err)
+ }
+ expectedResults := map[string]float64{
+ "probe_failed_due_to_regex": 1,
+ }
+ checkRegistryResults(expectedResults, mfs, t)
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Download the latest version here")
if !result {
t.Fatalf("Regexp test failed unexpectedly, got %s", body)
}
+ mfs, err = registry.Gather()
+ if err != nil {
+ t.Fatal(err)
+ }
+ expectedResults = map[string]float64{
+ "probe_failed_due_to_regex": 0,
+ }
+ checkRegistryResults(expectedResults, mfs, t)
// With multiple regexps configured, verify that any matching regexp causes
// the probe to fail, but probes succeed when no regexp matches.
Name: "probe_ssl_earliest_cert_expiry",
Help: "Returns earliest SSL cert expiry date",
})
+ probeFailedDueToRegex := prometheus.NewGauge(prometheus.GaugeOpts{
+ Name: "probe_failed_due_to_regex",
+ Help: "Indicates if probe failed due to regex",
+ })
+ registry.MustRegister(probeFailedDueToRegex)
deadline := time.Now().Add(module.Timeout)
conn, err := dialTCP(ctx, target, module, registry)
if err != nil {
return false
}
if match == nil {
+ probeFailedDueToRegex.Set(1)
return false
}
+ probeFailedDueToRegex.Set(0)
send = string(re.Expand(nil, []byte(send), scanner.Bytes(), match))
}
if send != "" {
if probeTCP(testCTX, ln.Addr().String(), module, registry) {
t.Fatalf("TCP module succeeded, expected failure.")
}
+ mfs, err := registry.Gather()
+ if err != nil {
+ t.Fatal(err)
+ }
+ expectedResults := map[string]float64{
+ "probe_failed_due_to_regex": 1,
+ }
+ checkRegistryResults(expectedResults, mfs, t)
<-ch
}
if got, want := <-ch, "OpenSSH_6.9p1"; got != want {
t.Fatalf("Read unexpected version: got %q, want %q", got, want)
}
+ mfs, err := registry.Gather()
+ if err != nil {
+ t.Fatal(err)
+ }
+ expectedResults := map[string]float64{
+ "probe_failed_due_to_regex": 0,
+ }
+ checkRegistryResults(expectedResults, mfs, t)
+
}
func TestTCPConnectionProtocol(t *testing.T) {
res[mfs[i].GetName()] = mfs[i].Metric[0].GetGauge().GetValue()
}
for k, v := range expRes {
- if val, ok := res[k]; !ok || val != v {
+ val, ok := res[k]
+ if !ok {
+ t.Fatalf("Expected metric %v not found in returned metrics", k)
+ }
+ if val != v {
t.Fatalf("Expected: %v: %v, got: %v: %v", k, v, k, val)
}
}