Hi,
Im trying to build a powershell module, that allows me to ship logs to a humio endpoint.
But im having issues with converting my data to JSON:
[array]$Events = @()
$JsonBody = @(
@{
tags = @{
host = $env:COMPUTERNAME
ModuleType = "SQLBaseline2"
}
Events = @{
timestamp = get-date
attributes = @{
StatusCode = "Info"
RequestMethod = "GET"
PSRunbook = "Runbook123"
SQLInstance = "instance123"
CustomMessage = "wohoo"
}
}
}
) | ConvertTo-Json -Depth 10
$JsonBody
Invoke-RestMethod -Method Post -Uri "http://redacted.humio.endpoint/api/v1/ingest/humio-structured" -Headers $HumioHeader -Body $JsonBody -SkipCertificateCheck -ContentType "application/json"
I managed to get it working with this code instead, but i would really like to know what the reason is, why the first example isnt working.
$Events = @{
timestamp = get-date
attributes = @{
StatusCode = "Info"
RequestMethod = "GET"
PSRunbook = "Runbook123"
SQLInstance = "instance123"
CustomMessage = "wohoo"
}
}
$JsonBody = ConvertTo-Json -InputObject @(
@{
tags = @{
host = $env:COMPUTERNAME
ModuleType = "SQLBaseline2"
}
events = $Events
}
) -Depth 10
$JsonBody
Invoke-RestMethod -Method Post -Uri "http://redacted.humio.endpoint/api/v1/ingest/humio-structured" -Headers $HumioHeader -Body $JsonBody -SkipCertificateCheck -ContentType "application/json"
Can you explain to me why? ![]()