Advertisement
stephanlinke

PRTG - FalsePostiveChecker

Aug 31st, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. #requires -version 4.0
  3. # ___ ___ _____ ___
  4. #| _ \ _ \_   _/ __|
  5. #|  _/   / | || (_ |
  6. #|_| |_|_\ |_| \___|
  7. # FALSE POSITIVE CHECKER
  8. # ================================
  9. #>
  10.  
  11. param( [int]$id         = 0,
  12.        [string]$message = "",
  13.        [string]$match   = "",
  14.        [int]$triggers   = 10,
  15.        [int]$wait       = 10)
  16.  
  17. $prtgprot = ""
  18. $prtghost = ""
  19. $prtgport = 80
  20. $prtguser = ""
  21. $prtgpass = 0
  22. $logfile = "C:\ProgramData\Paessler\PRTG Network Monitor\Logs (Sensors)\$($id)-notifications.log"
  23.  
  24. # this will output debug messages to the console
  25. function Console-ShowMessage([string]$type,$message){
  26.         $date = (Get-Date).ToString()
  27.        
  28.         $log = ([string]::Format("[{0}] [{1}] - {2}",$date,$type,$message));
  29.  
  30.         $log | Out-File $logfile -Append
  31.    
  32. }
  33.  
  34. $url = ([string]::Format("{0}://{1}:{2}/api/scannow.htm?id={3}&username={4}&passhash={5}",
  35.                           $prtgprot,$prtghost,$prtgport,$id,$prtguser,$prtgpass));
  36.  
  37. $i = 0;
  38.  
  39. if($message -match $match){
  40.    
  41.     Console-ShowMessage -type "warning" -message "Sensor is probably in a false positive state - force checking..."
  42.     try{
  43.     while($i -lt $triggers)
  44.     {
  45.        Start-Sleep -Seconds $wait
  46.        Invoke-WebRequest $url | Out-Null
  47.        $i++;
  48.     }
  49.     Console-ShowMessage -type "success" -message "Sensor has been triggered a few times and should be UP now."
  50.     }
  51.     catch [Exception]{
  52.     Console-ShowMessage -type "error" -message "Could not trigger the sensor check. Notes below:"
  53.     Console-ShowMessage -type "notes" -message $_.Exception.Message
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement