0

I'm using the REST API via Powershell to add a description to computers. For some systems this fails with the error "The requested hostname already exists." It works for systems where the computer exists once in TM but not if the system exists twice.

This is in DSaaS.

Here is the powershell script part with the rest calls in it. The same call works for a server with a unique name in DS but not for servers which exist multiple times

{
$srv = $_.Name
$ci = $_.CI

$searchbody = @{
"searchCriteria"= @{
"fieldName" = "hostName"
"stringTest" = "equal"
"stringValue" = $srv+'%'}
}

$json = ConvertTo-Json $searchbody

$srvuri = "$url/computers/search?expand=none"

$computer = Invoke-RestMethod -Uri $srvuri -Method Post -Headers $headers -Body $json -ContentType 'application/json' -Proxy $proxy

$computer.computers | ForEach-Object {
$computerid = $_.ID

"{0} Setting CI $ci for Server $srv with ID {1}" -f (Get-Date -Format u),$computerid
$date = Get-Date -Format "yyyy-MM-dd"
$_.description+= "`n$($date): $ci"

$updatejson = ConvertTo-Json $_
$updateuri="$url/computers/$computerid"
$computerupdate = Invoke-RestMethod -Uri $updateuri -Method Post -Headers $headers -Body $updatejson -ContentType 'application/json' -Proxy $proxy
}
}  

Any explanation what mistake I make here is highly apreciated.

Bassmann
  • 1
  • 1
  • Hi @Bassmann, I am on the Deep Security team and we are investigating your question. Are you able to tell us if you actually have multiple computers with the same host name? And if so, do you know how is it that they have duplicate host names? – ScottBro Jan 02 '20 at 21:02
  • I'm sure I have duplicate computers with the same name in DSaaS. Partly this is because we started using the Azure agent only after a lot of servers had already been deployed. For some reasons sometimes the mapping to the existing computer doesn't work. The first REST call provides indeed different ID values which makes me wonder why the unique IDs aren't sufficient. Since this is sensitive information I cannot share the actual data here but I could share via TM support if that helps – Bassmann Jan 03 '20 at 13:12
  • The API does not support modifying a computer that has a non-unique host name. We have created an issue to support this use case. I think your workaround is to remove the duplicates (i.e. the computers that you originally added before you started using the Azure agent) before you run your script. – ScottBro Jan 03 '20 at 16:57
  • Thanks for the update. I find the behavior somewhat odd given that the update uses the id not the name but the good to know it's not my fault ;-). Is there a timeline when it will be available? – Bassmann Jan 21 '20 at 14:34
  • I'm sorry, I don't have an ETA for that – ScottBro Jan 27 '20 at 12:56

0 Answers0