#Powershell - отправка данных в http-сервис 1С (basic auth). На примере открытия/закрытия инцидентов в конфигурации ЦКК.
$url = 'http://host/QMC'
$user = 'user'
$password = 'password'
#Программная часть - не изменять
$password_cred = ConvertTo-SecureString –String $password –AsPlainText -Force
$credential = New-Object –TypeName "System.Management.Automation.PSCredential" –ArgumentList $user, $password_cred
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(("{0}:{1}" -f $user,$password_cred)))
$systeminfo = Get-WmiObject -Class Win32_ComputerSystem
$srv_name = $systeminfo.Name + "." + $systeminfo.Domain
function OpenIncident($code, $type, $msg){
$body =
"<Incident xmlns=""http://www.1c.ru/1cFresh/Incidents/1_0_1_1"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
<Id>$code</Id>
<Type>$type</Type>
<Infobase/>
<Cluster>$srv_name</Cluster>
<Message>$msg</Message>
<Count>1</Count>
</Incident>"
Send $body "Open"
}
function CloseIncident($code, $type){
$body =
"<IncidentClose xmlns=""http://www.1c.ru/1cFresh/Incidents/1_0_1_1"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
<Id>$code</Id>
<Type>$type</Type>
</IncidentClose>"
Send $body "Close"
}
function Send($body, $method){
$body_send = [System.Text.Encoding]::UTF8.GetBytes($body)
$headers = @{
Authorization = "Basic $base64AuthInfo"
AcceptCharset = 'utf-8'
Accept = 'application/xml'
ContentType = 'application/xml;charset=utf-8'
}
$url_send = $url + "/hs/InputIncidentTickets/" + $method
Invoke-WebRequest -Uri $url_send -Body $body_send -Headers $headers -Credential $credential -Method POST -UseBasicParsing
}
OpenIncident "Ошибка выполнения" "Архивирование техжурналов 1С" "Ошибка архивирования технологических журналов (см. лог выполнения $PSCommandPath)"
#CloseIncident "Ошибка выполнения" "Архивирование техжурналов 1С"