开发者

Bash Script to allow Nagios to report ping between two other Linux machines

开发者 https://www.devze.com 2023-01-27 08:22 出处:网络
I\'m looking for alternatives to working out the ping between two machine (mA and mB) and report this back to Nagios (on mC).

I'm looking for alternatives to working out the ping between two machine (mA and mB) and report this back to Nagios (on mC).

My current thoughts are to write a BASH script that will ping the machines in a cron job, output the data to a file then have another bash script that Nagios can use to read that file. This doesn't feel like the best/right way to do this though?

Here's the script I plan to run in the cron job:

#!/bin/bash

if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]
then
   echo $0: usage: $0 file? ip? pingcount? deadline?
   exit 126
else
   FILE=$1
   IP=$2
   PCOUNT=$3
   DLINE=$4

   while read line
   do
      if [[ $line == rtt* ]]
      then

         #replace forward slash with underscore
         line=${line////_}

         #replace spaces with underscore
         line=${line// /_}

         #get the 8 item when splitting string on underscore
         #echo $line| cut -d'_' -f 8 >> $FILE #Append
         #echo $line| cut -d'_' -f 8 > $FILE #Overwrite
         echo $line| c开发者_开发技巧ut -d'_' -f 8
      fi

   done < <(ping $IP -c $PCOUNT -q -w $DLINE) #-q output summary / -w deadline / -c pint count

I though about using trace route, but I think this would be produces a slower ping?, is there another way to achieve what I want?

Note: I know Nagios can directly ping a machine, but this isn't what I want to do and won't tell me what I want. Also this is my second script ever, so it's probably rubbish. Also, what alternative would I have if ICMP was blocked?


Have you looked at NRPE and check_ping? This would allow the nagios machine (mC) to ask mA to ping mB and then mA would report the results to mC. You would need to install and configure NRPE and the nagios-plugins on mA for this to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号