From 35901f5c35a37b56aa944eeb09a1422f38af7ba5 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sat, 13 Feb 2021 18:14:22 +0100 Subject: [PATCH 1/2] Add docs for the new CLI command. --- docs/source/chatops/aliases.rst | 54 ++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/docs/source/chatops/aliases.rst b/docs/source/chatops/aliases.rst index 2987b8695..864b9906b 100644 --- a/docs/source/chatops/aliases.rst +++ b/docs/source/chatops/aliases.rst @@ -75,6 +75,54 @@ To remove an action alias, use: After removing or modifying existing aliases, you may need to restart the ``st2chatops`` service, or you may see old or duplicate commands still showing up on your chatbot. +Testing an alias end to end +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To test an alias end to end (from matching to triggering an execution and formatting the result), +you can use ``st2 action-alias test `` command which has been added in |st2| +v3.4.0. + +This command is useful for testing and developing aliases since it allows you to skip the chat +layer and verify and adjust command matching and result formatting directly using the CLI. In the +end you should of course still verify everything works end to end via the chat / hubot layer by +executing a command on chat + +This command first checks if the provided command string matches any alias (same as the +``st2 action-alias match`` command) and if it does, it runs an execution for the matched +alias (same as the ``st2 action-alias execute``) command and at the end, prints the formatted +result for the triggered execution. + +Example usage and output: + +.. code-block:: bash + + $ st2 action-alias test "run 'whoami ; date ; echo stdout ; echo stderr >&2' on localhost" + Triggering execution via action alias + + Execution (6027f61dffb5b8fc2ebc204c) has been started, waiting for it to finish... + + . + + Execution (6027f61dffb5b8fc2ebc204c) has finished, rendering result... + + Execution (6027f61fffb5b8fc2ebc204f) has been started, waiting for it to finish... + + . + + Formatted ChatOps result message + + ================================================================================ + Ran command *whoami ; date ; echo stdout ; echo stderr >&2* on *1* hosts. + + Details are as follows: + Host: *localhost* + ---> stdout: stanley + Sat Feb 13 15:54:05 UTC 2021 + stdout + ---> stderr: stderr + + ================================================================================ + Supported formats ^^^^^^^^^^^^^^^^^ @@ -129,7 +177,7 @@ using this pattern. With immutable parameters -~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~ Sometimes an alias must have default values that cannot be changed by the chat user. @@ -156,8 +204,6 @@ support Jinja templating so you can, for example, retrieve a value from the data hosts: dev.server sudo_password: "{{ st2kv('system.dev_server_sudo_password', decrypt=true) }}" - - Regular Expressions ~~~~~~~~~~~~~~~~~~~ @@ -328,7 +374,7 @@ depending on execution status: To disable the result message, you can use the ``enabled`` flag in the same way as in ``ack``. Plaintext Messages (Slack) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +^^^^^^^^^^^^^^^^^^^^^^^^^^ Result messages tend to be quite long, and Hubot will utilize the extra formatting capabilities of some chat clients: Slack messages will be sent as attachments. While this is a good fit in most From 48a9762fd12da3c062da7567b2fe09db98bd2e71 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Mon, 28 Mar 2022 09:28:27 -0500 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Amanda McGuinness --- docs/source/chatops/aliases.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/chatops/aliases.rst b/docs/source/chatops/aliases.rst index 864b9906b..a94293e9f 100644 --- a/docs/source/chatops/aliases.rst +++ b/docs/source/chatops/aliases.rst @@ -80,12 +80,12 @@ Testing an alias end to end To test an alias end to end (from matching to triggering an execution and formatting the result), you can use ``st2 action-alias test `` command which has been added in |st2| -v3.4.0. +v3.7.0. This command is useful for testing and developing aliases since it allows you to skip the chat layer and verify and adjust command matching and result formatting directly using the CLI. In the end you should of course still verify everything works end to end via the chat / hubot layer by -executing a command on chat +executing a command on chat. This command first checks if the provided command string matches any alias (same as the ``st2 action-alias match`` command) and if it does, it runs an execution for the matched