This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Send data from Rule to Action

Hi, I’m learning stacktorm. I’m having trouble passing data from Sensor - Trigger -Rule to Action.

I have a sensor that checks for new rows in a MYSQL table.

The problem appears when I put the parameters in the Rule (commented in the example below “My Rule”). Action execution does not occur.
If I comment the parameters, the rule successfully matches and the action executes successfully.

What will be the mistake?

The second question, how pass payload data from Rule to Action? Can you give an example explained?

My Sensor:

			#hardcoded for debug
			payload = {'key':"test", 'count': int(count) + 1} 

			self.sensor_service.dispatch(trigger='monitor.sensor', payload=payload)

The payload matches the Rule criteria (checked in enforcement):

My Rule:

---
name: rule_a
pack: monitor
description: Rule Dummy Data.
enabled: true
trigger:
    type: monitor.sensor
    parameters: {}
criteria:
    trigger.key:
        pattern: "test"
        type: "equals"       
action:
    ref: monitor.action_a
  #parameters:
  #key: "{{trigger.key}}"

Payload in the trigger:
{ "count": 47, "key": "test" }

My Action def YAML

version: 1.0

description: Dummy action


tasks:
    main_from_database:
        action: monitor.action_def
        next:
          - when: <% succeeded() %>
            publish: > 
                     method=<% result().result.method %> 
                     .....(more data)
            do:
              - api
          - when: <% failed() %>
            publish: stderr=<% result().stderr %>
            do: notify_on_error

Your rule looks good and follows Rules — StackStorm 3.0.1 documentation

Just to be sure, check for yaml indentation issues around parameters, as parameters and key are not indented properly (at least in commented version).

action:
    ref: monitor.action_a
    parameters:
        key: "{{trigger.key}}"

If that still doesn’t work, try to debug it a bit and pass {{trigger}} or {{ trigger | to_json }} to action and verify if data/structure received is indeed correct and expected comparing to what you send.

Additionally, your example is missing action metadata (Actions — StackStorm 3.0.1 documentation), - please add that as well. If there is some issue with action metadata, for debugging reasons - try to pass payload to existing action like core.local with echo like this: st2/sample_rule_with_actiontrigger.yaml at master · StackStorm/st2 · GitHub

Don’t forget to check the st2 logs for any other error symptoms.
Hope this will help to understand where is the issue.

Hi,

Thanks for the time and help.

Its solved.

After some tests and changes, I think there was more than one problem, at least one problem was in the workflow definition. Your response and then reading the logs helped to indicate the direction to go.

Thank you very much,

Log reading:

Help me to realize that execution was occurring with success.

root@xxxx:/var/log/st2# grep -nr 5d0fb7168e02f472f99bf960 .
....
./st2rulesengine.log:158396:2019-06-23 18:29:58,581 140539742909136 INFO engine [-] Matched 1 rule(s) for trigger_instance 5d0fb7168e02f472f99bf960 (trigger=monitor.sensor)
./st2rulesengine.log:158397:2019-06-23 18:29:58,590 140539742909136 INFO enforcer [-] Invoking action monitor.action_a for trigger_instance 5d0fb7168e02f472f99bf960 with params {"key": "teste"}.
1 Like