• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 709
  • Last Modified:

A Ping Monitor

Looking for a ping monitor and success/fail logger.

I would like the ability to create a file that has the IP's or fqd to monitor.
Set how often to ping the entire list, and in a csv file output the success and fails.

So for example is I had a file called: servers.txt:
192.168.0.23
yahoo.com


And set it to ping once every 30 seconds for 24 hrs.
Output would look like this:
ping_test.csv:

4/7/2011 2:00:00 pm, 192.168.0.23, failed
4/7/2011 2:00:00 pm, yahoo.com, failed
4/7/2011 2:00:30 pm, 192.168.0.23, passed
4/7/2011 2:00:30 pm, yahoo.com, passed
4/7/2011 2:01:00 pm, 192.168.0.23, failed
4/7/2011 2:01:00 pm, yahoo.com, failed
4/7/2011 2:01:30 pm, 192.168.0.23, failed
4/7/2011 2:01:30 pm, yahoo.com, passed
4/7/2011 2:02:00 pm, 192.168.0.23, failed
4/7/2011 2:02:00 pm, yahoo.com, failed

and so on for 24 hours.

Would like to be able to set the how often it does ping and for how long it does test for.
0
Ed Walsh
Asked:
Ed Walsh
  • 6
  • 3
1 Solution
 
Bart-VandyckCommented:
$TimeToSleep=30
$outputfile="c:\temp\output.txt"
$Targets=cat c:\temp\listtoping.txt


for(;;)
{
    foreach ($target in $targets)
    {
     if (test-connection $target -q) 
     {
        $Result = (get-date -format g) +", $target, passed"
     }
     else
     {
        $result = (get-date -format g) +", $target, failed" 
     }
    $result | out-file $outputfile -append
    }
 start-sleep $timetoSleep
} 

Open in new window


The For (;;) creates an infinite loop!
0
 
Bart-VandyckCommented:
I did not see you wanted it to stop after a certain amoint of time. Just change the variable $HoursToTest


$TimeToSleep=30
$HoursToTest=24
$outputfile="c:\temp\output.txt"
$Targets=cat c:\temp\listtoping.txt

$starttest=get-date

Do
{
    foreach ($target in $targets)
    {
     if (test-connection $target -q) 
     {
        $Result = (get-date -format g) +", $target, passed"
     }
     else
     {
        $result = (get-date -format g) +", $target, failed" 
     }
    $result | out-file $outputfile -append
    }
 start-sleep $timetoSleep
} 
while (((get-date) - $StartTest).Hours -lt $HoursToTest)

Write-host "Stopped testing @ " (get-date -format g)

Open in new window

0
 
Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
@Bart-Vandyck
This is great thank you.
I forgot to include I need the output of the passed test.
so for example
A ping would show this:
Reply from 192.168.0.5: bytes=32 time=6ms TTL=61

If it passed, I also need the time (6ms in this example) and the TTL (61 in this example) if failed just leave , (commas).

So as an example the output file would look like this. (the first row is the column names, more for explanation and not absolutely needed in output file, but if you can add it that saves me from pasting it in later.)

Date_time_of_test, target, passed_fail, time, ttl
4/8/2011 8:34.00 AM, 192.168.0.5, passed, 6ms, 61
4/8/2011 8:34.30 AM, 192.168.0.5, passed, 4ms, 60
4/8/2011 8:35.00 AM, 192.168.0.5, passed, 6ms, 62
4/8/2011 8:35.30 AM, 192.168.0.5, failed, ,
4/8/2011 8:36.00 AM, 192.168.0.5, passed, 6ms, 62
4/8/2011 8:36.30 AM, 192.168.0.5, failed, ,

0
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

 
Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
@Bart-Vandyck

Also forgot to mention in above, but I did show in example, I would need the seconds in the time stamp. Since I would like to set the test time for less than a minute most of the times so would need the seconds to show on the time stamp.

0
 
Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
@Bart-Vandyck

Figured out how to capture the time with seconds, changed the "get-date -format g"  to "get-date -format G"

However, if possible, would still like to capture the "passed" attempts time and TTL data, as mentioned above.

Thanks again for this.

0
 
Bart-VandyckCommented:
$TimeToSleep=30
$HoursToTest=3
$outputfile="c:\temp\output.txt"
$Targets=cat c:\temp\listtoping.txt

$starttest=get-date

$ErrorActionPreference="SilentlyContinue"

Do
{
    foreach ($target in $targets)
    {
     
     $PingTest=test-connection $target -count 1
     if ($PingTest) 
     {
        $Result = (get-date -format g) +", $target, passed, " + $pingTest.responsetime + "," + $pingTest.TimeToLive
     }
     else
     {
        $result = (get-date -format g) +", $target, failed" 
     }
    $result | out-file $outputfile -append
    }
 start-sleep $timetoSleep
} 
while (((get-date) - $StartTest).Hours -lt $HoursToTest)

Write-host "Stopped testing @ " (get-date -format g)

Open in new window



Try this..
0
 
Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
This is great thank you.
I made some changes so the date/time shows with seconds and so the column names row is added to the top of the output file.

For the "failed" results, anyway to drop in the , (commas) for Response Time and TTL, I will be importing this into excel as a csv and with no commas will cause a problem.

$TimeToSleep=5
$HoursToTest=3
$outputfile="c:\Ping_Test\output.txt"
$Targets=cat c:\ping_Test\Ping_targets.txt

$starttest=get-date

$ErrorActionPreference="SilentlyContinue"

"date_time, target, Passed_failed, Response_Time, TTL" | out-file $outputfile -append
Do
{

    foreach ($target in $targets)
    {
         
     $PingTest=test-connection $target -count 1
     if ($PingTest)
     {
        $Result = (get-date -format G) +", $target, passed, " + $pingTest.responsetime + "," + $pingTest.TimeToLive
     }
     else
     {
        $result = (get-date -format G) +", $target, failed"
     }
    $result | out-file $outputfile -append
    }
 start-sleep $timetoSleep
}
while (((get-date) - $StartTest).Hours -lt $HoursToTest)

Write-host "Stopped testing @ " (get-date -format G)
0
 
Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
Never mind I figured out how to do the extra commas for the failed line.

Thank you VERY much. This helps me a lot.

$TimeToSleep=5
$HoursToTest=3
$outputfile="c:\Ping_Test\output.txt"
$Targets=cat c:\ping_Test\Ping_targets.txt

$starttest=get-date

$ErrorActionPreference="SilentlyContinue"

"date_time, target, Passed_failed, Response_Time, TTL" | out-file $outputfile -append
Do
{

    foreach ($target in $targets)
    {
         
     $PingTest=test-connection $target -count 1
     if ($PingTest)
     {
        $Result = (get-date -format G) +", $target, passed, " + $pingTest.responsetime + "," + $pingTest.TimeToLive
     }
     else
     {
        $result = (get-date -format G) +", $target, failed , ,"
     }
    $result | out-file $outputfile -append
    }
 start-sleep $timetoSleep
}
while (((get-date) - $StartTest).Hours -lt $HoursToTest)

Write-host "Stopped testing @ " (get-date -format G)
0
 
Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
When I added the two commas after the "failed"  in line 22 it works perfectly. Great answer and  thank you very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now