简体   繁体   English

Bash脚本,允许Nagios报告其他两台Linux机器之间的ping

[英]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). 我正在寻找替代方法来计算两台机器(mA和mB)之间的ping,并将其报告给Nagios(在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. 我目前的想法是编写一个BASH脚本,该脚本将对cron作业中的计算机执行ping操作,将数据输出到文件中,然后使用Nagios可以用来读取该文件的另一个bash脚本。 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: 这是我计划在cron作业中运行的脚本:

#!/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? 我虽然使用跟踪路由,但是我认为这会产生较慢的ping ?,是否还有另一种方法可以实现我想要的?

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. 注意:我知道Nagios可以直接ping机器,但这不是我想要做的,也不会告诉我我想要什么。 Also this is my second script ever, so it's probably rubbish. 这也是我的第二个脚本,所以可能是垃圾。 Also, what alternative would I have if ICMP was blocked? 另外,如果ICMP被阻止,我还有什么选择?

Have you looked at NRPE and check_ping? 您是否看过NRPE和check_ping? This would allow the nagios machine (mC) to ask mA to ping mB and then mA would report the results to mC. 这将使nagios机器(mC)要求mA ping mB,然后mA会将结果报告给mC。 You would need to install and configure NRPE and the nagios-plugins on mA for this to work. 您需要在mA上安装和配置NRPE和nagios-plugins才能起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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