These scripts allow you to ping an arbitrary system using an extension script that you can reconfigure remotely using SNMP. Therefore, it is no necessary to edit sysedge.cf or any other custom script. You can set or change the name of the system you want to observe by using SNMP SET from any MIB Browser or event snmpset utility provided with SystemEDGE. Reading the extension variable provides a string with ping information.
To reconfigure extension scripts through SNMP
extension 31 octetstring readwrite '/opt/CA/test/ping.sh' (UNIX, Linux) extension 31 octetstring readwrite 'c:\test\ping.bat' (Windows)
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
An error message appears.
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
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
The script checks that the extension has index 31. However, this check is technically not required and can be removed, so that the extension script can be assigned to any index.
The scripts ping.bat and ping.sh stores the configuration information in a temporary file.
Ping script for UNIX and Linux
#!/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
Ping script for Windows
@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=
Copyright © 2013 CA.
All rights reserved.
|
|