简体   繁体   中英

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

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| cut -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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM