Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created June 25, 2018 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/9211234c8d25321b0f9e9d661d5c6309 to your computer and use it in GitHub Desktop.
Save guitarrapc/9211234c8d25321b0f9e9d661d5c6309 to your computer and use it in GitHub Desktop.
$user ="Input UserName"
$credential = Get-SumoCredential -User $user -force
$Collectors = Get-SumoApiCollectors -Credential $credential
$sets = @(
("LogName","LogPath","Desctiption"),
("LogName","LogPath","Desctiption")
)
$jsons = $sets `
| %{ @{
source = @{
pathExpression = $_[1]
name = $_[0]
sourceType = "LocalFile"
category = $_[0]
description = $_[2]
alive = $true
states = ""
automaticDateParsing = $true
timeZonne = "Asia/Tokyo"
multilineProcessingEnabled = $true
}} ` | ConvertTo-Json
}
$osName = "Windows Server 2012"
$name = "hogehoge*"
$collectors `
| where osName -eq $osName `
| where Name -like $name `
| %{
try
{
foreach ($json in $jsons)
{
Invoke-RestMethod -Method Post -Uri "https://api.sumologic.com/api/v1/collectors/$($_.id)/sources/" -Credential $cred -ContentType "application/json" -Body $json -ErrorAction Stop
}
}
catch
{
throw $_
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment