paStash NG Commands - sipcapture/paStash GitHub Wiki
paStash Commands
This WIP outlines the nature of paStash commands and their general usage.
Requirements
The following modules are required to run this example:
sudo npm install -g @pastash/pastash @pastash/filter_command @pastash/command_math
What?
Command filters are pluggable pipeline functions users can inject in their logic using npm modules. By default they provide useful aggregation functions from the aggro
module, easily extensible with the use of custom plugins for custom tasks outside of the mainline, keeping everything simple and smoothly intersected.
Command Example:
.filter('method', 'INVITE')
.groupBy('response')
.divide('timestamp',1000,data)
Usage
In order to understand the potential usage of command
filters in paStash we'll create a custom command plugin providing a dummy divide
and multiply
set of commands to our pipeline.
This could be anything useful instead!
Create your own plugin, or use the default example at @pastash/command_math
for this execution.
Once ready, create a pipeline using your preferred in/out combination. Our custom plugin (alongside any other plugin) will be loaded at runtime via the plugins
property of the command
filter:
input {
stdin{}
}
filter {
json_fields {}
command {
debug => false
cmd => ".divide('age',2,data).multiply('eyes',2,data)"
plugins => ['@pastash/command_chain','@pastash/command_math']
}
}
output {
stdout {}
}
Feed it!
The following input should transverse the command pipeline and return all changes to the output:
STDIN
[{ "sex": "male", "age": 35, "eyes": 2 },{ "sex": "female", "age": 38, "eyes": 2 },{ "sex": "male", "age": 29, "eyes": 2 }]
STDOUT
[STDOUT] {
"key": null,
"values": [
{
"sex": "male",
"age": 17.5,
"eyes": 4
},
{
"sex": "female",
"age": 19,
"eyes": 4
},
{
"sex": "male",
"age": 14.5,
"eyes": 4
}
]
}