I was looking for a way to schedule the muting of alerting on individual nodes between specific times every day. I couldn't find a way to achieve this on a single node without having to create multiple alerts for specific instances. I have several servers which generate alerts daily during virus scans, or backups. I found a sample on github from the SDK and have edited to achieve what I want, but I don't understand why this is not an option as default, I can only assume I am missing something obvious and the ability is there, I just missed it? Would rather have an out-of-the-box solution rather than this. I see the option to do it on a specific day, but you cant simply pick a time instead.
If not, then feel free to use the below.
node,timefrom,timeto SERVER01,16:30:00,17:30:00 SERVER02,16:30:00,17:30:00
The script needs to be run on a schedule at the start of each day as the script imports the above from CSV format and then proceeds to build a hash table formatting the date using the current day as its date to schedule and adds on the time from the CSV.
Import-Module SwisPowerShell $OrionServer = 'localhost' $Username = '' $Password = '' $swis = Connect-Swis -Hostname $OrionServer -Username $Username -Password $Password #Get Nodes and schedule from csv file and convert date $Nodes = Import-Csv 'C:\Scripts\nodes-mute-schedule.csv' $Today = Get-Date -Format dd/MM/yyyy $Schedule = Foreach ($Node in $Nodes){ $Table = [PsCustomObject]@{ Node = $Node.node entityUris = $entityUris = Get-SwisData $swis "SELECT Uri FROM Orion.Nodes WHERE Caption IN @captions" @{captions=($node.node)} TimeFrom = ($Today +" "+ $Node.timefrom -as [DateTime] ) TimeTo = ($Today +" "+ $Node.timeto -as [DateTime] ) } $Table } # Suppress alerts for one or more entities Foreach ($object in $Schedule){ $entityUris = $object.entityUris $entityUris = @( $entityUris |% {[string]$_} ) Invoke-SwisVerb $swis Orion.AlertSuppression SuppressAlerts @($entityUris, $object.Timefrom.AddHours(1), $object.Timeto.AddHours(1)) | Out-Null } # List alert suppressions Get-SwisData $swis "SELECT ID, EntityUri, SuppressFrom, SuppressUntil FROM Orion.AlertSuppression"