Badgerati / Pode

Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
https://badgerati.github.io/Pode
MIT License
832 stars 92 forks source link

Add Native Logging to Splunk #1018

Open jbaechtelMT opened 1 year ago

jbaechtelMT commented 1 year ago

It would be great to have a logging option to write logs directly to Splunk

Badgerati commented 1 year ago

Hi @jbaechtelMT,

Splunk I haven't considered before, but Azure Log Analytics and AWS Cloudwatch I've though about. I'll have to go through the Splunk docs some time :)

robinmalik commented 1 year ago

Incase this helps, I have this test code to send data to Splunk when spinning up a copy in Docker (it's very particular about the datetime format):

$data = Get-Process | Select-Object name, id, cpu | Select-Object -First 10
$key = 'blah'
$Uri = "http://localhost:8088/services/collector"
$HostName = $env:computername
$DateTime = (Get-Date)
$unixEpochStart = New-Object -TypeName DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, ([DateTimeKind]::Utc)
$unixEpochTime = [int]($DateTime.ToUniversalTime() - $unixEpochStart).TotalSeconds
$Body = ConvertTo-Json -InputObject @{event = $data; host = $HostName; time = $unixEpochTime } -Compress
Invoke-RestMethod -Uri $uri -Method Post -Headers @{Authorization = "Splunk $Key" } -Body $Body
HeyItsGilbert commented 4 months ago

Having a handy logger function that could write logs async (so as not to block responses) would be really helpful. Maybe the end user could supply the function to process the logs. That would allow Splunk or whatever desired logger to work. Setting up and maintaining the runspace that would take in the logs would probably be handy for Pode to set up.