I have done this in troubleshooting an OSPF issue where we needed to
immediately grab logs from a buffer that had only limited size when the
adjacency reset due to a dead timer. If you have WildPackets OmniPeek analzyer
its easy if you understand the protocol operations you need to filter on. I
simply created a filter for the specific packet (in this case OSPF Master Bit).
Whenever the analyzer would see the specific packet it would launch an
executable file. I used SecureCRT's scripting language to have it log into the
router and save off whatever show commands I needed. You can also have it
syslog, snmp-trap, or send an email.