Advertisement
stephanlinke

PRTG-FindFalsePositives

Oct 19th, 2016
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #
  2. #requires -version 4.1
  3. # ___ ___ _____ ___
  4. #| _ \ _ \_   _/ __|
  5. #|  _/   / | || (_ |
  6. #|_| |_|_\ |_| \___|
  7. # FALSE POSITIVE CHECKER
  8. # ================================
  9. #>
  10.  
  11. param( [int]$id         = 0, # UNIQE Sensor Identifyer
  12.        [string]$message = "",# Last Error Message
  13.        [string]$match   = "",# "PE015" ==> Timeout Error on Sensor
  14.        [int]$triggers   = 10,# MAX Counter for repeats on Sensor refreshes
  15.        [int]$wait       = 10)# Time delay between repeats in seconds
  16.  
  17. $PRTG_PROT = ""
  18. $PRTG_HOST = ""
  19. $PRTG_PORT = 0
  20. $PRTG_USER = ""
  21. $PRTG_PASS = 0
  22. $LOGFILE = "C:\ProgramData\Paessler\PRTG Network Monitor\Logs (Sensors)\$($id)-notifications.log"
  23.  
  24. $url = ([string]::Format("{0}://{1}:{2}/api/scannow.htm?id={3}&username={4}&passhash={5}",
  25.                           $PRTG_PROT,$PRTG_HOST,$PRTG_PORT,$id,$PRTG_USER,$PRTG_PASS));
  26.  
  27. $i = 0;
  28.  
  29. # this will output debug messages to the LogFile
  30. function Console-ShowMessage([string]$type,$message1){
  31.         $date = (Get-Date).ToString()
  32.         $log = ([string]::Format("[{0}] [{1}] - {2}",$date,$type,$message1));
  33.         $log | Out-File $LOGFILE -Append
  34. }
  35.  
  36. if($message -match $match){ #Sensor ran into Timout
  37.     Console-ShowMessage -type "warning" -message1 "Sensor is probably in a false positive state - force checking..."
  38.     try{
  39.         while($i -lt $triggers){ #for($i =< $triggers){
  40.             Console-ShowMessage -type "info" -message1 "Iterate $i"
  41.             Start-Sleep -Seconds $wait
  42.             Invoke-WebRequest $url | Out-Null
  43.             $i++;
  44.         }
  45.         Console-ShowMessage -type "success" -message1 "Sensor has been triggered a few times and should be UP now."
  46.     }
  47.     catch [Exception]{
  48.         Console-ShowMessage -type "error" -message1 "Could not trigger the sensor check. Notes below:"
  49.         Console-ShowMessage -type "notes" -message1 $_.Exception.Message
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement