This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Scheduled task using Powershell or similar to disable/enable alerts during maintenance windows

Hello all,

We have scheduled maintenance windows typically once a month that start at 4 AM and end at 7 AM. We integrate SolarWinds NPM with PagerDuty to send alerts so during the maintenance window, we manually disable the SolarWinds alerts that would typically generate alerts in PagerDuty for obvious reasons.

At least twice now, we have forgotten to enable those alerts after the maintenance window has finished (this time for over 2 weeks before we noticed) so we'd like to automate this process.

After some research and playing around, I installed the SWQL Studio tool and was able to get the URI of the 2 alerts that need to be disabled and enabled. I was even able to use the Postman REST client to change the "Enabled" value of an alert to False and then back to True.

Now comes the part where I'm out of my depth... Well I was out of my depth initially as well. I'd like to schedule this as an scheduled task on our Orion server. I'm assuming this must be done in PowerShell but if there's another way, please feel free to correct me. Also, I have little to no PowerShell experience besides running some Cmdlets so if someone could provide some direction, I would really appreciate it.

Essentially, what I want to do is this:

Set the Enabled field of swis://orionserver/Orion/Orion.AlertConfigurations/AlertID=99 and swis://orionserver/Orion/Orion.AlertConfigurations/AlertID=100 to False during the maintenance window and back to True when the maintenance window ends.

Regards,

Keith

  • You don't have to do it on PowerShell, but I think that would be the easiest option for this setup.

    To enable your alerts from PowerShell running on the Orion server:

    Add-PSSnapin SwisSnapin

    $swis = Connect-Swis -Certificate

    $alerts = @("swis://orionserver/Orion/Orion.AlertConfigurations/AlertID=99", "swis://orionserver/Orion/Orion.AlertConfigurations/AlertID=100")

    $alerts | Set-SwisObject $swis -Properties @{Enabled=$true}

    To disable them, do the same thing but with $false on the last line.

    Using the "-Certificate" option for Connect-Swis means that the powershell script needs to be running on the Orion server under a user context that has rights to read the cert's private key. That means local admin. Another authentication option would be to run the scheduled task as a Windows (AD) user that has rights to log in to Orion (assuming you use AD auth for Orion, of course) and connect using "Connect-Swis -Trusted" instead. A third authentication option would be to put the Orion username and password in the script and connect using "Connect-Swis -Username 'myusername' -Password 'mypassword'" - in that case it doesn't matter what Windows user context the script runs under, but of course now you have a password in a script file.

  • Wow this is so simple, yet I was so far off. I had just gotten to the point of playing with and connecting to the Orion server via PowerShell on my desktop before seeing this reply. Thank you so much!

  • Just tried this, it appears there's an error with line 4 after the -Properties switch.

    Set-SwisObject : The credentials supplied to the package were not recognized

    At C:\Scripts\Enable-PagerDutyAlerts.ps1:4 char:11

    + $alerts | Set-SwisObject $swis -Properties @{Enabled=$true}

    +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [Set-SwisObject], Win32Exception

        + FullyQualifiedErrorId : System.ComponentModel.Win32Exception,SwisPowerShell.SetSwisObject

    Doing a man on Set-SwisObject didn't really shed any light to me on what the problem is.

  • The real problem is with the Connect-Swis line. That command actually only creates a connection object - the connection is not opened until you try to use it. There is some problem with authentication, but you aren't finding out until Set-SwisObject tries to open the connection.

    Which authentication method did you go with? What does your Connect-Swis line look like?

  • Verbatim of how you put it in. I now know based on your reply that you did not assume anything for the connection and that i must set that up myself!

  • In that case, this error could be caused if the account you are PowerShell running under does not have rights to read that private key. If User Account Control is turned on in Windows and your PowerShell process is not elevated, that can also interfere. Options: use an elevated local admin context for PowerShell or switch to a different authentication method.

  • That's what it was. I went back to your code, but ran PowerShell ISE as an Administrator and it worked. I was able to disable and enable the alerts using your script. Thank you!!!

  • Adding this link for anyone who sees this and wants to try and reverse engineer the code. Great examples of what is happening:

    https://github.com/solarwinds/OrionSDK/wiki/PowerShell