1833874 Members
2746 Online
110063 Solutions
New Discussion

Re: ping report

 
SOLVED
Go to solution
Ahmad Munawwar
Frequent Advisor

ping report

Hello,

I having a problem to determine the network connectivity. I have an application that will generate kind of alarm on the screen if there is any problem with network connection and the alrm cease automaticcaly if the problem resolve, according to our design the script use "ping" on ICMP level and hostname to get the status of the connection. What happen now is, although the alarm is report problem with connection BUT when I ping manually it doesn't show any time out or any problem with coonection. ( the alarm generate and cease quickly)

So I am looking a script that can continously ping (delay, timeout etc..) the ip or hostname then when there is a problem with network conn it stop automatically and produce report or create log file with date and time. This will help me to match with my alarm database. Would appreciate if someone can help.

Regards,
Munawwar
7 REPLIES 7
suki
Frequent Advisor

Re: ping report

Hi Munawar,
Try the following script and modify according to your requirement.The attached script looks into a file /ADMscripts/hosts.list
(all the hostname needs to be monitored is listed in this file.
-----------------------------------------------
#!/usr/bin/ksh
ext=$RANDOM
>/tmp/status.$ext
for i in `cat /ADMscripts/hosts.list`
do
echo "$i \t \c" >>/tmp/status.$ext
z=`ping $i -n 3|grep "packet loss"|awk -F , '{print $3}'`
echo $z >>/tmp/status.$ext
loss=`echo $z|awk '{print $1}'|tr -d "%"`
if [ -z "$loss" ]
then
mailx -s "ALERT:Failure of $i NameResolution" abc@abc.com &1
elif
[ "$loss" -ne "0" ]
then
mailx -s "ALERT:$i System packet loss is $loss%" abc@abc.com &1
else
cat /dev/null
fi
done
-----------------------------------------------
harry d brown jr
Honored Contributor

Re: ping report

You need http://www.bb4.com

live free or die
harry
Live Free or Die
Darrell Allen
Honored Contributor

Re: ping report

ping may not the best tool for verifying connectivity but it can be used. However, if you use ping, send more than 1 packet and check that you do not get 100% packet loss.

Search the forums and you should find some examples.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
A. Clay Stephenson
Acclaimed Contributor

Re: ping report

I'll give you the difficult part and you simply have to write the wrapper script. Ping.pl can send and ICMP,TCP, or UDP ping to a host with a variable timeout and repeat a variable number of times. The only thing that you need to do is examine the exit status: 0 - good.

e.g.

ping.pl -I -t 5 -n 3 bugs
STAT=${?}

if [[ ${STAT} -ne 0 ]]
then
echo "Ping of host bugs failed"
fi

This will request an ICMP ping with a timeout of 5 seconds and 3 attempts on host 'bugs'. This approach is much easier that parsing stderr of ping itself and the timeout and built-in.
If it ain't broke, I can fix that.
Shannon Petry
Honored Contributor

Re: ping report

In addition to what Clay gave you, I would recommend you set this ping in a loop to recheck if failure occurs the first time. Busy hosts, busy switches, etc.. can cause an initial failure, but the second time may work.

It's worth recording all failures so that you are aware of issues, but paging/emailing for a down host that is not down will get annoying.

Harry, BB in my opinion is not very good. I spent alot of time setting it up, and making it work. I get more use out of scripts like Clay demonstrates than investing so much time in BB. BB works well for Linux, but not enough functionality for HP-UX to be worth the time.

Regards,
Shannon
Microsoft. When do you want a virus today?
Ron Kinner
Honored Contributor
Solution

Re: ping report

You probably have a WAN link which is overloaded or full of erros. An overloaded WAN link causes the packets to get in a queue to go over the WAN. If the queue gets too long new packets get dropped at random. Same with errors. Doesn't bother tcp/ip very much. It just slows down and resends the packet. However, ICMP is just the one packet and if it doesn't make it that's the end of it. Check your router's WAN interface input queues for drops.

You may need to filter out garbage that doesn't need to go over the WAN or change the queue length or type. Or if you have lots of money get more bandwidth. If it's caused by errors then get on your supllier to clean them up.

Look into MRTG. You can have it monitor the traffic and drops/errors and really see what is going on. It can even map your ping delay times if you work with it a little. Runs on most anything and is free. http://www.mrtg.cz/

Ron
Bill Thorsteinson
Honored Contributor

Re: ping report

I have been using MON which is scripted entirely in PERL.
It has a variety of alert mechanisms and monitors.
I found it easy to configure.

You can find it at:
http://www.kernel.org/software/mon/