上一主题: 监控文件系统下一主题: 监控日志文件并通过电子邮件发送通知


通过 SNMP 重新配置扩展脚本

这些脚本允许您使用扩展脚本 ping 任意系统,您可以使用 SNMP 远程配置该扩展脚本。 因此,不需要编辑 sysedge.cf 或任何其他自定义脚本。 可以使用 MIB 浏览器中的 SNMP SET 或 SystemEDGE 附带的事件 snmpset 实用工具设置或更改要查看的系统的名称。 读取扩展变量提供字符串以及 ping 信息。

通过 SNMP 重新配置扩展脚本

  1. 将以下行添加到 sysedge.cf 配置文件中并重新启动 SystemEDGE:
    extension 31 octetstring readwrite '/opt/CA/test/ping.sh' (UNIX, Linux)
    extension 31 octetstring readwrite 'c:\test\ping.bat' (Windows)
    
  2. 将脚本 (ping.sh, ping.bat) 复制到扩展指令中指定的目录。
  3. 输入读取请求,但不设置 ping 目标:
    C:\SystemEDGE\bin>.\snmpget -o 1.3.6.1.4.1.546.14.31.0
    1.3.6.1.4.1.546.14.31.0 Ping target must be set first
    

    此时将显示错误消息。

  4. 将 my-sles3 设置为要 ping 的系统:
    C:\SystemEDGE\bin>.\snmpset -c private -o 1.3.6.1.4.1.546.14.31.0 -s my-sles3
    1.3.6.1.4.1.546.14.31.0 my-sles3
    
  5. 通过读取变量来 ping 系统:
    C:\SystemEDGE\bin>.\snmpget -o 1.3.6.1.4.1.546.14.31.0
    1.3.6.1.4.1.546.14.31.0 my-sles3 is alive
    

此脚本检查扩展是否具有索引 31。 但是技术上不需要此检查,可以将其删除,因此扩展脚本可以分配给任何索引。

脚本 ping.bat 和 ping.sh 将配置信息存储在临时文件中。

UNIX 和 Linux 的 ping 脚本

#!/bin/sh
#
# ping.sh example extension script 
#
# A simple example script for the SystemEDGE agent extension group.
# This script implements a "Ping" SNMP MIB variable whereby
# Sets to this variable indicate what system should be pinged
# and Gets to this variable cause the Ping to occur and the 
# output to be returned as an OctetString.
#
# For reference, the following are passed as parameters by the SystemEDGE
# Agent. They are not used in this script.
# 
# The Extension Group Leaf Number
LeafNumber=$1
# The SNMP Operation: GET, GETNEXT, or SET
Operation=$2
# The value if a SET Operation
SetValue=$3

# determine which ping program to use
OSNAME=`/bin/uname -r`
OSTYPE=`/bin/uname -s`

if [ "$LeafNumber" = "31" ]; then

   # setup who we should be pinging
   if [ "$Operation" = "SET" ]; then
      echo $SetValue > /tmp/sysedge.ping.target
      echo $SetValue 
   fi

   if [ "$Operation" = "GETNEXT" ];  then
      Operation="GET"
   fi

   if [ "$Operation" = "GET" ]; then
      if [ ! -f /tmp/sysedge.ping.target ]; then
         echo "Ping target must be Set first"
         exit 0
      fi

      case $OSTYPE in
        Linux)
		/bin/ping -c 1 -q -n `/bin/cat /tmp/sysedge.ping.target`
		;;

        HP-UX)
		/etc/ping `/bin/cat /tmp/sysedge.ping.target` -n 1
		;;
        AIX)
		/etc/ping -c 1 `/bin/cat /tmp/sysedge.ping.target`
		;;
	SunOS) 
		/usr/sbin/ping `/bin/cat /tmp/sysedge.ping.target` 2
		;;
  
	*) 
	      case $OSNAME in
		6.*)
		  /usr/etc/ping -c 1 -q -n `/bin/cat /tmp/sysedge.ping.target` 

		  # IRIX ping is very annoying since it doesnt appear you can get
		  # one-line output indicating if the machine is alive or not alive.
		  # If we were trickier shell programmers, we'd catch the output
		  # and only echo the last line.
		  ;;

		5.*)
		  /usr/sbin/ping `/bin/cat /tmp/sysedge.ping.target` 2
		  ;;

		4.*)
		  /usr/etc/ping `/bin/cat /tmp/sysedge.ping.target` 2
		  ;;

		*)
		  echo "Cant determine ping command for system " $OSNAME
		  exit 0     
		  ;;
	      esac
	esac
   fi
fi

Windows 的 ping 脚本

@ECHO OFF
@rem ping.bat example extension script 
@rem
@rem A simple example script for the SystemEDGE agent extension group.
@rem This script implements a "Ping" SNMP MIB variable whereby
@rem Sets to this variable indicate what system should be pinged
@rem and Gets to this variable cause the Ping to occur and the 
@rem output to be returned as an OctetString.
@rem
@rem For reference, the following are passed as parameters by the SystemEDGE
@rem Agent.
@rem 

@rem The Extension Group Leaf Number
set LeafNumber=%1%

@rem The SNMP Operation: GET, GETNEXT, or SET
set Operation=%2%

@rem The value if a SET Operation
set SetValue=%3%

@rem Which ping command should we use
set PING=%SystemRoot%\system32\ping.exe

@rem We store our target in the "environment" for future use
@rem using variable SYSEDGE_PING_TARGET

if not %LeafNumber% == 31 goto fi

   @rem if set, we want to ensure there is a value,
   @rem then store it away, then echo the value to STDOUT
   @rem so as to not confuse extension code
   if %Operation% == SET if !%SetValue%==! goto error
   if %Operation% == SET @echo set SYSEDGE_PING_TARGET=%SetValue% > %TMP%\pingtgt.bat
   if %Operation% == SET echo %SetValue%
   if %Operation% == SET goto fi

   @rem Run the script to recover the target name
   call %TMP%\pingtgt.bat
   if !%SYSEDGE_PING_TARGET% ==! goto error

   @rem echo pinging %SYSEDGE_PING_TARGET%
   %PING% -n 1 -w 250 %SYSEDGE_PING_TARGET% > nul

   if ERRORLEVEL 1 echo %SYSEDGE_PING_TARGET% not alive
   if not ERRORLEVEL 1 echo %SYSEDGE_PING_TARGET% is alive

:fi
goto exit

:error 
echo Ping target must be set first

:exit
rem cleanup because command.com is really pathetic, sigh
set PING=
set Operation=
set LeafNumber=
set SetValue=