Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
Last active November 12, 2016 14:28
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 mattmcnabb/1e8585b12c7b0ef8b27fc6949ceb6bbd to your computer and use it in GitHub Desktop.
Save mattmcnabb/1e8585b12c7b0ef8b27fc6949ceb6bbd to your computer and use it in GitHub Desktop.
OMS-custom-monitor_1
Import-Module OneLogin
$Credential = Get-Credential
$Token = New-OneLoginToken -Credential $Credential -Region us -SetAsDefault
$Events = Get-OneLoginEvent -Since (Get-Date).AddHours(-1)
Import-Module OneLogin
Import-Module OMSDataInjection
$OMSWorkSpaceID = "<your workspace ID here>"
$OmsPrimaryKey = "<your key here>"
$OmsSecondaryKey = "<your key here>"
$LogType = "OneLoginEvent"
$TimeStampFieldName = "LogTime"
# calculate start and end times for the previous hour
$Now = Get-Date
$CurrentHour = $Now.Hour
$PreviousHour = $Now.AddHours(-1).Hour
$Today = Get-Date | Select-Object -ExpandProperty Date
$Begin = $Today.AddHours($PreviousHour)
$End = $Today.AddHours($CurrentHour)
try
{
New-OneLoginToken -Credential $OneLoginApiCredential -Region us -SetAsDefault
$HourEvents = Get-OneLoginEvent -Since $Begin -Until $End
}
catch { exit }
$OMSSplat = @{
OMSWorkSpaceId = $OmsWorkspaceId
PrimaryKey = $OmsPrimaryKey
SecondaryKey = $OmsSecondaryKey
LogType = $LogType
}
foreach ($Event in $HourEvents | Select-Object -Property *,@{n=$TimeStampFieldName; e={$_.created_at.UtcDateTime}} -ExcludeProperty created_at)
{
try
{
New-OMSDataInjection @OMSSplat -OMSDataObject $Event -UTCTimeStampField $TimeStampFieldName
}
catch
{
Write-Error $_
}
}
Install-Module OneLogin
Install-Module OMSDataInjection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment