New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attribute Difference Agent #1572
Conversation
Awesome @lloydpick, this looks like a useful addition to Huginn. Thanks, and welcome! |
|
||
private | ||
|
||
def handle(opts, event = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably don't need the = nil
part, since the attribute is always provided.
11a337e
to
a289d80
Compare
Changes made |
|
||
def handle(opts, event) | ||
attribute = opts['attribute'] | ||
attribute_value = event.payload[attribute].nil? ? 0 : event.payload[attribute] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be an option to use either JSONPath or Liquid to access the attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, i'll need to go find an example of that, but sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I just noticed you are already calling interpolated(event)
in receive
, so using liquid to modify the attribute based on the incoming event would already work, but one could not access values nested in the received event object.
You could change the attribute
option key to value
and directly use that interpolated result, this would allow the user to set it to {{data.value}}
, interpolated({data: {value: 6}})
would then return {value: "6"}
.
a289d80
to
5dcc6ab
Compare
ok, JSON path support has been added. I've also taken out the BigDecimal stuff after running into some weird edge cases, just gone back to floats and rounding which can be customised. |
That looks like a neat combination of both worlds to me, maybe you could note that all configuration options will be liquid interpolated based on the incoming event? |
Looks great! |
5dcc6ab
to
23ce4b2
Compare
Note added |
Awesome, thanks @lloydpick! |
Hi,
I wanted to have the ability to enrich an event with a comparison of events, e.g. the last received value was X, what is the integer/decimal difference or percentage change when compared to the new event value Y.
Wrote this agent because I couldn't really find one that did what I wanted. I'm not sure if I could have achieved the the same outcome with some agent that already exists? I've not been using Huginn for too long, but decided to write this anyway, it let me learn how to write agents.
Code and passing tests are attached.
Cheers