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.

Unable to call workflow from Rule (StackStorm) and how to debug the flow

  1. I’m new to StackStorm, I need to understand how the mistral-workflow is getting called from Rule. I am trying to do small POC. Could you please provide me the working sample examples to understand and execute in our end?

  2. I have used below samples and tried to run. But it is not working and correct me if the below examples are correct or not.

Step 1:
sample_rule_with_webhook.yaml

name: "sample_rule_with_webhook.yaml"
pack:"examples"
description: "sample rule dumping webhook payload to a file"
enabled: true
trigger:
           type: "core.st2.webhook"
           parameters: 
               url: "sample" 
 criteria: {}
 action:
           ref:"examples.mistral-basic"
           parameters:
               cmd: "echo {{date}} "
               timeout:20

step 2:

st2 rule create sample_rule_with_webhook.yaml

(Rule got registered successfully) checked using the below command

st2 rule list

Step 3:

execute the below for getting token which is passed to the curl command

    export ST2_AUTH_TOKEN=`st2 auth -t -p 'Ch@ngeMe' st2admin`
    echo $ST2_AUTH_TOKEN

execute the above rule using the below command

curl -k https://localhost/api/v1/webhooks/sample -H 'Content-Type: application/json' -H 'X-Auth-Token: put_token_here'

(No error)

The same we can execute thru postman by passing this rest url along with token which will work

Step 4:

Created mistral-basic.yaml action under action folder

description: Run a local linux command
enabled: true
runner_type: mistral-v2
entry_point: workflows/mistral-basic.yaml
name: mistral-basic
pack: examples
parameters:
  cmd:
    required: true
    type: string
  timeout:
    type: integer
    default: 60

Step 5:

Created mistral-basic.yaml workflow under workflow folder

version: '2.0'

examples.mistral-basic:
    description: A basic workflow that runs an arbitrary linux command.
    type: direct
    input:
        - cmd
        - timeout
    output:
        stdout: <% $.stdout %>
    tasks:
        task1:
            action: core.local cmd=<% $.cmd %> timeout=<% $.timeout %>
            publish:
                stdout: <% task(task1).result.stdout %>
                stderr: <% task(task1).result.stderr %>

step 6:

execute the action using the below command

st2 action create mistral-basic.yaml

I’m seeing registered workflow examples.mistral-basic in StackStorm when I execute st2 action list

step 7:

execute the workflow using the below command

st2 run examples.mistral-basic cmd=date timeout=20 -a

Step: 8

When I execute the below command, I am able to see the workflow status

st2 execution get <execution id>

Question;

  1. please let know how to execute this workflow from rule using curl or using rest api. please check the above code

  2. please provide any sample examples (atleast hello work program) - end to end (calling from postman >>> webhook rule >>>> action >>>> workflow >>> return result postman

  3. Please let know how to debug this flow?

Thanks all and waiting for quick reply.

It looks like you have most of the pieces already there.

Your problem is most likely in your rule:

           ref:"examples.mistral-basic"
           parameters:
               cmd: "echo {{date}} "
               timeout:20

{{date}} needs to be defined somewhere if you want to use it as a variable. You haven’t defined it anywhere. Rather than using cmd: "echo {{date}}", you probably just want to use cmd: date

This blog shows how to walk through rule/action troubleshooting How to Troubleshoot a Rule - StackStorm

My guess is that you’ll probably find errors in st2rulesengine.log, related to failure to render that {{date}} Jinja parameter (because you didn’t define it anywhere).

Thanks Lindsay Hill

As you suggested i tried the same

ref:“examples.mistral-basic”
parameters:
cmd: date
timeout:20

Please help where to see the output whether the rule is calling appropriate action or not?
I cant use the below command as i am trying to execute from rule

st2 action create mistral-basic.yaml
st2 run examples.mistral-basic cmd=date timeout=20 -a
st2 execution get execution id

below is the output while i tried to execute the workflow independently

Hi Charles. Did you get a chance to read How to Troubleshoot a Rule - StackStorm? That should help you determine whether the rule is calling the appropriate action or not.

Warren - Thank you.

Yes I went thru the link for troubleshoot a rule. It is basically related to sensor and triggers. In my program i did not use sensor. this is webhook rule. please correct me If i am wrong.

Webhook is just another form of sensor. The overall process is still the same