Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
New Member

EEM Script to log IOS CMD to Syslog

I have been playing around with EEM scripts to run this cmd every 120 seconds so I can see how many of my voice Channels are in use on my MGCP Gateway which has 3 PRIs terminating on it.

Router# sh mgcp stat | i Inuse

Inuse channels: 4

This way I can monitor all my MGCP gateways in one syslog file for usage.

7 REPLIES
Cisco Employee

Re: EEM Script to log IOS CMD to Syslog

Are you asking how to do this with EEM?

New Member

Re: EEM Script to log IOS CMD to Syslog

Yes, how do you do this with EEM?

I have tried this EEM script, but the timer does not appear to work. It only executes once and displays my routers host name:

!

!

event manager applet t1

event none

action 2.0 cli command "enable"

action 2.1 cli command "conf t"

action 2.2 cli command "event manager applet t2"

action 2.3 cli command "event timer countdown time 10"

action 2.4 cli command "exit"

!

event manager applet t2

event none

action 1.0 syslog msg "applet called"

action 1.6 cli command "sh int fa2/0 | inc packets input|packets output"

action 1.7 syslog msg "pkts-in/out fa2/0: $_cli_result"

action 2.0 cli command "enable"

action 2.1 cli command "conf t"

action 2.2 cli command "event manager applet t2"

action 2.3 cli command "event timer countdown time 10"

action 2.4 cli command "exit"

!

event manager applet t3

event none

action 1.0 cli command "sh int fa2/0 | inc packets input|packets output"

action 2.0 syslog msg "result: $_cli_result"

!

event manager applet t4

event none

action 1.0 syslog msg "disabling applet t2"

action 2.0 cli command "enable"

action 2.1 cli command "conf t"

action 2.2 cli command "event manager applet t2"

action 2.3 cli command "event none"

action 2.4 cli command "exit"

!

alias exec stc event manager run t1

alias exec etc event manager run t4

!

alias exec eem event manager run

!

Thanks

Cisco Employee

Re: EEM Script to log IOS CMD to Syslog

I don't see a timer ED here at all. All of your applets have none EDs. However, I see you're trying to configure a timer policy with a countdown timer. The countdown timer only counts down to 0 once, then it never runs again unless it is reregistered. What you want is a watchdog. For example, rewriting applet2:

event manager applet t2

event timer watchdog time 10

action 1.0 syslog msg "applet called"

action 1.1 cli command "enable"

action 1.6 cli command "sh int fa2/0 | inc packets input|packets output"

action 1.7 syslog msg "pkts-in/out fa2/0: $_cli_result"

New Member

Re: EEM Script to log IOS CMD to Syslog

Thanks jclarke,

It appears that the variable "$_cli_result" will only display the last line displayed (written) by the router, which is the hostname. For Example:

Router1#sh mgcp stat | i Inuse

Inuse channels: 0

Router1#

"$_cli_result" = Router1#, not "Inuse channels: 0" because the return of the hostname is the trigger that the command output is finished, at least that I am thinking.

Router1(config)#event manager applet t3

Router1(config-applet)# event timer watchdog time 10

Router1(config-applet)# action 10 syslog msg "applet called"

Router1(config-applet)# action 20 cli command "sh mgcp stat | i Inuse"

Router1(config-applet)# action 30 syslog msg $_cli_result

Router1(config-applet)#!

Router1(config-applet)#^Z

Router1#

180319: .May 20 17:36:35 PDT: %HA_EM-6-LOG: t3: applet called

180320: .May 20 17:36:36 PDT: %HA_EM-6-LOG: t3: Router1>

Router1#

180321: .May 20 17:36:45 PDT: %HA_EM-6-LOG: t3: applet called

180322: .May 20 17:36:46 PDT: %HA_EM-6-LOG: t3: Router1>

Router1#

Cisco Employee

Re: EEM Script to log IOS CMD to Syslog

No, $_cli_result shows the entire contents of the last CLI command. I don't have a router running MGCP, but I do have a 7206 running 12.4(24)T in which show mgcp stat does return some output. The command shows:

UDP pkts rx 0, tx 0

Unrecognized rx pkts 0, MGCP message parsing errors 0

Duplicate MGCP ack tx 0, Invalid versions count 0

CreateConn rx 0, successful 0, failed 0

DeleteConn rx 0, successful 0, failed 0

ModifyConn rx 0, successful 0, failed 0

DeleteConn tx 0, successful 0, failed 0

NotifyRequest rx 0, successful 0, failed 0

AuditConnection rx 0, successful 0, failed 0

AuditEndpoint rx 0, successful 0, failed 0

RestartInProgress tx 0, successful 0, failed 0

Notify tx 0, successful 0, failed 0

ACK tx 0, NACK tx 0

ACK rx 0, NACK rx 0

Collisions: Passive 0, Active 0

IP address based Call Agents statistics:

No Call Agent message.

System resource check is DISABLED. No available statistic

MGCP is disabled. Cannot provide DS0 statistics.

So, I configured an applet:

event manager applet t3

event timer watchdog time 10

action 10 syslog msg "applet called"

action 20 cli command "show mgcp stat | i Collisions"

action 30 syslog msg "$_cli_result"

And I see this on my VTY:

May 21 03:40:21.424: %HA_EM-6-LOG: t3: applet called

May 21 03:40:21.456: %HA_EM-6-LOG: t3: Collisions: Passive 0, Active 0

nms-7206a>

So your applet really should work.

New Member

Re: EEM Script to log IOS CMD to Syslog

I tried it out on a different router, actually a production router and it works!

!

event manager applet t3

event timer watchdog time 20

action 20 cli command "sh mgcp stat | i Inuse"

action 30 syslog msg "$_cli_result"

!

Test Router IOS = c2800nm-advipservicesk9-mz.124-15.T1.bin

Test-Rtr#

180358: .May 21 15:43:16 PDT: %HA_EM-6-LOG: t3: applet called

180359: .May 21 15:43:16 PDT: %HA_EM-6-LOG: t3: Test-Rtr>

Test-Rtr#

IOS = c2800nm-advipservicesk9-mz.124-15.T1.bin

Production Router IOS = c2800nm-spservicesk9-mz.124-15.T7.bin

May 21 22:45:26.289: %HA_EM-6-LOG: t3: Inuse channels: 15

Prod-Rtr#

May 21 22:45:46.289: %HA_EM-6-LOG: t3: Inuse channels: 16

Prod-Rtr#

May 21 22:46:06.290: %HA_EM-6-LOG: t3: Inuse channels: 16

124.15.T7 is newer that 124.15.T1, I wonder if that is the difference?

Now I can have 4 MGCP Gateways, 6 PRIs, all sysloging this info and GREP'ing to my hearts delight ;-)

Thanks jclarke!

Prod-Rtr#

Cisco Employee

Re: EEM Script to log IOS CMD to Syslog

There were quite a few EEM fixes that went into 12.4(15)T7. I didn't see an exact bug for this problem with _cli_result, but one of the fixes could very well have solves some CLI buffer problem. In any event, how you are seeing this work in 12.4(15)T7 is the intended behavior.

522
Views
5
Helpful
7
Replies
CreatePlease to create content