Discussion:
find SNMP ifIndex value if hostname and SNMP ifDescr are known
(too old to reply)
Martin T
2015-05-12 15:45:14 UTC
Permalink
Hi,

Is there a clever method to find out the SNMP ifIndex value if I know
the hostname of the network device and ifDescr for this particular
interface? At the moment I do it like this:

snmpwalk -v 2c -c public router ifDescr | grep -E
"GigabitEthernet5/26$" | gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"

"router" is the hostname and "GigabitEthernet5/26" is the ifDescr.
"gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"" part is to make sure
that I get the ifIndex of the physical interface and not the
sub-interface like "GigabitEthernet5/26.123".


thanks,
Martin
Jurkiewicz Jean-Marc
2015-05-12 16:50:23 UTC
Permalink
Hi,

"gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"" part is to make sure that I get the ifIndex of the physical interface and not the sub-interface like "GigabitEthernet5/26.123".

Isn't that achieved by the "$" in grep -E "GigabitEthernet5/26$"

Some further information would be welcome in order to be able to answer your question.
Platform ?
Language ? is PERL an option ? AWK seems the most appropriate when I see your example.

Example :

[***@nocu07 ~]$ snmpwalk -c MyCS MySwitch 1.3.6.1.2.1.2.2.1.2
.1.3.6.1.2.1.2.2.1.2.1 = STRING: GigabitEthernet0/0
.1.3.6.1.2.1.2.2.1.2.2 = STRING: Null0
.1.3.6.1.2.1.2.2.1.2.3 = STRING: GigabitEthernet1/0/1
.1.3.6.1.2.1.2.2.1.2.4 = STRING: GigabitEthernet1/0/2
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3
.1.3.6.1.2.1.2.2.1.2.6 = STRING: GigabitEthernet1/0/4
Removed lines
.1.3.6.1.2.1.2.2.1.2.29 = STRING: GigabitEthernet1/0/27
.1.3.6.1.2.1.2.2.1.2.30 = STRING: GigabitEthernet1/0/28
.1.3.6.1.2.1.2.2.1.2.31 = STRING: GigabitEthernet1/0/29
.1.3.6.1.2.1.2.2.1.2.32 = STRING: GigabitEthernet1/0/30
.1.3.6.1.2.1.2.2.1.2.33 = STRING: GigabitEthernet1/0/31
.1.3.6.1.2.1.2.2.1.2.34 = STRING: GigabitEthernet1/0/32
Removed lines


Then

[***@nocu07 ~]$ snmpwalk -c MyCS MySwitch 1.3.6.1.2.1.2.2.1.2 | grep GigabitEthernet1/0/3$
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3 ==>> does not return GigabitEthernet1/0/3x
[***@nocu07 ~]$


Split the line
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3

By "="

Removes spaces => .1.3.6.1.2.1.2.2.1.2.5

Spilt by "." (dot)

The last element of the table is the index

Regards
JMJ

-----Message d'origine-----
De : Martin T [mailto:***@gmail.com]
Envoyé : mardi, 12. mai 2015 17:45
À : net-snmp-***@lists.sourceforge.net
Objet : find SNMP ifIndex value if hostname and SNMP ifDescr are known

Hi,

Is there a clever method to find out the SNMP ifIndex value if I know the hostname of the network device and ifDescr for this particular interface? At the moment I do it like this:

snmpwalk -v 2c -c public router ifDescr | grep -E "GigabitEthernet5/26$" | gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"

"router" is the hostname and "GigabitEthernet5/26" is the ifDescr.
"gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"" part is to make sure that I get the ifIndex of the physical interface and not the sub-interface like "GigabitEthernet5/26.123".


thanks,
Martin

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Net-snmp-users mailing list
Net-snmp-***@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
Martin T
2015-05-13 08:39:30 UTC
Permalink
Jean-Marc,

sorry, my mistake. "$" in "grep -E "GigabitEthernet5/26$"" ensures
that I get the ifIndex of the physical interface.
snmpwalk/snmpget are run under Linux, SNMP agent runs on Cisco and
Juniper equipment and language of choice is bash/grep/sed/awk.
However, the example in my initial post works, but I was looking more
like a built-in feature in snmpwalk/snmpget, i.e. something which
would avoid me listing all the "ifDescr" -s first and then greping the
right one and doing all this parsing.


thanks,
Martin
Post by Jurkiewicz Jean-Marc
Hi,
"gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"" part is to make sure that I
get the ifIndex of the physical interface and not the sub-interface like
"GigabitEthernet5/26.123".
Isn't that achieved by the "$" in grep -E "GigabitEthernet5/26$"
Some further information would be welcome in order to be able to answer your
question.
Platform ?
Language ? is PERL an option ? AWK seems the most appropriate when I see
your example.
.1.3.6.1.2.1.2.2.1.2.1 = STRING: GigabitEthernet0/0
.1.3.6.1.2.1.2.2.1.2.2 = STRING: Null0
.1.3.6.1.2.1.2.2.1.2.3 = STRING: GigabitEthernet1/0/1
.1.3.6.1.2.1.2.2.1.2.4 = STRING: GigabitEthernet1/0/2
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3
.1.3.6.1.2.1.2.2.1.2.6 = STRING: GigabitEthernet1/0/4
Removed lines
.1.3.6.1.2.1.2.2.1.2.29 = STRING: GigabitEthernet1/0/27
.1.3.6.1.2.1.2.2.1.2.30 = STRING: GigabitEthernet1/0/28
.1.3.6.1.2.1.2.2.1.2.31 = STRING: GigabitEthernet1/0/29
.1.3.6.1.2.1.2.2.1.2.32 = STRING: GigabitEthernet1/0/30
.1.3.6.1.2.1.2.2.1.2.33 = STRING: GigabitEthernet1/0/31
.1.3.6.1.2.1.2.2.1.2.34 = STRING: GigabitEthernet1/0/32
Removed lines
Then
grep GigabitEthernet1/0/3$
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3 ==>> does not return
GigabitEthernet1/0/3x
Split the line
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3
By "="
Removes spaces => .1.3.6.1.2.1.2.2.1.2.5
Spilt by "." (dot)
The last element of the table is the index
Regards
JMJ
-----Message d'origine-----
Envoyé : mardi, 12. mai 2015 17:45
Objet : find SNMP ifIndex value if hostname and SNMP ifDescr are known
Hi,
Is there a clever method to find out the SNMP ifIndex value if I know the
hostname of the network device and ifDescr for this particular interface? At
snmpwalk -v 2c -c public router ifDescr | grep -E "GigabitEthernet5/26$" |
gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"
"router" is the hostname and "GigabitEthernet5/26" is the ifDescr.
"gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"" part is to make sure that I
get the ifIndex of the physical interface and not the sub-interface like
"GigabitEthernet5/26.123".
thanks,
Martin
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications Performance
metrics, stats and reports that give you Actionable Insights Deep dive
visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Net-snmp-users mailing list
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
Jurkiewicz Jean-Marc
2015-05-15 07:47:22 UTC
Permalink
Hi Martin,

When you work with SNMP, the Index is the "key".

Once you have the Index you can "snmpget" a lot of information regarding this Index ( i.e. this Interface).
There is no way to "invert" the process ( find an Index when you have the Description).

http://jmjmon.eu/LaSupervisionDeReseau/SNMP_Mon-V010.pdf will provide you more explanations ( in French for the moment)

As you want a "Description" there is no other issue than reading all the "Descriptions" and then get the Index referring to the Interface you are looking for.

Best regards

JMJ

-----Message d'origine-----
De : Martin T [mailto:***@gmail.com]
Envoyé : mercredi, 13. mai 2015 10:40
À : Jurkiewicz Jean-Marc
Cc : net-snmp-***@lists.sourceforge.net
Objet : Re: find SNMP ifIndex value if hostname and SNMP ifDescr are known

Jean-Marc,

sorry, my mistake. "$" in "grep -E "GigabitEthernet5/26$"" ensures that I get the ifIndex of the physical interface.
snmpwalk/snmpget are run under Linux, SNMP agent runs on Cisco and Juniper equipment and language of choice is bash/grep/sed/awk.
However, the example in my initial post works, but I was looking more like a built-in feature in snmpwalk/snmpget, i.e. something which would avoid me listing all the "ifDescr" -s first and then greping the right one and doing all this parsing.


thanks,
Martin
Post by Martin T
Hi,
"gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"" part is to make sure
that I get the ifIndex of the physical interface and not the
sub-interface like "GigabitEthernet5/26.123".
Isn't that achieved by the "$" in grep -E "GigabitEthernet5/26$"
Some further information would be welcome in order to be able to
answer your question.
Platform ?
Language ? is PERL an option ? AWK seems the most appropriate when I
see your example.
.1.3.6.1.2.1.2.2.1.2.1 = STRING: GigabitEthernet0/0
.1.3.6.1.2.1.2.2.1.2.2 = STRING: Null0
.1.3.6.1.2.1.2.2.1.2.3 = STRING: GigabitEthernet1/0/1
.1.3.6.1.2.1.2.2.1.2.4 = STRING: GigabitEthernet1/0/2
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3
.1.3.6.1.2.1.2.2.1.2.6 = STRING: GigabitEthernet1/0/4 Removed lines
.1.3.6.1.2.1.2.2.1.2.29 = STRING: GigabitEthernet1/0/27
.1.3.6.1.2.1.2.2.1.2.30 = STRING: GigabitEthernet1/0/28
.1.3.6.1.2.1.2.2.1.2.31 = STRING: GigabitEthernet1/0/29
.1.3.6.1.2.1.2.2.1.2.32 = STRING: GigabitEthernet1/0/30
.1.3.6.1.2.1.2.2.1.2.33 = STRING: GigabitEthernet1/0/31
.1.3.6.1.2.1.2.2.1.2.34 = STRING: GigabitEthernet1/0/32 Removed lines
Then
grep GigabitEthernet1/0/3$
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3 ==>> does not return
GigabitEthernet1/0/3x
Split the line
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3
By "="
Removes spaces => .1.3.6.1.2.1.2.2.1.2.5
Spilt by "." (dot)
The last element of the table is the index
Regards
JMJ
-----Message d'origine-----
Objet : find SNMP ifIndex value if hostname and SNMP ifDescr are known
Hi,
Is there a clever method to find out the SNMP ifIndex value if I know
the hostname of the network device and ifDescr for this particular
snmpwalk -v 2c -c public router ifDescr | grep -E
"GigabitEthernet5/26$" | gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"
"router" is the hostname and "GigabitEthernet5/26" is the ifDescr.
"gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"" part is to make sure
that I get the ifIndex of the physical interface and not the
sub-interface like "GigabitEthernet5/26.123".
thanks,
Martin
----------------------------------------------------------------------
-------- One dashboard for servers and applications across
Physical-Virtual-Cloud Widest out-of-the-box monitoring support with
50+ applications Performance metrics, stats and reports that give you
Actionable Insights Deep dive visibility with transaction tracing
using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Net-snmp-users mailing list
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
Martin T
2015-05-15 09:52:47 UTC
Permalink
Jean-Marc,

ok. Thank you for explaining this!


regards,
Martin
Post by Jurkiewicz Jean-Marc
Hi Martin,
When you work with SNMP, the Index is the "key".
Once you have the Index you can "snmpget" a lot of information regarding
this Index ( i.e. this Interface).
There is no way to "invert" the process ( find an Index when you have the
Description).
http://jmjmon.eu/LaSupervisionDeReseau/SNMP_Mon-V010.pdf will provide you
more explanations ( in French for the moment)
As you want a "Description" there is no other issue than reading all the
"Descriptions" and then get the Index referring to the Interface you are
looking for.
Best regards
JMJ
-----Message d'origine-----
Envoyé : mercredi, 13. mai 2015 10:40
À : Jurkiewicz Jean-Marc
Objet : Re: find SNMP ifIndex value if hostname and SNMP ifDescr are known
Jean-Marc,
sorry, my mistake. "$" in "grep -E "GigabitEthernet5/26$"" ensures that I
get the ifIndex of the physical interface.
snmpwalk/snmpget are run under Linux, SNMP agent runs on Cisco and Juniper
equipment and language of choice is bash/grep/sed/awk.
However, the example in my initial post works, but I was looking more like a
built-in feature in snmpwalk/snmpget, i.e. something which would avoid me
listing all the "ifDescr" -s first and then greping the right one and doing
all this parsing.
thanks,
Martin
Post by Martin T
Hi,
"gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"" part is to make sure
that I get the ifIndex of the physical interface and not the
sub-interface like "GigabitEthernet5/26.123".
Isn't that achieved by the "$" in grep -E "GigabitEthernet5/26$"
Some further information would be welcome in order to be able to
answer your question.
Platform ?
Language ? is PERL an option ? AWK seems the most appropriate when I
see your example.
1.3.6.1.2.1.2.2.1.2
.1.3.6.1.2.1.2.2.1.2.1 = STRING: GigabitEthernet0/0
.1.3.6.1.2.1.2.2.1.2.2 = STRING: Null0
.1.3.6.1.2.1.2.2.1.2.3 = STRING: GigabitEthernet1/0/1
.1.3.6.1.2.1.2.2.1.2.4 = STRING: GigabitEthernet1/0/2
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3
.1.3.6.1.2.1.2.2.1.2.6 = STRING: GigabitEthernet1/0/4 Removed lines
.1.3.6.1.2.1.2.2.1.2.29 = STRING: GigabitEthernet1/0/27
.1.3.6.1.2.1.2.2.1.2.30 = STRING: GigabitEthernet1/0/28
.1.3.6.1.2.1.2.2.1.2.31 = STRING: GigabitEthernet1/0/29
.1.3.6.1.2.1.2.2.1.2.32 = STRING: GigabitEthernet1/0/30
.1.3.6.1.2.1.2.2.1.2.33 = STRING: GigabitEthernet1/0/31
.1.3.6.1.2.1.2.2.1.2.34 = STRING: GigabitEthernet1/0/32 Removed lines
Then
|
grep GigabitEthernet1/0/3$
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3 ==>> does not
return
GigabitEthernet1/0/3x
Split the line
.1.3.6.1.2.1.2.2.1.2.5 = STRING: GigabitEthernet1/0/3
By "="
Removes spaces => .1.3.6.1.2.1.2.2.1.2.5
Spilt by "." (dot)
The last element of the table is the index
Regards
JMJ
-----Message d'origine-----
Objet : find SNMP ifIndex value if hostname and SNMP ifDescr are known
Hi,
Is there a clever method to find out the SNMP ifIndex value if I know
the hostname of the network device and ifDescr for this particular
snmpwalk -v 2c -c public router ifDescr | grep -E
"GigabitEthernet5/26$" | gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"
"router" is the hostname and "GigabitEthernet5/26" is the ifDescr.
"gsed -r "s/IF-MIB::ifDescr.([0-9]+) .*/\1/"" part is to make sure
that I get the ifIndex of the physical interface and not the
sub-interface like "GigabitEthernet5/26.123".
thanks,
Martin
----------------------------------------------------------------------
-------- One dashboard for servers and applications across
Physical-Virtual-Cloud Widest out-of-the-box monitoring support with
50+ applications Performance metrics, stats and reports that give you
Actionable Insights Deep dive visibility with transaction tracing
using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Net-snmp-users mailing list
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
Loading...