cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5340
Views
5
Helpful
46
Replies

Cisco IOS XR EEM

mkhalil10
Spotlight
Spotlight

Hi , I have Cisco ASR9k running with NAT44 service

I have some numbers to monitor that will be extracted using show | include

I want to write an EEM script that will take an action if this value exceeds a certain value

As well , can I draw these value using show with include option ?

 

Thanks

46 Replies 46

Joe Clarke
Cisco Employee
Cisco Employee

I'm not exactly sure what you're asking.  If you're asking can you take the data presented from a show command piped to include within EEM, then the answer is yes.  Here is a quick example:

 

set output [cli_exec $cli(fd) "show proc cpu sorted | include SNMP"]

 

Then the variable $output will contain the results of the piped show command.

Hi and thanks for the reply

ASR9k ISM has no MIBs available and there are some values I get from show commands I want to graph , but first I need to write the script to pull the data

In the example you gave the results are stored where ?

 

BR,

Mohammad

The output is stored in an in-memory variable.  You can decide how to persist or transmit that data.  You can send it via a syslog message, email, or write it out to a file.  The file can be transmitted to a remote server via any of the protocols supported by IOS-XR.

Hi again and thanks for the reply , can you provide a sample script that will achieve what am looking for , or is there any specific scripting language I shall follow?

 

Thanks

I don't know what commands and data you're looking to extract or how you'd like to store/transmit them.  There are a number of sample Tcl scripts in this forum that do all sorts of things.  If you browse through the "Documents" section of this community, you can see them.  Else you'll need to provide some more information.

What am looking for graphing the output below

 

RP/0/RSP0/CPU0:ASR9K#run attach 0/1/CPU0
Sun Feb 15 13:11:31.280 UTC

attach: Starting session 1 to node 0/1/CPU0
# show_nat44_stats

         CORE-ID              #SESSIONS(%UTIL)          #USERS(%UTIL)
------------------------------------------------------------------------
            0              667077(23.2%)             54632(41.68%)
            1              679003(23.6%)             54596(41.65%)
            2              684900(23.8%)             54499(41.58%)
            3              680761(23.7%)             54496(41.58%)
            4              236874(8.2%)              10823(8.26%)
            5              241627(8.4%)              10837(8.27%)
            6              241785(8.4%)              10853(8.28%)
            7              240576(8.4%)              10791(8.23%)
------------------------------------------------------------------------
                 Total Sessions: 3672603                 Total users: 261527
Main DB size is 2875008 and User DB size is 131072
#
# exit
Terminating attach to node 0/1/CPU0..

I haven't personally tried attach commands through EEM, but I think they will work.  Here is a script that can be registered and run with "event manager run SCRIPTNAME" to print each line via syslog.  See http://www.cisco.com/c/en/us/td/docs/routers/crs/software/crs_r4-2/system_monitoring/configuration/guide/b_sysmon_cg42crs/b_sysmon_cg42crs_chapter_010.html for instructions to register the script:

::cisco::eem::event_register_none

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]

if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_write $cli1(fd) "run attach 0/1/CPU0"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_read_pattern $cli1(fd) "#"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_write $cli1(fd) "show_nat44_stats"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_read_pattern $cli1(fd) "#"} _cli_result] {
    error $_cli_result $errorInfo
}

set output $_cli_result

if [catch {cli_exec $cli1(fd) "exit"} _cli_result] {
    error $_cli_result $errorInfo
}

foreach line [split $output "\n"] {
    set line [string trim $line]
    regsub -all {\s+} " " $line line
    if { [regexp {^([0-9]+) ([0-9]+)\([0-9]+%\) ([0-9]+)} $line -> core sessions users] } {
        action_syslog msg "Core: $core, Sessions: $sessions, Users: $users"    }
}

# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result

Thanks very much man , I will try it and give u an update in regards

I have a question , in the run attach mode , I cannot get a list of commands available and I searched google and 0 results , how can I get to know the commands available in that mode?

 

BR,

Mohammad

Joseph , I have a question

If I wanted to run the policy above and test it , what should I do ?

I already configured the user

router#admin Config

username user
   group root-system
   group cisco-support
   secret user
  

aaa authorization eventmanager default local

event manager directory user policy harddisk:/scripts/

event manager policy stats.tcl  username user persist-time infinite

#event manager tun stats.tcl ?

 

Thanks in advance

Yes, that should work.

I have IOS XR simulation box and am trying to test EEM TCL scripting

username EEMUSER
 group root-system
 group cisco-support
 secret cisco

aaa authorization eventmanager default local

event manager directory user policy disk0:/usr/
event manager policy test.tcl username EEMUSER persist-time infinite

I tried to write a script that will only display the show bgp summary when I run it , but it seems not working

::cisco::eem::event_register_none

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

set commands [ list \
  "sh bgp summary"\
  ]

action_syslog priority info msg "test.tcl was triggered"

action_syslog priority notice msg "Opening CLI..."
if [catch {cli_open} result] {
     action_syslog priority info msg "Error: $result : $errorInfo"
     error $result $errorInfo
} else {
     action_syslog priority info msg "OK"
     array set cli $result
}

#Run cmds
foreach cmd $commands {
     action_syslog priority info msg "Executing: $cmd"
     set result [ cli_exec $cli(fd) $cmd ]
     action_syslog priority info msg $result }

RP/0/0/CPU0:XR1#event manager run test.tcl
Tue Apr  7 13:43:44.488 EET
RP/0/0/CPU0:Apr  7 13:43:45.768 : tclsh[65816]: %HA-HA_EEM-6-ACTION_SYSLOG_LOG_INFO : test.tcl: test.tcl was triggered
RP/0/0/CPU0:Apr  7 13:43:45.768 : tclsh[65816]: %HA-HA_EEM-5-ACTION_SYSLOG_LOG_NOTICE : test.tcl: Opening CLI...
RP/0/0/CPU0:Apr  7 13:43:47.318 : tclsh[65816]: %HA-HA_EEM-6-ACTION_SYSLOG_LOG_INFO : test.tcl: OK
RP/0/0/CPU0:Apr  7 13:43:47.318 : tclsh[65816]: %HA-HA_EEM-6-ACTION_SYSLOG_LOG_INFO : test.tcl: Executing: sh bgp summary
RP/0/0/CPU0:Apr  7 13:43:48.048 : tclsh[65816]: %HA-HA_EEM-6-ACTION_SYSLOG_LOG_INFO : test.tcl: sh bgp summary

No output appears

 

Syslog is a bad way to pass command output.  Try "puts" instead:

 

puts $result

Hi Joseph,

 

I have to collect some show tech files but only when this log message is

generated:

sysdb_svr_admin[421]:

When this message appears I have to collect 

show tech sysdb

show tech gsp client process sysdb_mc

show  tech gsp

Problem is that I have only 5 minutes to collect this info.

 

I do not have an idea how to write this script. On IOS it's simple.

Can you help me out?

Hi

If you can write the script using IOS , use the below to convert it

www.marcuscom.com/cgi-bin/convert_applet.cgi

 

BR,

Mohammad

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: