cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
6166
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

Hi Joesph

Please check below

::cisco::eem::event_register_none sync yes

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
}

append output $_cli_result

if [cli_read_pattern $cli1(fd) {#\s}} _cli_result]
    error $_cli_result $errorInfo
}

append output $_cli_result

if [catch {cli_exec $cli1(fd) "exit"} _cli_result] {
    error $_cli_result $errorInfo
}
append output $_cli_result
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] } {
        puts "Core: $core, Sessions: $sessions, Users: $users"    }
}

append $output

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

 

Is this the right format ?

 

Thank in advance

This looks right (assuming there is in fact a space after the '#' prompt).  You may have to play with that regular expression so that it matches the prompt without matching the other '#' in the command output.