Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ___ ___ _____ ___
- #| _ \ _ \_ _/ __|
- #| _/ / | || (_ |
- #|_| |_|_\ |_| \___|
- # NETWORK MONITOR
- #-------------------
- # Description: This sensor will read water pump informations and error out if it has been running too often in the given interval
- # Parameters:
- # -TargetHost: The host address of the target appliance. Using %host within PRTG will work.
- # -Port The used SNMP port, defaulting to 161
- # -Community The SNMP community
- # -Oids The OID
- # -SensorID The ID of the sensor
- # -Minutes The Interval the sensor should look for pump state entries
- #
- # Requirements
- # ------------------
- # - needs snmpget.exe within the EXEXML directory (can be obtained via https://www.snmpsoft.com/cmd-tools/snmp-get/)
- #
- # Version History
- # ------------------
- # Version Date Notes
- # 1.0 09/02/2017 Initial Release
- #
- # ------------------
- # (c) 2017 Stephan Linke | Paessler AG
- param(
- [string]$TargetHost = "",
- [int]$SensorID,
- [int]$Port = 161,
- [int]$Minutes = 30,
- [string]$Community = "public",
- [string[]]$Oids = @("1.3.6.1.5")
- )
- $Result = @"
- <?xml version="1.0" encoding="UTF-8" ?>
- <prtg>
- <result>
- <channel>Current State</channel>
- <value>{0}</value>
- <NotifyChanged></NotifyChanged>
- </result>
- <result>
- <channel>Runs in the past {1} minutes</channel>
- <value>{2}</value>
- </result>
- <text>{3}</text>
- </prtg>
- "@
- $EventFilter = @{
- ProviderName="PRTG Network Monitor Sensors";
- LogName="PRTG Sensor Logs";
- ID=1;
- StartTime=(get-date).AddMinutes(-$Minutes)
- }
- function getOid([string]$Oid){
- $pinfo = New-Object System.Diagnostics.ProcessStartInfo
- $pinfo.FileName = "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\snmpget.exe"
- $pinfo.RedirectStandardError = $true
- $pinfo.RedirectStandardOutput = $true
- $pinfo.UseShellExecute = $false
- $pinfo.Arguments = [string]::Format("-r:{0} -p:{1} -t:10 -c:{2} -o:{3} -q", $TargetHost, $Port,$Community, $Oid);
- $p = New-Object System.Diagnostics.Process
- $p.StartInfo = $pinfo
- $p.Start() | Out-Null
- #Do Other Stuff Here....
- $p.WaitForExit()
- return $p.StandardOutput.ReadToEnd();
- }
- $state = [convert]::ToInt32((getOid -oid $Oids[0]).Trim(), 10);
- # create an event log entry
- Write-EventLog -LogName 'PRTG Sensor Logs' -Source "PRTG Network Monitor Sensors" -Message "Water pump is in state $($state)" -ID $state -EntryType Information
- # get the amount of entries in the last x minutes
- $Events = (Get-WinEvent -FilterHashtable $EventFilter)
- if($State -eq 1)
- { $Message = [string]::Format("The water pump is currently running ({0} runs in the last $($Minutes) minutes)",$Events.Count) }
- else
- { $Message = [string]::Format("The water pump is currently not running ({0} runs in the last $($Minutes) minutes)",$Events.Count) }
- Write-Host ([string]::Format($result, $State, $Minutes, $Events.Count, $message));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement