Python Netsnmp and snmpwalk

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I am trying to use snmpwalk to gain some info and stats on some interfaces. I use this:
import netsnmp
serv = "172.16.1.1"
snmp_pass = "private"
oid = netsnmp.VarList('IF-MIB::ifName','IF-MIB::ifDescr')
snmp_res = netsnmp.snmpwalk(oid, Version=2, DestHost=serv, Community=snmp_pass)
for x in snmp_res:
print "snmp_res:: ", x
All I get as answer is:
snmp_res:: lo
snmp_res:: EtherNet Adapter XYZ
The answer is correct but I want more info. When I do same thing from linux command with snmpwalk I get more info such as:
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: EtherNet Adapter XYZ
The ID is 2 for "EtherNet Adapter XYZ" and I need that value as well to reference for other stats on interface. How do I get that/them with python and snmp?
python linux snmp net-snmp
migrated from unix.stackexchange.com Dec 4 at 14:02
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
add a comment |
up vote
2
down vote
favorite
I am trying to use snmpwalk to gain some info and stats on some interfaces. I use this:
import netsnmp
serv = "172.16.1.1"
snmp_pass = "private"
oid = netsnmp.VarList('IF-MIB::ifName','IF-MIB::ifDescr')
snmp_res = netsnmp.snmpwalk(oid, Version=2, DestHost=serv, Community=snmp_pass)
for x in snmp_res:
print "snmp_res:: ", x
All I get as answer is:
snmp_res:: lo
snmp_res:: EtherNet Adapter XYZ
The answer is correct but I want more info. When I do same thing from linux command with snmpwalk I get more info such as:
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: EtherNet Adapter XYZ
The ID is 2 for "EtherNet Adapter XYZ" and I need that value as well to reference for other stats on interface. How do I get that/them with python and snmp?
python linux snmp net-snmp
migrated from unix.stackexchange.com Dec 4 at 14:02
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
Have you examined the returned objects to see if more information isn't being returned? All you're seeing is a string representation
– TheIncorrigible1
Dec 4 at 14:11
I have tried with little luck. I imagine I look at "oid"? It appears to be a "<class 'netsnmp.client.VarList'>". I am really needing ID matched to interface name.
– Matt
Dec 4 at 15:52
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am trying to use snmpwalk to gain some info and stats on some interfaces. I use this:
import netsnmp
serv = "172.16.1.1"
snmp_pass = "private"
oid = netsnmp.VarList('IF-MIB::ifName','IF-MIB::ifDescr')
snmp_res = netsnmp.snmpwalk(oid, Version=2, DestHost=serv, Community=snmp_pass)
for x in snmp_res:
print "snmp_res:: ", x
All I get as answer is:
snmp_res:: lo
snmp_res:: EtherNet Adapter XYZ
The answer is correct but I want more info. When I do same thing from linux command with snmpwalk I get more info such as:
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: EtherNet Adapter XYZ
The ID is 2 for "EtherNet Adapter XYZ" and I need that value as well to reference for other stats on interface. How do I get that/them with python and snmp?
python linux snmp net-snmp
I am trying to use snmpwalk to gain some info and stats on some interfaces. I use this:
import netsnmp
serv = "172.16.1.1"
snmp_pass = "private"
oid = netsnmp.VarList('IF-MIB::ifName','IF-MIB::ifDescr')
snmp_res = netsnmp.snmpwalk(oid, Version=2, DestHost=serv, Community=snmp_pass)
for x in snmp_res:
print "snmp_res:: ", x
All I get as answer is:
snmp_res:: lo
snmp_res:: EtherNet Adapter XYZ
The answer is correct but I want more info. When I do same thing from linux command with snmpwalk I get more info such as:
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: EtherNet Adapter XYZ
The ID is 2 for "EtherNet Adapter XYZ" and I need that value as well to reference for other stats on interface. How do I get that/them with python and snmp?
python linux snmp net-snmp
python linux snmp net-snmp
edited Dec 4 at 19:19
Benyamin Jafari
2,56531833
2,56531833
asked Dec 3 at 23:01
Matt
266
266
migrated from unix.stackexchange.com Dec 4 at 14:02
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
migrated from unix.stackexchange.com Dec 4 at 14:02
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
Have you examined the returned objects to see if more information isn't being returned? All you're seeing is a string representation
– TheIncorrigible1
Dec 4 at 14:11
I have tried with little luck. I imagine I look at "oid"? It appears to be a "<class 'netsnmp.client.VarList'>". I am really needing ID matched to interface name.
– Matt
Dec 4 at 15:52
add a comment |
Have you examined the returned objects to see if more information isn't being returned? All you're seeing is a string representation
– TheIncorrigible1
Dec 4 at 14:11
I have tried with little luck. I imagine I look at "oid"? It appears to be a "<class 'netsnmp.client.VarList'>". I am really needing ID matched to interface name.
– Matt
Dec 4 at 15:52
Have you examined the returned objects to see if more information isn't being returned? All you're seeing is a string representation
– TheIncorrigible1
Dec 4 at 14:11
Have you examined the returned objects to see if more information isn't being returned? All you're seeing is a string representation
– TheIncorrigible1
Dec 4 at 14:11
I have tried with little luck. I imagine I look at "oid"? It appears to be a "<class 'netsnmp.client.VarList'>". I am really needing ID matched to interface name.
– Matt
Dec 4 at 15:52
I have tried with little luck. I imagine I look at "oid"? It appears to be a "<class 'netsnmp.client.VarList'>". I am really needing ID matched to interface name.
– Matt
Dec 4 at 15:52
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Straight out of the documentation:
snmpwalk(<Varbind/VarList>, <Session args>))
Takes args of netsnmp.Session preceded by a Varbind or
VarList from which the 'walk' operation will start.
Returns a tuple of values retrieved from the MIB below
the Varbind passed in. If a VarList is passed in it
will be updated to contain a complete set of VarBinds
created for the results of the walk. It is not
recommended to pass in just a Varbind since you loose
the ability to examine the returned OIDs. But, if only
a Varbind is passed in it will be returned unaltered.
Note that only one varbind should be contained in the
VarList passed in. The code is structured to maybe
handle this is the the future, but right now walking
multiple trees at once is not yet supported and will
produce insufficient results.
You're already passing a VarList, so you already have what you need. You just need to examine the results properly.
The tests have an example:
vars = netsnmp.VarList(netsnmp.Varbind('system'))
vals = sess.walk(vars)
print "v1 sess.walk result: ", vals, "n"
for var in vars:
print " ",var.tag, var.iid, "=", var.val, '(',var.type,')'
The key is that the input variable is modified to give you what you need. The return value is not of much value (lol) to you.
Putting this all together it looks like you want the following:
import netsnmp
serv = "172.16.1.1"
snmp_pass = "private"
oid = netsnmp.VarList('IF-MIB::ifName','IF-MIB::ifDescr')
snmp_res = netsnmp.snmpwalk(oid, Version=2, DestHost=serv, Community=snmp_pass)
for x in oid:
print "snmp_res:: ", x.iid, " = ", x.val
(Disclaimer: can't test; adapt as needed)
There's enough information about VarBind and VarList in that documentation to figure out the best stuff to get out of x.
x.iid is the instance identifier, though, so that should give you the 1 and 2 that you're after. Don't forget to examine x.tag as well, though, which will be either IF-MIB::ifName or IF-MIB::ifDescr (or something equivalent; you'd have to experiment).
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Straight out of the documentation:
snmpwalk(<Varbind/VarList>, <Session args>))
Takes args of netsnmp.Session preceded by a Varbind or
VarList from which the 'walk' operation will start.
Returns a tuple of values retrieved from the MIB below
the Varbind passed in. If a VarList is passed in it
will be updated to contain a complete set of VarBinds
created for the results of the walk. It is not
recommended to pass in just a Varbind since you loose
the ability to examine the returned OIDs. But, if only
a Varbind is passed in it will be returned unaltered.
Note that only one varbind should be contained in the
VarList passed in. The code is structured to maybe
handle this is the the future, but right now walking
multiple trees at once is not yet supported and will
produce insufficient results.
You're already passing a VarList, so you already have what you need. You just need to examine the results properly.
The tests have an example:
vars = netsnmp.VarList(netsnmp.Varbind('system'))
vals = sess.walk(vars)
print "v1 sess.walk result: ", vals, "n"
for var in vars:
print " ",var.tag, var.iid, "=", var.val, '(',var.type,')'
The key is that the input variable is modified to give you what you need. The return value is not of much value (lol) to you.
Putting this all together it looks like you want the following:
import netsnmp
serv = "172.16.1.1"
snmp_pass = "private"
oid = netsnmp.VarList('IF-MIB::ifName','IF-MIB::ifDescr')
snmp_res = netsnmp.snmpwalk(oid, Version=2, DestHost=serv, Community=snmp_pass)
for x in oid:
print "snmp_res:: ", x.iid, " = ", x.val
(Disclaimer: can't test; adapt as needed)
There's enough information about VarBind and VarList in that documentation to figure out the best stuff to get out of x.
x.iid is the instance identifier, though, so that should give you the 1 and 2 that you're after. Don't forget to examine x.tag as well, though, which will be either IF-MIB::ifName or IF-MIB::ifDescr (or something equivalent; you'd have to experiment).
add a comment |
up vote
1
down vote
Straight out of the documentation:
snmpwalk(<Varbind/VarList>, <Session args>))
Takes args of netsnmp.Session preceded by a Varbind or
VarList from which the 'walk' operation will start.
Returns a tuple of values retrieved from the MIB below
the Varbind passed in. If a VarList is passed in it
will be updated to contain a complete set of VarBinds
created for the results of the walk. It is not
recommended to pass in just a Varbind since you loose
the ability to examine the returned OIDs. But, if only
a Varbind is passed in it will be returned unaltered.
Note that only one varbind should be contained in the
VarList passed in. The code is structured to maybe
handle this is the the future, but right now walking
multiple trees at once is not yet supported and will
produce insufficient results.
You're already passing a VarList, so you already have what you need. You just need to examine the results properly.
The tests have an example:
vars = netsnmp.VarList(netsnmp.Varbind('system'))
vals = sess.walk(vars)
print "v1 sess.walk result: ", vals, "n"
for var in vars:
print " ",var.tag, var.iid, "=", var.val, '(',var.type,')'
The key is that the input variable is modified to give you what you need. The return value is not of much value (lol) to you.
Putting this all together it looks like you want the following:
import netsnmp
serv = "172.16.1.1"
snmp_pass = "private"
oid = netsnmp.VarList('IF-MIB::ifName','IF-MIB::ifDescr')
snmp_res = netsnmp.snmpwalk(oid, Version=2, DestHost=serv, Community=snmp_pass)
for x in oid:
print "snmp_res:: ", x.iid, " = ", x.val
(Disclaimer: can't test; adapt as needed)
There's enough information about VarBind and VarList in that documentation to figure out the best stuff to get out of x.
x.iid is the instance identifier, though, so that should give you the 1 and 2 that you're after. Don't forget to examine x.tag as well, though, which will be either IF-MIB::ifName or IF-MIB::ifDescr (or something equivalent; you'd have to experiment).
add a comment |
up vote
1
down vote
up vote
1
down vote
Straight out of the documentation:
snmpwalk(<Varbind/VarList>, <Session args>))
Takes args of netsnmp.Session preceded by a Varbind or
VarList from which the 'walk' operation will start.
Returns a tuple of values retrieved from the MIB below
the Varbind passed in. If a VarList is passed in it
will be updated to contain a complete set of VarBinds
created for the results of the walk. It is not
recommended to pass in just a Varbind since you loose
the ability to examine the returned OIDs. But, if only
a Varbind is passed in it will be returned unaltered.
Note that only one varbind should be contained in the
VarList passed in. The code is structured to maybe
handle this is the the future, but right now walking
multiple trees at once is not yet supported and will
produce insufficient results.
You're already passing a VarList, so you already have what you need. You just need to examine the results properly.
The tests have an example:
vars = netsnmp.VarList(netsnmp.Varbind('system'))
vals = sess.walk(vars)
print "v1 sess.walk result: ", vals, "n"
for var in vars:
print " ",var.tag, var.iid, "=", var.val, '(',var.type,')'
The key is that the input variable is modified to give you what you need. The return value is not of much value (lol) to you.
Putting this all together it looks like you want the following:
import netsnmp
serv = "172.16.1.1"
snmp_pass = "private"
oid = netsnmp.VarList('IF-MIB::ifName','IF-MIB::ifDescr')
snmp_res = netsnmp.snmpwalk(oid, Version=2, DestHost=serv, Community=snmp_pass)
for x in oid:
print "snmp_res:: ", x.iid, " = ", x.val
(Disclaimer: can't test; adapt as needed)
There's enough information about VarBind and VarList in that documentation to figure out the best stuff to get out of x.
x.iid is the instance identifier, though, so that should give you the 1 and 2 that you're after. Don't forget to examine x.tag as well, though, which will be either IF-MIB::ifName or IF-MIB::ifDescr (or something equivalent; you'd have to experiment).
Straight out of the documentation:
snmpwalk(<Varbind/VarList>, <Session args>))
Takes args of netsnmp.Session preceded by a Varbind or
VarList from which the 'walk' operation will start.
Returns a tuple of values retrieved from the MIB below
the Varbind passed in. If a VarList is passed in it
will be updated to contain a complete set of VarBinds
created for the results of the walk. It is not
recommended to pass in just a Varbind since you loose
the ability to examine the returned OIDs. But, if only
a Varbind is passed in it will be returned unaltered.
Note that only one varbind should be contained in the
VarList passed in. The code is structured to maybe
handle this is the the future, but right now walking
multiple trees at once is not yet supported and will
produce insufficient results.
You're already passing a VarList, so you already have what you need. You just need to examine the results properly.
The tests have an example:
vars = netsnmp.VarList(netsnmp.Varbind('system'))
vals = sess.walk(vars)
print "v1 sess.walk result: ", vals, "n"
for var in vars:
print " ",var.tag, var.iid, "=", var.val, '(',var.type,')'
The key is that the input variable is modified to give you what you need. The return value is not of much value (lol) to you.
Putting this all together it looks like you want the following:
import netsnmp
serv = "172.16.1.1"
snmp_pass = "private"
oid = netsnmp.VarList('IF-MIB::ifName','IF-MIB::ifDescr')
snmp_res = netsnmp.snmpwalk(oid, Version=2, DestHost=serv, Community=snmp_pass)
for x in oid:
print "snmp_res:: ", x.iid, " = ", x.val
(Disclaimer: can't test; adapt as needed)
There's enough information about VarBind and VarList in that documentation to figure out the best stuff to get out of x.
x.iid is the instance identifier, though, so that should give you the 1 and 2 that you're after. Don't forget to examine x.tag as well, though, which will be either IF-MIB::ifName or IF-MIB::ifDescr (or something equivalent; you'd have to experiment).
edited Dec 6 at 10:58
answered Dec 6 at 10:52
Lightness Races in Orbit
281k51453769
281k51453769
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53614670%2fpython-netsnmp-and-snmpwalk%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you examined the returned objects to see if more information isn't being returned? All you're seeing is a string representation
– TheIncorrigible1
Dec 4 at 14:11
I have tried with little luck. I imagine I look at "oid"? It appears to be a "<class 'netsnmp.client.VarList'>". I am really needing ID matched to interface name.
– Matt
Dec 4 at 15:52