2 years ago

#26195

test-img

Leon

Need a Net-SNMP agent script example that returns a table

I need to add an agent of Net-SNMP daemon on a OpenWrt router. Because a script involved by extend directive only can return a string, so I have to use pass directive to involve my script and implement it.

If I return a single line string in the script, everything is OK, but I need to return a table such as route table or online user list of OpenVPN.

Is there a example script that implementing such a agent of Net-SNMP?

This is my script on halfway:

#!/bin/sh

opt=$1
oid=$2
type=$3
value=$4

touch /var/log/snmp_pass.log
echo "passing $opt $oid $type $value" >> /var/log/snmp_pass.log

if [ "$oid" = ".1.3.6.1.4.1.12345" ]; then
    prefix=$oid
    sub_id=0
else
    prefix=${oid%.*}
    sub_id=${oid##*.}
fi

if [ "$opt" = "-s" ]; then
#   echo $oid
#   echo string
#   echo "Finished"
    exit 0
fi

if [ "$opt" = "-n" ]; then
    sub_id=`expr $sub_id + 1`
fi

# if [ "$opt" = "-g" ]; then
# fi

echo "${prefix}.${sub_id}"
echo string
case $sub_id in
[0-8])
    echo "Hello$sub_id"
    echo "second line"
    exit 0
    ;;
9)
    cat /var/log/openvpn-server-status
    exit 0
    ;;
esac

exit 1

shell

agent

extendscript

net-snmp

snmpd

0 Answers

Your Answer

Accepted video resources