fmnisme / err-stackstorm

a plugin for stackstorm
Apache License 2.0
15 stars 4 forks source link

multiple alias formats not working #11

Closed bartwalczak1 closed 6 years ago

bartwalczak1 commented 7 years ago

I am trying to put multiple formats in single alias

following this --> https://docs.stackstorm.com/chatops/aliases.html#multiple-formats-in-a-single-alias

here's alias I've put together

---
name: "get_ip_address"
pack: "core"
description: "get_ip_address"
action_ref: "core.get_ip_address"
formats:
      - "get ip {{tag_key}} {{tag_value}} {{tag_key2}} {{tag_value2}}"
      - "get ip {{tag_key}} {{tag_value}}"
ack:
  format: "Thinking...\n Execution id: '{{execution.id}}'"
  enabled: false
  append_url: false
result:
  extra:
    slack:
      color: "#00AA00"
      pretext: "Here's your response {{execution.context.api_user}}"
      title: "title"
      text: "optional text"
  format: |
    {{ execution.result.stdout}}

when I hit !st2 get ip ec2_tag_cluster qa-blue I am getting result, but when I hit !st2 get ip ec2_tag_cluster qa-blue a b

I am getting st2 command 'get ip ec2_tag_cluster qa-blue a b' not found. Check help with !st2help

in st2help I can see two formats listed

!st2 get ip {{tag_key}} {{tag_value}} {{tag_key2}} {{tag_value2}} -- get_ip_address
!st2 get ip {{tag_key}} {{tag_value}} -- get_ip_address
nzlosh commented 7 years ago

I was able to reproduce the problem and have had the time to dig into this issue a little deeper. The err-stackstorm plugin calls match via StackStorm's API and reports the actionalias doesn't exist. The bug on the plugins side is, it should have reported duplicate matches found. It should be a minor change to fix it so it reports the correct error.

Here is the test environment configuration and execution output: https://gist.github.com/nzlosh/c6d357f7891ee4080977536071dda296. You can see in the end of the gist that even st2 CLI fails to match when 4 variables are supplied.

I used the actionalias code from StackStorm to make a test script which helps visualise the matching logic.

Action Alias Tester
-------------------
Format: 'test {{arg1}}'
Text: 'test hello'
Result: {'arg1': 'hello'}

Format: 'test {{key1}} {{value1}}'
Text: 'test hello world'
Result: {'key1': 'hello', 'value1': 'world'}

Format: 'test {{key1}} {{value1}}'
Text: 'test k1 v1 k2 v2'
Result: {'key1': 'k1', 'value1': 'v1 k2 v2'}

Format: 'test {{key1}} {{value1}} {{ key2 }} {{ value2 }}'
Text: 'test k1 v1 k2 v2'
Result: {'key2': 'k2', 'key1': 'k1', 'value2': 'v2', 'value1': 'v1'}

Format: 'test {{key1}} {{value1}} {{ key2 }} {{ value2 }}'
Text: 'test k1 v1 k2 v2 k3=v3'
Result: {'k3': 'v3', 'key2': 'k2', 'key1': 'k1', 'value2': 'v2', 'value1': 'v1'}

Do you think it's possible to use extra Key-Value Parameters as describe here and just have a single format? E.g.

format: get ip {{tag_key}} {{tag_value}}
User input: 'get ip ec2_tag_cluster qa-blue tag_key2=a tag_value2=b'

Another option would be to use a fixed keyword between the two tags:

Format: 'test {{key1}} {{value1}} and {{ key2 }} {{ value2 }}'
Text: 'test k1 v1 and k2 v2'
Result: {'key2': 'k2', 'key1': 'k1', 'value2': 'v2', 'value1': 'v1'}
nzlosh commented 7 years ago

After thinking on it a bit more the 2nd option will still generate two matches, so adding the and keyword isn't a solution. It looks like Key-Value Parameters is the reliable way to setup the action alias.

nzlosh commented 6 years ago

Closing this issue since action aliases are working as designed.