Skip to content

Instantly share code, notes, and snippets.

@marcusschiesser
Created November 18, 2022 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusschiesser/6aa832c6bd48173d2aad320f7e76b17e to your computer and use it in GitHub Desktop.
Save marcusschiesser/6aa832c6bd48173d2aad320f7e76b17e to your computer and use it in GitHub Desktop.
Splunk outputlookup macro that ensure that only x% of a KV store are changed at once
[outputlookup_guard(2)]
args = name,allowed_changes
definition = eventstats count as new_count\
| eval old_count=[| inputlookup $name$ | stats count | return $count]\
| eval max_count=old_count*(1+$allowed_changes$), min_count=old_count/(1+$allowed_changes$)\
| where new_count>min_count and new_count<max_count\
| fields - new_count, old_count, min_count, max_count\
| outputlookup $name$ override_if_empty=false
iseval = 0
errormsg = 'name' must be a lookup and 'allowed_changes' must be a number between 0 and 1
validation = isstr($name$) and isnum($allowed_changes$)
@marcusschiesser
Copy link
Author

marcusschiesser commented Nov 18, 2022

Practical if override_if_empty=false is not enough 😄

Example usage: | outputlookup_guard(name=mylookup,allowed_changes=0.1) - this is like | outputlookup mylookup, it just ensures that those changes are only applied if the result set size does not differ more than 10%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment