Monday, June 1, 2009

How to Check a Cisco Interface Last Change

Sometimes, customers ask:
"I would like to know when was the last time this port went down!"

Well, our aswer will always be, "we will investigate and let you know."

The problem is, how can I get this information.
Actually, you will find it, if you have a syslog server, but what if the syslog rotates de logs earlier then your think !

Well, there is another way to get some info. Although Cisco says that it is valid, all my tests have not give me any confidence for this data:
Anyway, here it is how to get it.

Cisco provides a MIB for the last change of an Interface:
snmpwalk -v 1 -c .iso.3.6.1.2.1.2.2.1.9

IF-MIB::ifLastChange.1 = Timeticks: (10995) 0:01:49.95
IF-MIB::ifLastChange.2002 = Timeticks: (14524) 0:02:25.24
IF-MIB::ifLastChange.5001 = Timeticks: (12082) 0:02:00.82
IF-MIB::ifLastChange.5002 = Timeticks: (96967443) 11 days, 5:21:14.43
IF-MIB::ifLastChange.10101 = Timeticks: (97498708) 11 days, 6:49:47.08
IF-MIB::ifLastChange.10102 = Timeticks: (97497760) 11 days, 6:49:37.60
IF-MIB::ifLastChange.10103 = Timeticks: (97497340) 11 days, 6:49:33.40
IF-MIB::ifLastChange.10104 = Timeticks: (97496849) 11 days, 6:49:28.49
IF-MIB::ifLastChange.10105 = Timeticks: (97495422) 11 days, 6:49:14.22
IF-MIB::ifLastChange.10106 = Timeticks: (97494025) 11 days, 6:49:00.25
IF-MIB::ifLastChange.10107 = Timeticks: (97494995) 11 days, 6:49:09.95
IF-MIB::ifLastChange.10108 = Timeticks: (11332) 0:01:53.32
IF-MIB::ifLastChange.10109 = Timeticks: (11332) 0:01:53.32
IF-MIB::ifLastChange.10110 = Timeticks: (11332) 0:01:53.32
IF-MIB::ifLastChange.10111 = Timeticks: (11332) 0:01:53.32
IF-MIB::ifLastChange.10112 = Timeticks: (11332) 0:01:53.32
IF-MIB::ifLastChange.10113 = Timeticks: (11332) 0:01:53.32
IF-MIB::ifLastChange.10114 = Timeticks: (11332) 0:01:53.32
IF-MIB::ifLastChange.10115 = Timeticks: (11332) 0:01:53.32
IF-MIB::ifLastChange.10116 = Timeticks: (97498710) 11 days, 6:49:47.10
IF-MIB::ifLastChange.10117 = Timeticks: (97497765) 11 days, 6:49:37.65
IF-MIB::ifLastChange.10118 = Timeticks: (97497353) 11 days, 6:49:33.53
IF-MIB::ifLastChange.10119 = Timeticks: (97496854) 11 days, 6:49:28.54
IF-MIB::ifLastChange.10120 = Timeticks: (97495448) 11 days, 6:49:14.48
IF-MIB::ifLastChange.10121 = Timeticks: (97494037) 11 days, 6:49:00.37
IF-MIB::ifLastChange.10122 = Timeticks: (97494996) 11 days, 6:49:09.96
IF-MIB::ifLastChange.10123 = Timeticks: (11333) 0:01:53.33
IF-MIB::ifLastChange.10124 = Timeticks: (11333) 0:01:53.33
IF-MIB::ifLastChange.10125 = Timeticks: (11333) 0:01:53.33


Use it in your own risk!

4 comments:

Unknown said...

This works great for me! At first I thought it didn't work because I took several samples and noticed that the values never changed between samples. However, it is important to note that the value returned is the uptime value of the system since the interface last changed states. Therefore, if IF-MIB::ifLastChange.10001 = 8640000 (which would be 1 day; value is in 100th of seconds) then you would have to subtract this value from the value returned by querying 1.3.6.1.2.1.1.3.0 (sysUptime) and then divide that result by 100 to figure out the number of seconds which have passed since the last interface state change.

ciscohowtos said...

thanks great posts, I have also a blog if anyone interested then please visit http://ciscohowtos.blogspot.com

Christophe said...

So it mean that when an interface goes from up to down oper status you have to substract ifLastChange value to sysUpTime value and when the interface goes from down to up, the ifLastChange value is the one you are looking for. No ?

Regards.

NewOne said...

Hello this is a very old post but I don't found a newer solution...


I have a question about the values. 1.3.6.1.2.1.1.3.0 = sysUpTimeInstance I got no values. 1.3.6.1.2.1.1 = sysUpTime I got a value.


Uptime: 607986491/100 = 70d 8h 51min...
Gi1/0/1: 502826553/100 = 58d 4h 44min...

(607986491-502826553)/100 = ~1051599 = 12d 4h 6min...

But why du you substract that? I interpret the values like that the Gi1/0/1 has changed the state before 58d or I'm wrong?

Or is it a timestamp from the systime at statechange and the Interface has changed 12d?

Thanks a lot!