Add logic starlark example (#7864)

This commit is contained in:
Samantha Wang 2020-07-20 19:45:25 -07:00 committed by GitHub
parent de313fcde6
commit 903a065a0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -152,6 +152,9 @@ Attempting to modify the global scope will fail with an error.
- [ratio](/plugins/processors/starlark/testdata/ratio.star)
- [rename](/plugins/processors/starlark/testdata/rename.star)
- [scale](/plugins/processors/starlark/testdata/scale.star)
- [number logic](/plugins/processors/starlark/testdata/number_logic.star)
Open a [PR](https://github.com/influxdata/telegraf/compare) to add any other useful Starlark examples.
[specification]: https://github.com/google/starlark-go/blob/master/doc/spec.md
[string]: https://github.com/google/starlark-go/blob/master/doc/spec.md#strings

View File

@ -0,0 +1,9 @@
# Set any 'status' field between 1 and 6 to a value of 0
def apply(metric):
v = metric.fields.get('status')
if v == None:
return metric
if 1 < v and v < 6:
metric.fields['status'] = 0
return metric