Solved

Net-SNMP exec with OID

Posted on 2011-03-23
5
1,029 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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Let’s list some of the technologies that enable smooth teleworking. 
Outsource Your Fax Infrastructure to the Cloud (And come out looking like an IT Hero!) Relative to the many demands on today’s IT teams, spending capital, time and resources to maintain physical fax servers and infrastructure is not a high priority.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now