# Script written by Kris Springer # https://www.krisspringer.com # https://www.ionetworkadmin.com # # This script pings a list of IP's and alerts if any are unreachable # This runs the actual ping test function PingTest($comp) { $pingtest = Test-Connection $comp -Quiet -Count 2 -ErrorAction SilentlyContinue if($pingtest){ Write-Host ("&green " + $comp) } else{ Write-Host ("&red " + $comp) } } # This section records a ping session Start-Transcript "c:\Program Files\xymon\ext\lanpingOutput.log" Write ____________________________________________ Write "`n" Write "Dell Color MFP H625cdw PCL6 Printer" PingTest("192.168.1.20") Write ____________________________________________ Write "`n" Write "Dell Color MFP H625cdw PCL6 Printer" PingTest("192.168.1.21") Write ____________________________________________ Write "`n" Write "Lexmark MS610dn Printer" PingTest("192.168.1.22") Write ____________________________________________ Write "`n" Write "HP Color LaserJet CM4540 MFP PCL6 Printer" PingTest("192.168.1.26") Write ____________________________________________ Write "`n" Write "HP Color LaserJet CM4540 MFP PCL6 Printer" PingTest("192.168.1.27") Write ____________________________________________ Write "`n" Write "HP LaserJet M4555 MFP PCL6 Printer" PingTest("192.168.1.28") Write ____________________________________________ Write "`n" Write "HP LaserJet M4555 MFP PCL6 Printer" PingTest("192.168.1.30") Write ____________________________________________ Write "`n" Write "EnGenius AP-1" PingTest("192.168.1.36") Write ____________________________________________ Write "`n" Write "EnGenius AP-2" PingTest("192.168.1.37") Write ____________________________________________ Write "`n" Write "EnGenius AP-3" PingTest("192.168.1.38") Write ____________________________________________ Write "`n" Write "EnGenius AP-4" PingTest("192.168.1.39") Write ____________________________________________ Write "`n" Write "Router" PingTest("192.168.1.1") Write ____________________________________________ Stop-Transcript # variables $log = 'c:\Program Files\xymon\ext\lanpingOutput.log' $outputFile = "C:\Program Files\xymon\tmp\lanping" $fqdnHostname = [System.Net.DNS]::GetHostByName('').HostName.ToLower() $dateString = Get-Date -Format "MM-dd-yyyy, HH:mm:ss" # This section strips out the top header junk and last tail junk from the transcript output $content1 = Get-Content $log $content1[19..($content1.length-1)]|Out-File $log $content2 = Get-Content $log $content2[0..($content2.length-5)]|Out-File $log # This section controls the red-green icon colors. function Set-Colour { If (Select-String -Pattern "OFFLINE" -Path $log) { "red" } Else { "green" } } $colour = Set-Colour # This section controls the Xymon page status reporting colors. function Status-Color { If (Select-String -Pattern "red" -Path $log) { "red" } Else { "green" } } $statusColor = Status-Color #this is displayed on the Xymon webpage $outputText = $outputText + "$statusColor+12h $dateString [$fqdnHostname]`r`n" $outputText = $outputText + "