cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/checks/rule/link.md
112lines · modecode
| 1 | --- |
| 2 | layout: default |
| 3 | parent: Checks |
| 4 | grand_parent: Documentation |
| 5 | --- |
| 6 | |
| 7 | # rule/link |
| 8 | |
| 9 | This check allows to validate if URLs passed in alerting rule |
| 10 | annotations. It will send a GET request to each link matching |
| 11 | configured regexp and warn if it gets a non-200 response. |
| 12 | |
| 13 | ## Configuration |
| 14 | |
| 15 | Syntax: |
| 16 | |
| 17 | ```js |
| 18 | link "$pattern" { |
| 19 | severity = "bug|warning|info" |
| 20 | uri = "..." |
| 21 | timeout = "1m" |
| 22 | headers = { ... } |
| 23 | } |
| 24 | ``` |
| 25 | |
| 26 | - `$pattern` - regexp pattern to match, each rule will only check link |
| 27 | URLs that match this patter. This can be templated to reference checked |
| 28 | rule fields, see [Configuration](../../configuration.md) for details. |
| 29 | - `uri` - optional URI rewrite rule, this will be used as the URI for all |
| 30 | requests if specified, regexp capture groups can be referenced here. |
| 31 | - `severity` - set custom severity for reported issues, defaults to a bug. |
| 32 | - `timeout` - timeout to be used for all request, defaults to 1 minute. |
| 33 | - `headers` - a list of HTTP headers to set on all requests. |
| 34 | |
| 35 | ## How to enable it |
| 36 | |
| 37 | This check is not enabled by default as it requires explicit configuration |
| 38 | to work. |
| 39 | To enable it add one or more `rule {...}` blocks and specify all rejected patterns |
| 40 | there. |
| 41 | |
| 42 | Examples: |
| 43 | |
| 44 | Validate all links found in alert annotations: |
| 45 | |
| 46 | ```js |
| 47 | rule { |
| 48 | link "https?://.+" {} |
| 49 | } |
| 50 | ``` |
| 51 | |
| 52 | Only validate HTTPS links, ignore plain HTTP. |
| 53 | |
| 54 | ```js |
| 55 | rule { |
| 56 | link "https://.+" {} |
| 57 | } |
| 58 | ``` |
| 59 | |
| 60 | Only validate specific hostname. |
| 61 | |
| 62 | ```js |
| 63 | rule { |
| 64 | link "https?://runbooks.example.com/.+" {} |
| 65 | } |
| 66 | ``` |
| 67 | |
| 68 | Rewrite URI to use `http://docs.internal.example.com/foo.html` instead of |
| 69 | `https://docs.example.com/foo.html`: |
| 70 | |
| 71 | ```js |
| 72 | rule { |
| 73 | link "https?://docs.example.com/(.+)" { |
| 74 | uri = "http://docs.internal.example.com/$1" |
| 75 | } |
| 76 | } |
| 77 | ``` |
| 78 | |
| 79 | Set `X-Auth` header for all requests. |
| 80 | |
| 81 | ```js |
| 82 | rule { |
| 83 | link "https?://runbooks.example.com/.+" { |
| 84 | headers = { |
| 85 | X-Auth = "secret key" |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | ``` |
| 90 | |
| 91 | ## How to disable it |
| 92 | |
| 93 | You can disable this check globally by adding this config block: |
| 94 | |
| 95 | ```js |
| 96 | checks { |
| 97 | disabled = ["rule/link"] |
| 98 | } |
| 99 | ``` |
| 100 | |
| 101 | Or you can disable it per rule by adding a comment to it. |
| 102 | |
| 103 | `# pint disable rule/link` |
| 104 | |
| 105 | If you want to disable only individual instances of this check |
| 106 | you can add a more specific comment. |
| 107 | |
| 108 | `# pint disable rule/link($pattern)` |
| 109 | |
| 110 | Example: |
| 111 | |
| 112 | `# pint disable rule/link(^https?://.+$)` |
| 113 | |