| 1 | # matcher |
| 2 | ## Supported Format |
| 3 | |
| 4 | * string |
| 5 | * glob |
| 6 | * regexp |
| 7 | * simple patterns |
| 8 | |
| 9 | Depending on the symbol at the start of the string, the `matcher` will use one of the supported formats. |
| 10 | |
| 11 | | matcher | short format | long format | |
| 12 | |-----------------|--------------|-------------------| |
| 13 | | string | ` =` | `string` | |
| 14 | | glob | `*` | `glob` | |
| 15 | | regexp | `~` | `regexp` | |
| 16 | | simple patterns | | `simple_patterns` | |
| 17 | |
| 18 | Example: |
| 19 | |
| 20 | - `* pattern`: It will use the `glob` matcher to find the `pattern` in the string. |
| 21 | |
| 22 | ### Syntax |
| 23 | |
| 24 | **Tip**: Read `::=` as `is defined as`. |
| 25 | |
| 26 | ``` |
| 27 | Short Syntax |
| 28 | [ <not> ] <format> <space> <expr> |
| 29 | |
| 30 | <not> ::= '!' |
| 31 | negative expression |
| 32 | <format> ::= [ '=', '~', '*' ] |
| 33 | '=' means string match |
| 34 | '~' means regexp match |
| 35 | '*' means glob match |
| 36 | <space> ::= { ' ' | '\t' | '\n' | '\n' | '\r' } |
| 37 | <expr> ::= any string |
| 38 | |
| 39 | Long Syntax |
| 40 | [ <not> ] <format> <separator> <expr> |
| 41 | |
| 42 | <format> ::= [ 'string' | 'glob' | 'regexp' | 'simple_patterns' ] |
| 43 | <not> ::= '!' |
| 44 | negative expression |
| 45 | <separator> ::= ':' |
| 46 | <expr> ::= any string |
| 47 | ``` |
| 48 | |
| 49 | When using the short syntax, you can enable the glob format by starting the string with a `*`, while in the long syntax |
| 50 | you need to define it more explicitly. The following examples are identical. `simple_patterns` can be used **only** with |
| 51 | the long syntax. |
| 52 | |
| 53 | Examples: |
| 54 | |
| 55 | - Short Syntax: `'* * '` |
| 56 | - Long Syntax: `'glob:*'` |
| 57 | |
| 58 | ### String matcher |
| 59 | |
| 60 | The string matcher reports whether the given value equals to the string. |
| 61 | |
| 62 | Examples: |
| 63 | |
| 64 | - `'= foo'` matches only if the string is `foo`. |
| 65 | - `'!= bar'` matches any string that is not `bar`. |
| 66 | |
| 67 | String matcher means **exact match** of the `string`. There are other string match related cases: |
| 68 | |
| 69 | - string has prefix `something` |
| 70 | - string has suffix `something` |
| 71 | - string contains `something` |
| 72 | |
| 73 | This is achievable using the `glob` matcher: |
| 74 | |
| 75 | - `* PREFIX*`, means that it matches with any string that *starts* with `PREFIX`, e.g `PREFIXnetdata` |
| 76 | - `* *SUFFIX`, means that it matches with any string that *ends* with `SUFFIX`, e.g `netdataSUFFIX` |
| 77 | - `* *SUBSTRING*`, means that it matches with any string that *contains* `SUBSTRING`, e.g `netdataSUBSTRINGnetdata` |
| 78 | |
| 79 | ### Glob matcher |
| 80 | |
| 81 | The glob matcher reports whether the given value matches the wildcard pattern. It uses the standard `golang` |
| 82 | library `path`. You can read more about the library in the [golang documentation](https://golang.org/pkg/path/#Match), |
| 83 | where you can also practice with the library in order to learn the syntax and use it in your Netdata configuration. |
| 84 | |
| 85 | The pattern syntax is: |
| 86 | |
| 87 | ``` |
| 88 | pattern: |
| 89 | { term } |
| 90 | term: |
| 91 | '*' matches any sequence of characters |
| 92 | '?' matches any single character |
| 93 | '[' [ '^' ] { character-range } ']' |
| 94 | character class (must be non-empty) |
| 95 | c matches character c (c != '*', '?', '\\', '[') |
| 96 | '\\' c matches character c |
| 97 | |
| 98 | character-range: |
| 99 | c matches character c (c != '\\', '-', ']') |
| 100 | '\\' c matches character c |
| 101 | lo '-' hi matches character c for lo <= c <= hi |
| 102 | ``` |
| 103 | |
| 104 | Examples: |
| 105 | |
| 106 | - `* ?` matches any string that is a single character. |
| 107 | - `'?a'` matches any 2 character string that starts with any character and the second character is `a`, like `ba` but |
| 108 | not `bb` or `bba`. |
| 109 | - `'[^abc]'` matches any character that is NOT a,b,c. `'[abc]'` matches only a, b, c. |
| 110 | - `'*[a-d]'` matches any string (`*`) that ends with a character that is between `a` and `d` (i.e `a,b,c,d`). |
| 111 | |
| 112 | ### Regexp matcher |
| 113 | |
| 114 | The regexp matcher reports whether the given value matches the RegExp pattern ( use regexp.Match ). |
| 115 | |
| 116 | The RegExp syntax is described at https://golang.org/pkg/regexp/syntax/. |
| 117 | |
| 118 | Learn more about regular expressions at [RegexOne](https://regexone.com/). |
| 119 | |
| 120 | ### Simple patterns matcher |
| 121 | |
| 122 | The simple patterns matcher reports whether the given value matches the simple patterns. |
| 123 | |
| 124 | Simple patterns are a space separated list of words. Each word may use any number of wildcards `*`. Simple patterns |
| 125 | allow negative matches by prefixing a word with `!`. |
| 126 | |
| 127 | Examples: |
| 128 | |
| 129 | - `!*bad* *` matches anything, except all those that contain the word bad. |
| 130 | - `*foobar* !foo* !*bar *` matches everything containing foobar, except strings that start with foo or end with bar. |
| 131 | |
| 132 | |
| 133 | |
| 134 |