Print commands to Webhook

Hi all. Hope you are all doing great.

I am just beginning to dive in Mikrotik scripting and found a roadblock that’s preventing me from doing what I want - I need to be able to execute commands using a script and in turn prints the output of the command to a webhook

E.g.,

/tool fetch mode=https url=“https://xxxxx” http-method=post http-data=“payload={"attachments": [ { "title": "Outage Alert", "text": "[Device.Name] ([Device.FirstAddress]) is [Device.Status]", "color": "danger" } ] }”

The above prints the correct Device.Name from The Dude as they are variables. I wanted to do the same using RouterOS terminal and instead paste command output on the webhook

/tool fetch mode=https url=“https://xxxxxx” http-method=post http-data=“payload={"attachments": [ { "title": "Test Print Script", "text": "do=[:execute {/system history print}]", "color": "good" } ] }”

Obviously, it prints /system history print as is on the Webhook channel.

How do I go to print command outputs to a webhook integration?

Any help would be appreciated!

I think if you make this part of a script and do something like:

# Get our information
:local deviceName [/system identity get name]

# Build the POST data
:set $data "deviceName=$deviceName&somethingElse=\"something%20else\"";

# Send the data
/tool fetch mode=https url="https://xxxx" http-method=post http-data=$data;

Of course you can add more data to the script, but the whole thing is needing to run commands to fetch data and then you can use it.