azure - Azure 自动化在返回 400 错误的混合工作人员上调用内部应用程序 Rest API
问题描述
我正在尝试构建 Azure 自动化运行手册来解锁本地 AD 帐户。帐户解锁后,我想向具有 API 的 ITSM 应用程序提交票证。我能够在 Windows PowerShell 中的服务器上创建调用并获得返回码 200。
但是,当我从 Azure 自动化运行它时,我收到 400 bad request 的错误代码。关于为什么我可以使用 Windows PowerShell 在服务器上进行调用,但不能在混合工作人员上调用 Azure 自动化,有什么想法吗?
Custom_ITSM_API_Module 的模块是一个本土模块,在我尝试过的每个地方都可以使用。它适用于我的开发计算机 (Windows PowerShell) 和混合工作服务器 (Windows PowerShell),但在使用 Azure 自动化时不起作用。
代码:
Param
([object]$WebhookData) #this parameter name needs to be called WebHookData otherwise the webhook does not work as expected.
$VerbosePreference = 'continue'
Import-Module ActiveDirectory
Import-Module "Custom_ITSM_API_Module"
#region Verify if Runbook is started from Webhook.
# If runbook was called from Webhook, WebhookData will not be null.
if ($WebHookData){
# Collect properties of WebhookData
$WebhookName = $WebHookData.WebhookName
$WebhookHeaders = $WebHookData.RequestHeader
$WebhookBody = $WebHookData.RequestBody
# Collect individual headers. Input converted from JSON.
$From = $WebhookHeaders.From
$RequestData = (ConvertFrom-Json -InputObject $WebhookBody)
Write-Output -InputObject ('Input: {0}' -f $RequestData )
Write-Output ('WebhookBody: {0}' -f $WebhookBody)
Write-Output -InputObject ('Runbook started from webhook {0} by {1}.' -f $WebhookName, $From)
$User = Get-ADUser $RequestData.SamAccountName -Properties *
If($User.SamAccountName.count -ne 1 ){
throw "Found $($User.SamAccountName.count) user(s). Please make sure this user is unique"
}
else{
Write-Output "Unlocking User"
Unlock-ADAccount -Identity $User
$RanByEmployeeID = $RequestData.RanByEmployeeID
$Runby = Get-ADUser -Filter {EmployeeID -eq $RanByEmployeeID} -Properties EmployeeID
$Description = "User Unlcoked<br>EmployeeID: $($User.EmployeeID)<br>SamAccountName: $($User.SamAccountName)<br>Unlocked at: $((Get-Date).ToString())"
Write-Custom_ITSM_API_ModuleTicket -Title "Unlocked User $($User.Name)"-Description $Description
}
}
else{
Write-Error -Message 'Runbook was not started from Webhook' -ErrorAction stop
}
解决方案
我遇到的问题实际上是我们的防火墙和代理的问题。这些服务器无法与建议的所有 Azure/O365 URL 通信。一旦我们将所有 URLS 列入白名单,我就可以与我的内部应用程序对话。
推荐阅读
- sql - 多个总和聚合
- java - 无法更新詹金斯
- c++ - 将 OpenCV Mat 转换为“位掩码”
- flutter - Flutter 应用程序音频播放器不播放 url src
- swift - 如何从模态呈现的视图控制器返回到选定的选项卡栏视图控制器?
- python - 如何使鼠标在给定时间范围内平滑过渡到新的相对位置
- groovy - 使用 binding.variables 创建的 SimpleTemplate 在转换为 String 时终止执行
- powershell - Powershell 将访客用户添加到启用邮件的安全组
- windows - 获取短期文件的内容
- r - 为什么“surv.svm”在 R 的“mlr3proba”包中显示错误?