Webhooks, which send data in JSON format over HTTP, are ideal for informing systems about events. This can be used, for example, to notify Microsoft Teams about events and store them in an action card. Actions for problem solving can also be included.

Webhooks offer special benefits in combination with Microsoft Teams or other collaboration tools. Teams can be divided into channels so that notifications can be sorted according to category or origin. In addition, admins can comment on events there and clarify who is responsible for certain incidents.

Action cards in Microsoft Teams ^

In the article "Instead of email alerts: Send system notifications to Microsoft Teams via webhooks," I describe how to send message cards to Teams via PowerShell. This article, on the other hand, deals with so-called action cards. Not only do they store information, but they also enable you to trigger actions using buttons.

I will demonstrate this feature using a practical use case: A PowerShell script gathers the utilization data of drives on selected servers, checks how much storage is still available there (in percentage), and sends an alert to Teams as an action card via webhook if the threshold value is exceeded.

Action card in Microsoft Teams which not only displays info about the drive but can also start WAC via a button

Action card in Microsoft Teams which not only displays info about the drive but can also start WAC via a button

A button then opens the server in WAC so that you can fix the problem by increasing the partition size.

Technical implementation ^

Action cards are declared via a JSON file and sent over an HTTP post to the Teams Connector URL. I cover the configuration of a Teams Connector for webhooks in the article above. The same steps are required for action cards.

The standardized JSON format, in conjunction with an HTTP request, allows you to use webhooks independently of the underlying platform. Hence, besides PowerShell, curl and other services can also be used to send the webhook.

PowerShell provides cmdlets to create and edit JSON files, but creating an action card with them is relatively cumbersome. Therefore, the PowerShell community has developed a special module for this purpose: PSTeams. The following how-to uses this module.

Explanation of the PowerShell script ^

Before the actual design of the action card, various inputs must be gathered. The data include the servers to be queried, a threshold that triggers the alert, the Teams connector ID, and the URL of your WAC.

Any number of additional computers may be added to the array of computer names. For a larger number, a CSV import into an array is recommended.

Note: 60 is very high as a threshold and is only used to trigger an alert for demonstration purposes. A practical value here would be 10 to 20 percent free drive storage.

The script triggers an alert for drive C as soon as less than 60 percent of disk space is free

The script triggers an alert for drive C as soon as less than 60 percent of disk space is free

The following script ensures that the necessary module is installed and imported into the system:

All the desired disk information is now stored in corresponding variables. $DiskFreePercentage, whose value results from the ratio between free and total storage, now contains the free disk space in percent. Based on this, it determines whether an alert is to be generated.

If the determined percentage falls below the defined threshold, an action card is created via the cmdlets of the PSTeams module. This is made up of facts and a button. The facts contain the properties of the affected drive. The button opens the storage management for the server in WAC. This link is created directly under the IF condition. The objects are combined into a section and transferred to the specified URL via Send-TeamsMessage. The already action card will appear in the Teams channel.

The full script is below:

Conclusion ^

With PSTeams, admins have an easy-to-use tool at hand to generate alerts, combined with an option for action. Of course, such a script could then be run automatically at regular intervals via a cron job or task scheduler.

The example shows a simple application, but there are certainly many more use cases. For example, various RSS feeds of IT security news could be received via PowerShell and collected in Teams.

In addition to simply retrieving data from a website, the button can also send HTTP POST requests; this opens up almost unlimited possibilities. Alerts or messages could be forwarded by team members to other systems by clicking a button.

Subscribe to 4sysops newsletter!

In this way, tickets could be opened or closed, messages could be saved in your own to-do list, and virtual machines could be started or stopped in the cloud or on-premises. All tasks that should not be fully automated, but rather executed in a controlled manner, can thus achieve partial automation by using approval steps via Teams.

+2
0 Comments

Leave a reply

Please enclose code in pre tags

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2021

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account