[mrtg] Re: mrtg-ping-probe --> how can I tell when a device goes down??

Kruepke lister at kruepke.com
Fri Apr 7 23:50:33 MEST 2000


Here one possible solution.  (Others are likely to follow from the list...)  I think it should be accurate, but don't hold me to it:

while (<PING>) {
  $ping_output .= $_;
  if (m|^round-trip(?: \(ms\) )? min/avg/max(?:/stddev)? = (\d+)(?:\.\d+)?/(\d+)(?:\.\d+)?/(\d+)(?:\.\d+)?|)
    close(PING), return($1,$2,$3);
  elsif (m|^\s+Minimum\s+=\s+(\d+)(?:\.\d+)?ms,\s+Maximum\s+=\s+(\d+)(?:\.\d+)ms,\s+Average\s+=\s+(\d+)(?:\.\d+)?ms|)
    close(PING), return($1,$3,$2);
  elsif (m|100% [Ll]oss|)
    close(PING), return($deadval,$deadval,$deadval);

Basically, I've just added a condition at the end to check if the line has "100% loss" anywhere in the line.  If it does, it will return the value of the variable $deadval (3 times) and stop processing.  This code works on the assumption that the "100% loss" line will show up before the rest of the stats, which is true in this particular case.  Just bear in mind that this snippet of code may not be portable to other systems.

Be sure to either set $deadval to something meaningful to you before the loop runs (by using "$deadval = XXX;"), or take $deadval out and put in your own value(s).  I was not sure what you would want to see here.

Bear in mind that if you have 75% packet loss, this will not help you.  You will have one meaningful ping (in which case you don't want this new code to execute), but I'm not sure if those three lost packets are factored into the average calcuation as 0ms packets.  Of course, you are probably most likely to have either 0% or 100% packet loss in most cases (either completely up or completely down), so this may not be a big deal.


Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org

More information about the mrtg mailing list