File: special-rules.md

package info (click to toggle)
python-pyfunceble 4.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,144 kB
  • sloc: python: 27,918; sh: 142; makefile: 48
file content (175 lines) | stat: -rw-r--r-- 5,303 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# `special_rules`

PyFunceble tries to be as flexible as possible. This is why we now allow you to define special rules that PyFunceble should follow.

The special rules are defined in the `special_rules` section of the configuration file.

## Overview

```yaml title=".PyFunceble.overwrite.yaml"
special_rules:
  # Let end-user define or integrate their own special rules.
  #
  # The idea: We want to give the end-user the possibility to define their own
  # rules. This is useful when they want to switch the status of a subject based
  # on a specific pattern, header, body, or status code.
  #
  # The structure:
  #    subject_pattern:
  #      -> The pattern to match against the subject.
  #    validation_type:
  #      -> The type of validation to perform. It can be one of the following:
  #         - all: A combination of everything (first match wins).
  #         - status_code: Only the status code.
  #         - headers: Only the headers.
  #         - body: Only the body.
  #         - headers+body: Match against the headers and the body.
  #    state_transition:
  #      -> The state to switch to when the validation is successful.
  #         When set to `down`, the status will be switched to INACTIVE. When set
  #         to `up`, the status will be switched to ACTIVE.
  #    required_status_code:
  #      -> A list of status code to match against.
  #    required_headers_patterns:
  #      -> A dictionary of headers to match against. The key is the header name
  #         and the value is a list of patterns to match against.
  #    required_body_patterns:
  #      -> A list of patterns to match against the body.
  #
  # Examples:
  #    When testing httpbin.org, we want to switch the status to down when the
  #    status code is 403 and the server header contains "gunicorn".
  #
  #    - subject_pattern: "^httpbin\\.org$"
  #      validation_type: all
  #      state_transition: down
  #      required_status_code:
  #        - 403
  #      required_headers_patterns:
  #        server:
  #          - gunicorn
  #
  #    When testing example.org, we want to switch the status to down when the
  #    status code is 404.
  #
  #    - subject_pattern: "^example\\.org$"
  #      validation_type: status_code
  #      state_transition: down
  #      required_status_code:
  #        - 404
  #
  #    When testing example.com, we want to switch The body and headers.the status to down when the
  #    header `server` contains `nginx`.
  #
  #    - subject_pattern: "^example\\.com$"
  #      validation_type: headers
  #      state_transition: down
  #      required_headers_patterns:
  #        server:
  #          - nginx
  #
  #    When testing example.net, we want to switch the status to down when the
  #    body contains "Hello, World!".
  #
  #    - subject_pattern: "^example\\.net$"
  #      validation_type: body
  #      state_transition: down
  #      required_body_patterns:
  #        - Hello, World!
  #
  #    When testing example.dev, we want to switch the status to down when the
  #    headers server contains `nginx` or the body contains "Hello, World!".
  #
  #    - subject_pattern: "^example\\.dev$"
  #      validation_type: headers+body
  #      state_transition: down
  #      required_headers_patterns:
  #        server:
  #          - nginx
  #      required_body_patterns:
  #        - Hello, World!
  []
```

## Examples

### `validation_type`: `all`

When testing httpbin.org, we want to switch the status to down when the status
code is 403 and the server header contains "gunicorn".

```yaml title=".PyFunceble.overwrite.yaml"
special_rules:
  - subject_pattern: "^httpbin\\.org$"
    validation_type: all
    state_transition: down
    required_status_code:
      - 403
    required_headers_patterns:
      server:
        - gunicorn
```

### `validation_type`: `status_code`

When testing example.org, we want to switch the status to down when the status
code is 404.

```yaml title=".PyFunceble.overwrite.yaml"
special_rules:
  - subject_pattern: "^example\\.org$"
    validation_type: status_code
    state_transition: down
    required_status_code:
      - 404
```

### `validation_type`: `headers`

When testing example.com, we want to switch the status to down when the header
`server` contains `nginx`.

```yaml title=".PyFunceble.overwrite.yaml"
special_rules:
  - subject_pattern: "^example\\.com$"
    validation_type: headers
    state_transition: down
    required_headers_patterns:
      server:
        - nginx
```

### `validation_type`: `body`

When testing example.net, we want to switch the status to down when the body
contains `Hello, World!`.

```yaml title=".PyFunceble.overwrite.yaml"
special_rules:
  - subject_pattern: "^example\\.net$"
    validation_type: body
    state_transition: down
    required_body_patterns:
      - Hello, World!
```

### `validation_type`: `headers+body`

When testing example.dev, we want to switch the status to down when the header
`server` contains `nginx` or the body contains `Hello, World!`.

```yaml title=".PyFunceble.overwrite.yaml"
special_rules:
  - subject_pattern: "^example\\.dev$"
    validation_type: headers+body
    state_transition: down
    required_headers_patterns:
      server:
        - nginx
    required_body_patterns:
      - Hello, World!
```