github.com/google/cloudprober@v0.11.3/docs/content/how-to/validators.md (about) 1 --- 2 menu: 3 main: 4 parent: "How-Tos" 5 weight: 26 6 title: "Validators" 7 date: 2019-07-28T17:24:32-07:00 8 --- 9 Validators allow you to run checks on the probe request output (if any). For 10 example, you can specify if you expect the probe output to match a certain 11 regex or return a certain status code (for HTTP). You can configure more than 12 one validators and all validators should succeed for the probe to be marked as 13 success. 14 15 {{< highlight bash >}} 16 probe { 17 name: "google_homepage" 18 type: HTTP 19 targets { 20 host_names: "www.google.com" 21 } 22 interval_msec: 10000 # Probe every 10s 23 24 # This validator should succeed. 25 validator { 26 name: "status_code_2xx" 27 http_validator { 28 success_status_codes: "200-299" 29 } 30 } 31 32 # This validator will fail, notice missing 'o' in our regex. 33 validator { 34 name: "gogle_re" 35 regex: "gogle" 36 } 37 } 38 {{< / highlight >}} 39 40 (Full listing: https://github.com/google/cloudprober/blob/master/examples/validators/cloudprober_validator.cfg) 41 42 To make the debugging easier, validation failures are logged and exported as an 43 independent map counter -- *validation_failure*, with *validator* key. For 44 example, the above example will result in the following counters being 45 exported after 5 runs: 46 47 {{< highlight bash >}} 48 total{probe="google_homepage",dst="www.google.com"} 5 49 success{probe="google_homepage",dst="www.google.com"} 0 50 validation_failure{validator="status_code_2xx",probe="google_homepage",dst="www.google.com"} 0 51 validation_failure{validator="gogle_re",probe="google_homepage",dst="www.google.com"} 5 52 {{< / highlight >}} 53 54 Note that validator counter will **not** go up if probe fails for other 55 reasons, for example web server timing out. That's why you typically don't want 56 to alert only on validation failures. That said, in some cases, validation 57 failures could be the only thing you're interested in, for example, if you're 58 trying to make sure that a certain copyright is always present in your web 59 pages or you want to catch data integrity issues in your network. 60 61 Let's take a look at the types of validators you can configure. 62 63 ## Regex Validator 64 65 Regex validator simply checks for a regex in the probe request output. It works 66 for all probe types except for UDP and UDP_LISTENER - these probe types don't 67 support any validators at the moment. 68 69 ## HTTP Validator 70 71 HTTP response validator works only for the HTTP probe type. You can currently 72 use HTTP validator to define success and failure status codes (represented by 73 success_status_codes and failure_stauts_codes in the config): 74 75 * If *failure_status_codes* is defined and response status code falls within 76 that range, validator is considered to have failed. 77 * If *success_status_codes* is defined and response status code *does not* 78 fall within that range, validator is considered to have failed. 79 * If *failure_header* is defined and HTTP response include specified header and 80 there are matching values, validator is considered to have failed. Leaving 81 *value_regex* empty checks only for header name. 82 * If *success_header* is defined and HTTP response *does not* include specified header 83 with matching values, validator is considered to have failed. Leaving 84 *value_regex* empty checks only for header name. 85 86 ## Data Integrity Validator 87 88 Data integrity validator is designed to catch the packet corruption issues in 89 the network. We have a basic check that verifies that the probe output is made 90 up purely of a pattern repeated many times over. 91