Is there any way to automate Azure event hub metrics screenshot and posting to MS Teams channel which can run scheduled intervals of time

Kumar2024 0 Reputation points
2024-04-16T19:46:38.4933333+00:00

the below process is to be automated:

  1. connect to Azure and Gather the metrics screenshot from Azure resource ( Azure event hub - incoming vs outgoing messages ), Also select the range as last 6 hours.
  2. Take the screenshot and post it in MS Teams specific group channel with proper header text.
Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
558 questions
{count} votes

1 answer

Sort by: Most helpful
  1. hossein jalilian 2,915 Reputation points
    2024-04-16T21:51:17.47+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    1. Use the Connect-AzAccount cmdlet to authenticate with your Azure account.
    2. Use the Get-AzMetric cmdlet to retrieve the incoming and outgoing messages metrics for the Azure Event Hub. Specify the time range as the last 6 hours using the -StartTime and -EndTime parameters
    3. Use a PowerShell module like ScreenCapture or Win32API to capture a screenshot of the Azure portal showing the Event Hub metrics.
    4. Use the Microsoft Teams REST API to post the screenshot to a specific channel.

    Here's a sample PowerShell script:

    # Connect to Azure
    Connect-AzAccount
    
    # Gather 
    $eventHubName = "your-event-hub-name"
    $resourceGroupName = "your-resource-group-name"
    $startTime = (Get-Date).AddHours(-6)
    $endTime = Get-Date
    
    $metrics = Get-AzMetric -ResourceId "/subscriptions/[your-subscription-id]/resourceGroups/$resourceGroupName/providers/Microsoft.EventHub/namespaces/[your-event-hub-namespace]/eventhubs/$eventHubName" `
                            -MetricName "IncomingMessages", "OutgoingMessages" `
                            -TimeGrain ([TimeSpan]::FromMinutes(5)) `
                            -StartTime $startTime `
                            -EndTime $endTime
    
    # Screenshot
    $screenshotPath = "C:\temp\event-hub-metrics.png"
    Invoke-ScreenCapture -Path $screenshotPath
    
    # Post to Microsoft Teams
    $teamsWebhookUrl = "https://outlook.office.com/webhook/[your-teams-webhook-url]"
    $headerText = "Azure Event Hub Metrics"
    Invoke-TeamsWebhookMessage -WebhookUrl $teamsWebhookUrl -Message $headerText -ImagePath $screenshotPath
    

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful