2018-09-05 22:13:29 +00:00
# Strings Processor Plugin
The `strings` plugin maps certain go string functions onto measurement, tag, and field values. Values can be modified in place or stored in another key.
Implemented functions are:
- lowercase
- uppercase
- trim
- trim_left
- trim_right
- trim_prefix
- trim_suffix
2018-09-27 02:30:02 +00:00
- replace
2019-07-31 23:55:25 +00:00
- left
2018-09-05 22:13:29 +00:00
Please note that in this implementation these are processed in the order that they appear above.
2019-07-19 20:16:54 +00:00
Specify the `measurement` , `tag` , `tag_key` , `field` , or `field_key` that you want processed in each section and optionally a `dest` if you want the result stored in a new tag or field. You can specify lots of transformations on data with a single strings processor.
2018-09-05 22:13:29 +00:00
2019-07-19 20:16:54 +00:00
If you'd like to apply the change to every `tag` , `tag_key` , `field` , `field_key` , or `measurement` , use the value `"*"` for each respective field. Note that the `dest` field will be ignored if `"*"` is used.
If you'd like to apply multiple processings to the same `tag_key` or `field_key` , note the process order stated above. See [Example 2]() for an example.
2018-09-27 02:30:02 +00:00
2018-09-05 22:13:29 +00:00
### Configuration:
```toml
[[processors.strings]]
2019-07-19 20:16:54 +00:00
## Convert a field value to lowercase and store in a new field
2018-09-05 22:13:29 +00:00
# [[processors.strings.lowercase]]
# field = "uri_stem"
# dest = "uri_stem_normalised"
2019-07-19 20:16:54 +00:00
## Convert a tag value to uppercase
# [[processors.strings.uppercase]]
# tag = "method"
## Trim leading and trailing whitespace using the default cutset
2018-09-05 22:13:29 +00:00
# [[processors.strings.trim]]
# field = "message"
2019-07-19 20:16:54 +00:00
## Trim leading characters in cutset
2018-09-05 22:13:29 +00:00
# [[processors.strings.trim_left]]
# field = "message"
# cutset = "\t"
2019-07-19 20:16:54 +00:00
## Trim trailing characters in cutset
2018-09-05 22:13:29 +00:00
# [[processors.strings.trim_right]]
# field = "message"
# cutset = "\r\n"
2019-07-19 20:16:54 +00:00
## Trim the given prefix from the field
2018-09-05 22:13:29 +00:00
# [[processors.strings.trim_prefix]]
# field = "my_value"
# prefix = "my_"
2019-07-19 20:16:54 +00:00
## Trim the given suffix from the field
2018-09-05 22:13:29 +00:00
# [[processors.strings.trim_suffix]]
# field = "read_count"
# suffix = "_count"
2018-09-27 02:30:02 +00:00
2019-07-19 20:16:54 +00:00
## Replace all non-overlapping instances of old with new
2018-09-27 02:30:02 +00:00
# [[processors.strings.replace]]
# measurement = "*"
# old = ":"
# new = "_"
2019-07-31 23:55:25 +00:00
## Trims strings based on width
# [[processors.strings.left]]
# field = "message"
# width = 10
2018-09-05 22:13:29 +00:00
```
#### Trim, TrimLeft, TrimRight
The `trim` , `trim_left` , and `trim_right` functions take an optional parameter: `cutset` . This value is a string containing the characters to remove from the value.
#### TrimPrefix, TrimSuffix
The `trim_prefix` and `trim_suffix` functions remote the given `prefix` or `suffix`
respectively from the string.
2018-09-27 02:30:02 +00:00
#### Replace
The `replace` function does a substring replacement across the entire
string to allow for different conventions between various input and output
plugins. Some example usages are eliminating disallowed characters in
field names or replacing separators between different separators.
Can also be used to eliminate unneeded chars that were in metrics.
If the entire name would be deleted, it will refuse to perform
the operation and keep the old name.
2018-09-05 22:13:29 +00:00
### Example
**Config**
```toml
[[processors.strings]]
[[processors.strings.lowercase]]
2019-07-19 20:16:54 +00:00
tag = "uri_stem"
2018-09-05 22:13:29 +00:00
[[processors.strings.trim_prefix]]
2019-07-19 20:16:54 +00:00
tag = "uri_stem"
2018-09-05 22:13:29 +00:00
prefix = "/api/"
[[processors.strings.uppercase]]
field = "cs-host"
dest = "cs-host_normalised"
```
**Input**
```
2019-07-19 20:16:54 +00:00
iis_log,method=get,uri_stem=/API/HealthCheck cs-host="MIXEDCASE_host",http_version=1.1 1519652321000000000
```
**Output**
```
iis_log,method=get,uri_stem=healthcheck cs-host="MIXEDCASE_host",http_version=1.1,cs-host_normalised="MIXEDCASE_HOST" 1519652321000000000
```
### Example 2
**Config**
```toml
[[processors.strings]]
[[processors.strings.lowercase]]
tag_key = "URI-Stem"
[[processors.strings.replace]]
tag_key = "uri-stem"
old = "-"
new = "_"
```
**Input**
```
iis_log,URI-Stem=/API/HealthCheck http_version=1.1 1519652321000000000
2018-09-05 22:13:29 +00:00
```
**Output**
```
2019-07-19 20:16:54 +00:00
iis_log,uri_stem=/API/HealthCheck http_version=1.1 1519652321000000000
2018-09-05 22:13:29 +00:00
```