?
Solved

Net-SNMP exec with OID

Posted on 2011-03-23
5
Medium Priority
?
1,109 Views
Last Modified: 2012-06-21
Hello, experts,

I was ordered some small program as

 - Using Net-SNMP and "exec" in snmpd.conf
 - answer for "snmpget ..snip.. .xxx.123"
 - above 123 is pid(process id) and variable
 - exec program can be any language(sh,perl,c)
 - exec calling program works with pid
 - exec calling program returns like
   ".xxx.123 = 28765 Integer" (28765 is example)

I can program with C, but I'm newbie in snmp.
I read documents about snmpd.conf, but it says about only fixed parameter.

I need experts help, Thanks
0
Comment
Question by:NobMiwa
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:svs
ID: 35206973
'pass' is better suited for this than 'exec'
0
 
LVL 9

Accepted Solution

by:
svs earned 1500 total points
ID: 35207097
something like this should work
#!/bin/sh

OIDBASE=.1.3.6.1.4.1.789

CMD=$1
OID=$2

if [ -z "$OID" ]; then
        echo "this is a snmpd 'pass' plugin"
        exit 1
fi

if [ $CMD != "-g" ]; then
        exit
fi

PID=${OID##.1.3.6.1.4.1.789.}
RESULT=`cat /proc/$PID/cmdline | wc -c`

echo $OID
echo integer
echo $RESULT

Open in new window

0
 

Author Comment

by:NobMiwa
ID: 35208524
Thanks svs,

But still don't know about how to write pass statement in snampd,conf

I wrote like this,

pass .1.3.6.1.4.1.789 /bin/sh /usr/local/passtest.sh

And try

# snmpwalk -v 2c -c private localhost .1.3.6.1.4.1.789.999
SNMPv2-SMI::enterprises.789.999 = No Such Instance currently exists at this OID

Please advice .. (T_T)
0
 

Author Comment

by:NobMiwa
ID: 35209227
Hi, svs,

I searched Google and got a code attached.
and now it works !

Thanks for advice.

#!/bin/sh
if [ "$1" = "-g" ]
then
echo .1.3.6.1.2.1.1.1.0
echo string
echo test2 $1 $2
fi
if [ "$1" = "-n" ]
then
if [ "$2" = ".1.3.6.1.2.1.1.1" ]
then
echo .1.3.6.1.2.1.1.1.0
echo string
echo testNext2
fi
fi

Open in new window

0
 

Author Closing Comment

by:NobMiwa
ID: 35209236
Great advice at this moment
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will be showing you how to subnet the easiest way possible for IPv4 (Internet Protocol version 4). This article does not cover IPv6. Keep in mind that subnetting requires lots of practice and time.
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question