Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ___ ___ _____ ___
- #| _ \ _ \_ _/ __|
- #| _/ / | || (_ |
- #|_| |_|_\ |_| \___|
- # NETWORK MONITOR
- #-------------------
- # Description: Reads performance counters from a file, retrieves them and puts them into channels
- # ------------------
- # (c) 2015 Stephan Linke | Paessler AG
- Param(
- [string]$Computername,
- [string]$CounterFile = "counter-cpu.dat" )
- #Variables
- [string]$CounterBasePath = "C:\temp\"
- [string]$CounterPath = $CounterBasePath + $CounterFile
- [int]$i = 1
- # lets test the connection first
- If(!(Test-Connection -Count 1 -Quiet $Computername)) { Write-Host "<prtg><error>1</error><text>Host not found.</text></prtg>"; exit 2; }
- # create a new counter list
- $CounterList = New-Object System.Collections.ArrayList
- # retrieve the counters and add them to the list
- $Counters = (Get-Content -Path $CounterPath | ConvertFrom-Csv -Delimiter ";")
- # add the path from the csv to an array list so we can use it with get-counter
- $Counters | ForEach-Object { $CounterList.Add($_.Path)} | Out-Null
- # retrieve the counters
- $ResultSet = (Get-Counter -ComputerName $Computername -Counter $CounterList)
- # add the values to the corresponding counter object
- Foreach($Result in $ResultSet.CounterSamples){
- $Counters | Where {$_.ID -eq $i } | Add-Member "Value" $Result.CookedValue
- $i++;
- }
- Write-Host "<?xml version='1.0' encoding='UTF-8' ?><prtg>";
- Foreach ($Counter in $Counters){
- Write-Host @"
- <result>
- <channel>$($Counter.FriendlyName)</channel>
- <value>$($Counter.Value)</value>
- <unit>$($Counter.Unit)</unit>
- <float>$($Counter.Float)</float>
- </result>
- "@
- }
- Write-Host "</prtg>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement