stephanlinke

[PRTG] Read Date from OID

Oct 7th, 2016
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # note: it's easier if you enter the parameters directly in the script and save it.
  2. # Only the sensor ID should be passed like this in the sensors parameter settings: -sensorid 1234
  3. param(
  4.     $prtgusername  = "<the-username-you-want-to-use>",
  5.     $prtgpasshash  = "<your-prtg-user-passhash>",
  6.     $sensoroid     = <the id of the sensor that retrieves the timestamp>,
  7.     $prtg          = "<the-url-of-your-prtg-server, e.g. http://your-prtg-server>"
  8. )
  9.  
  10. $prtgurl = ([string]::Format("http://{3}/api/getsensordetails.json?id={0}&username={1}&passhash={2}",$sensoroid,$prtguser,$prtgpass,$prtg))
  11. $result =  ((Invoke-WebRequest -UseBasicParsing $prtgurl) | ConvertFrom-Json).sensordata.lastmessage
  12.  
  13. [datetime]$timestamp        = [datetime]::ParseExact($result,"yyyy-mm-dd HH:MM:ss",$null)
  14. [datetime]$currentTimeStamp = (Get-Date);
  15.  
  16. $timediff = (New-TimeSpan -Start $timestamp -End $currentTimeStamp).Seconds
  17. if($timediff -lt 0){ $timediff = $timediff * -1 }
  18.  
  19. Write-Host ("{0}:Current time offset between PRTG and host: {0} seconds" -f $timediff);
Advertisement
Add Comment
Please, Sign In to add comment