Send Active vSphere Alarms to Microsoft Teams

I’m sure that my PowerShell could be much improved, but this will query vCenter for active alarms and push them to a Microsoft Teams channel via an incoming webhook.

Each card contains a button to launch the vSphere Client along with one section per alarm. The section contains some facts of the alarm and the object involved along with another button that launches the object’s summary page in the vSphere Client.

I set it up on a utility server as a scheduled task that runs every 10 minutes. This gives me details while on the go via the Microsoft Teams app and handy shortcuts if on-site or otherwise connected.

Code at [https://gist.github.com/TScalzott/30f422e010a974d86397e695223edc28](https://gist.github.com/TScalzott/30f422e010a974d86397e695223edc28)

Let me know what you think!

Added sample image to the gist, viewable directly at https://user-images.githubusercontent.com/10374853/64088255-1e2e8400-cd30-11e9-8a92-3858eee20eab.png

View Reddit by tscalzottView Source


To see the full content, share this page by clicking one of the buttons below

Related Articles


  1. Neat, I wish I were at work to test this out. If you’re trying to squeeze anymore speed out of this, you could use Get-View instead of Get-VMHost to only query the name, ignoring that I’d also personally use a switch on that part, and definitely drop the += in favor of just setting report once, or making it an array object and using the .Add() method.

    Also, you might be able to either use updateviewdata or include the host/vm names in the initial properties, and filter on the alarm state. I’ll check on Tuesday when I get back to work.

    $report = foreach ($ac in $AlarmClusters) {
    foreach ($ta in $ac.TriggeredAlarmstate) {
    $param = [PSCustomObject]@{
    ‘AlarmTime’ = (($ta.Time).ToLocalTime()).ToString()
    ‘AlarmStatus’ = $ta.OverallStatus.ToString()
    ‘AlarmAcked’ = $ta.Acknowledged
    ‘Cluster’ = $ac.Name
    ‘MoRef’ = $ta.MoRef
    ‘TriggeredAlarms’ = (Get-AlarmDefinition -Id $ta.Alarm.ToString()).Name

    switch -Regex ($ta.Entity.ToString()) {
    $param.Entity = $ac.Name
    $param.Type = “Cluster”
    $param.MoRef = $ac.MoRef
    $param.ImageUrl = “https://i.imgur.com/iq2BkLQ.png”
    ‘^HostSystem’ {
    $param.Entity = (Get-VMHost -Id $entity).Name
    $param.Type = “VMHost”
    $param.MoRef = $entity
    $param.ImageUrl = “https://i.imgur.com/k22bhCD.png”

    $param.Entity = (Get-VM -Id $entity).Name
    $param.Type = “VM”
    $param.MoRef = $entity
    $param.ImageUrl = “https://i.imgur.com/Y0ShH0n.png”

  2. Just did a quick read through on my phone and was able to follow the code well. I’m going to give this a further look later as I’ve been meaning to write something very similar for some time now. Great job!

  3. Hey, if you’re bored, see if this works for generating the data you need, I made it as fast as I could:

    $serverHash = @{ Server = $vCenter }

    $uriHash = @{
    ClusterComputeResource = ‘https://i.imgur.com/iq2BkLQ.png’
    HostSystem = ‘https://i.imgur.com/k22bhCD.png’
    VirtualMachine = ‘https://i.imgur.com/Y0ShH0n.png’

    $Cluster = Get-View @serverHash -ViewType ComputeResource -Property Name, OverallStatus, TriggeredAlarmstate |
    Where-Object { $null -ne $PSItem.TriggeredAlarmState }

    $entityListUnique = $Cluster.TriggeredAlarmState.Entity | ForEach-Object { ‘{0}-{1}’ -f $PSItem.Type,$PSItem.Value } | Sort-Object -Unique
    $alarmListUnique = $Cluster.TriggeredAlarmState.alarm | Sort-Object -Unique

    $null = Get-View @serverHash -Id $entityListUnique -Property Name -OutVariable combinedList
    $null = Get-View @serverHash -Id $alarmListUnique -Property ‘Info.Name’ -OutVariable +combinedList

    $combinedHash = $combinedList | Group-Object -AsHashTable -Property MoRef

    foreach ($a_Cluster in $Cluster){
    $a_Cluster.TriggeredAlarmState | Select-Object Time,OverallStatus,Acknowledged,
    @{ n = ‘Entity’; e = { $combinedHash[$PSItem.Entity].Name }},
    @{ n = ‘Type’; e = { $PSItem.Entity.Type }},
    @{ n = ‘MoRef’; e = { $PSItem.Entity }},
    @{ n = ‘TriggeredAlarms’; e = { $combinedHash[$PSItem.Alarm].Info.Name }},
    @{ n = ‘ImageUrl’; e = { $uriHash[$PSItem.Entity.Type] }}

Leave a Reply