How to Fix Runbook Error

Navaska 25 Reputation points
2024-10-22T21:47:32.2866667+00:00

I have an error which occasionally appears on my azure automation account runbook.

This has only happened twice in the last month, and i'm unable to determine the cause of the error. Any help would be much appreciated.

The error I get is "The SSL connection could not be established, see inner exception. (The SSL connection could not be established, see inner exception.)".image

Runbook Code:

Param(
    [string]$subscriptionId = "09bc1b84-e082-438e-9b61-5d1d59a9c061",
    [string]$resourceGroupName = "IoTVista",
    [string]$asaJobName = "iotvistastream-2",
    [int]$restartThresholdMinute = 180,
    [int]$stopThresholdMinute = 5,
    
    [int]$maxInputBacklog = 5,
    [int]$maxWatermark = 10
)
$ErrorActionPreference = 'stop'
$currentUTCtime = (Get-Date).ToUniversalTime()
Write-Host "asaRobotPause - Starting at: $currentUTCtime"
 
$resourceId = "/subscriptions/$($subscriptionId)/resourceGroups/$($resourceGroupName)/providers/Microsoft.StreamAnalytics/streamingjobs/$($asaJobName)"
Disable-AzContextAutosave -Scope Process | Out-Null
try {
    $AzureContext = (Connect-AzAccount -Identity).context
} catch {
    Write-Output "No system-assigned identity. Aborting."
    exit
}
$scheduledStartTimes = @('03:00', '06:00', '09:00', '12:00', '15:00', '18:00', '21:00', '00:00')
function IsCurrentTimeWithinStartWindow {
    param($currentTime, $times)
    $currentTime = [DateTime]::ParseExact($currentTime, 'HH:mm', $null)
    foreach ($time in $times) {
        $scheduledTime = [DateTime]::ParseExact($time, 'HH:mm', $null)
        $timeBefore = $scheduledTime.AddMinutes(-5)
        $timeAfter = $scheduledTime.AddMinutes(5)
        if ($currentTime -ge $timeBefore -and $currentTime -le $timeAfter) {
            return $true
        }
    }
    return $false
}
try {
    $currentJobState = Get-AzStreamAnalyticsJob -ResourceGroupName $resourceGroupName -Name $asaJobName | ForEach-Object {$_.JobState}
    Write-Output "asaRobotPause - Job $asaJobName is $currentJobState."
    if ($currentJobState -eq "Running") {
        $startTimeStamp = Get-AzActivityLog -ResourceId $resourceId -MaxRecord 1000 -WarningAction Ignore | Where-Object {$_.operationName -like "Start Job*"} | Select-Object -First 1 | ForEach-Object {$_.EventTimeStamp}
        $currentBacklog = Get-AzMetric -ResourceId $resourceId -TimeGrain 00:01:00 -MetricName "InputEventsSourcesBacklogged" -DetailedOutput -WarningAction Ignore
        $currentWatermark = Get-AzMetric -ResourceId $resourceId -TimeGrain 00:01:00 -MetricName "OutputWatermarkDelaySeconds" -DetailedOutput -WarningAction Ignore
        $Backlog = $currentBacklog.Data | Where-Object {$_.Maximum -ge 0} | Sort-Object -Property Timestamp -Descending | Where-Object {$_.Timestamp -ge $startTimeStamp} | Select-Object -First $stopThresholdMinute | Measure-Object -Sum Maximum
        $BacklogSum = $Backlog.Sum
        $Watermark = $currentWatermark.Data | Where-Object {$_.Maximum -ge 0} | Sort-Object -Property Timestamp -Descending | Where-Object {$_.Timestamp -ge $startTimeStamp} | Select-Object -First $stopThresholdMinute | Measure-Object -Average Maximum
        $WatermarkAvg = [int]$Watermark.Average
        Write-Output "asaRobotPause - Running since $startTimeStamp, with $BacklogSum backlogged events, and avg watermark of $WatermarkAvg sec."
        if ($BacklogSum -le $maxInputBacklog -and $WatermarkAvg -le $maxWatermark -and $Watermark.Count -ge $stopThresholdMinute) {
            Write-Output "asaRobotPause - Stopping job..."
            Stop-AzStreamAnalyticsJob -ResourceGroupName $resourceGroupName -Name $asaJobName
        } else {
            Write-Output "asaRobotPause - Job is not stopping yet. Needs less backlog and lower watermark."
        }
    } elseif ($currentJobState -eq "Stopped") {
        $stopTimeStamp = Get-AzActivityLog -ResourceId $resourceId -MaxRecord 1000 -WarningAction Ignore | Where-Object {$_.operationName -like "Stop Job*"} | Select-Object -First 1 | ForEach-Object {$_.EventTimeStamp}
        $minutesSinceStopped = ((Get-Date).ToUniversalTime() - $stopTimeStamp).TotalMinutes
        $utcTime = (Get-Date).ToUniversalTime()
        $aestTimeZoneId = "E. Australia Standard Time"
        $aestTimeZone = [TimeZoneInfo]::FindSystemTimeZoneById($aestTimeZoneId)
        $aestTime = [TimeZoneInfo]::ConvertTimeFromUtc($utcTime, $aestTimeZone)
        $currentTime = $aestTime.ToString("HH:mm")
        Write-Output "$currentTime"
        if (IsCurrentTimeWithinStartWindow -currentTime $currentTime -times $scheduledStartTimes) {
            Write-Output "asaRobotPause - Scheduled to start now."
            Start-AzStreamAnalyticsJob -ResourceGroupName $resourceGroupName -Name $asaJobName -OutputStartMode LastOutputEventTime
        } else {
            Write-Output "asaRobotPause - Not scheduled to start."
        }
    } else {
        Write-Output "asaRobotPause - Job state $currentJobState is not manageable."
    }
    $newJobState = Get-AzStreamAnalyticsJob -ResourceGroupName $resourceGroupName -Name $asaJobName | ForEach-Object {$_.JobState}
    Write-Output "asaRobotPause - Job was $currentJobState, is now $newJobState. Done."
} catch {
    throw $_.Exception.Message
}

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,297 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pavan Minukuri 1,045 Reputation points Microsoft Vendor
    2024-11-12T19:07:24.4233333+00:00

    Hi @Navaska
    Welcome Microsoft Q&A, thank you for asking question here.!
    The error message you are seeing indicates that the SSL connection could not be established. This error can occur when there is a problem with the SSL certificate, or when there is a problem with the network connection.
    To troubleshoot this issue, you can try the following steps:

    1. Check the SSL certificate: Make sure that the SSL certificate is valid and has not expired. You can check the certificate by opening the URL in a web browser and examining the certificate details.
    2. Check the network connection: Make sure that the network connection is working properly. You can try pinging the server to see if it is reachable, and you can try accessing the URL from a different network to see if the problem is with your network.
    3. Check the inner exception: The error message you provided includes an inner exception. You can try examining the inner exception to see if it provides more information about the problem.

    For Better understanding purpose please go through attached link: https://learn.microsoft.com/en-us/azure/automation/troubleshoot/runbooks https://learn.microsoft.com/en-us/azure/automation/automation-create-alert-triggered-runbook

    If u required anything please let us know, If the answer was helpful, please accept answer.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.