Dave Krause (Customer) asked a question.

Using WhatsUp Gold 2024 to execute a PS script when Disk Space gets below a threshold

We have a threshold setup to try to run a PS script to cleanup our C: drive but it is not executing the code to do said action. We know the PS script runs fun, because we can run it from the server itself and it does cleanup the space.

 

Running the script from WhatsUp in an Action sequence is just not working. Has anyone been able to get a PS script to run properly when a thresholds has been reached to cleanup disk space on a server?

 

If so, do you have any suggestions or examples of how it worked?

 

Thanks in advance,

Dave


  • Mike Rockwell (Progress Software)

    Any errors in the logs? You must tell WhatsUp Gold that your script finished correctly of did not using the SetResult from the Context namespace, which is a WUG namespace and does not work in standard PowerShell.

     

    Could you post your script?

  • Dave Krause (Customer)

    Here is the script:

     

    The Alert Center/Action PS Script?

    $target = (Resolve-DNSName $Context.GetProperty("Address")).NameHost

    $user = $Context.GetProperty("CredWindows:DomainAndUserid")

    $password = $Context.GetProperty("CredWindows:Password")

    $securePassword = ConvertTo-SecureString $password -asPlainText -force

    $credential = New-Object -typeName System.Management.Automation.PSCredential -argumentList $user,$securePassword

    try {

    Invoke-Command -computername $target -FilePath "C:\Utils\C-Cleanup-Script.ps1" -credential $credential -AsJob -errorAction Stop

    $Context.SetResult(0, "Executed C-Cleanup-Script")

    } catch {

    $Context.SetResult(1, "Failed to execute script: $($_.exception.message)")

    }

     

    The error did mention a credential issue, but we know that the account we use with WUG works, as it is used to pull info and run things on other servers.

    • Mike Rockwell (Progress Software)

      Is this for Alert Center? Then all of the Device specific things do not work. Alert Center is a different critter. Because it is not pulling things from a device, it is pulling from data in the database and it Not device specific. I found this out when testing it. You will have to use the Percent variables from Alert Center, like "%AlertCenter.Threshold.NewItemNames". And yes, when you use them in the PowerShell script, they MUST be surrounded by quotation marks " ".

       

      For passwords, I created a secure PS file and encrypted user names and passwords and then read them from the file into the other parts of the script to connect to the device to pass credentials. Yes, it's a pain, but at least we can do PS actions with alert center now ....