02-27-2014 05:41 AM
Hi,
I am working on an applet which would get triggered if there is a state change on an object.
One of the requirements is to collect the traceroute output.
I am able to append the output of most of the commands to a text file but not the output of traceroute. I tried the following method however that doesn't help either:
action 8.0 cli command "more $_cli_result | append log-failure.txt"
How can I write the output of ping and traceroute to a file?
Thanks,
Nishant Hura
Device :
Cisco IOS Software, C3900 Software (C3900-UNIVERSALK9-M), Version 15.1(4)M6, RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2013 by Cisco Systems, Inc.
Compiled Thu 14-Feb-13 07:40 by prod_rel_team
ROM: System Bootstrap, Version 15.0(1r)M16, RELEASE SOFTWARE (fc1)
mla1-rpi-wan-1 uptime is 35 weeks, 6 days, 5 minutes
System returned to ROM by reload at 08:26:29 CST Fri Jun 21 2013
System restarted at 08:33:38 CST Fri Jun 21 2013
System image file is "flash0:c3900-universalk9-mz.SPA.151-4.M6.bin"
Last reload type: Normal Reload
Last reload reason: Reload Command
This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.
A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
If you require further assistance please contact us by sending email to
Cisco CISCO3945-CHASSIS (revision 1.0) with C3900-SPE150/K9 with 2029568K/67584K bytes of memory.
Processor board ID FCZ16337QPJ
3 Gigabit Ethernet interfaces
62 Serial interfaces
1 terminal line
4 Channelized E1/PRI ports
DRAM configuration is 72 bits wide with parity enabled.
255K bytes of non-volatile configuration memory.
4013856K bytes of ATA System CompactFlash 0 (Read/Write)
License Info:
License UDI:
-------------------------------------------------
Device# PID SN
-------------------------------------------------
*0 C3900-SPE150/K9 FOC16461CXM
Technology Package License Information for Module:'c3900'
-----------------------------------------------------------------
Technology Technology-package Technology-package
Current Type Next reboot
------------------------------------------------------------------
ipbase ipbasek9 Permanent ipbasek9
security None None None
uc uck9 Permanent uck9
data None None None
Configuration register is 0x2102
02-27-2014 09:15 PM
You can take your applet to http://www.marcuscom.com/convert_applet/ to convert it to Tcl. Then, you can add this code to output the traceroute:
set fd [open "flash:log-failure.txt" "a"]
puts $fd $_cli_result
close $fd
03-10-2014 07:30 AM
Thanks for the reply Joseph.
I tried the TCL conversion tool for the following script.
# event manager applet log-failure
# event track 13 state any
# action 1.0 cli command "enable"
# action 7.0 cli command "trace 4.2.2.2 source lo 0"
It got converted into
::cisco::eem::event_register_track 13 state any
#
# This EEM tcl policy was generated by the EEM applet conversion
# utility at http://www.marcuscom.com/convert_applet/
# using the following applet:
#
# event manager applet log-failure
# event track 13 state any
# action 1.0 cli command "enable"
# action 7.0 cli command "trace 4.2.2.2 source lo 0"
#
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_exec $cli1(fd) "enable"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "trace 4.2.2.2 source lo 0"} _cli_result] {
error $_cli_result $errorInfo
}
#Added the following script as suggested by yourself.
set fd [open "flash:log-failure.txt" "a"]
puts $fd $_cli_result
close $fds
# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result
Following is the error i get
mla1-rpi-wan-1#tclsh flash:test.tcl
invalid command name "::cisco::eem::event_register_track"
while executing
"::cisco::eem::event_register_track 13 state any"
(file "flash:test.tcl" line 1)
03-13-2014 07:50 PM
This is an EEM Tcl script not a tclsh script. You need to register it by following the instructions at http://www.cisco.com/c/en/us/td/docs/ios/netmgmt/configuration/guide/12_2sx/nm_12_2sx_book/nm_eem_policy_tcl.html .
03-13-2014 10:41 PM
Hello Joseph,
I need your expert advice on this. I have EEM that pings several sites...
I went further by instructing the EEM to send the ping output to my mail.
Now the problem is that output of all before that last are omitted in the mail.
How can I have everything( all pings to sites) sent in one mail.
Thanks to treat...
07-20-2016 04:13 AM
Hello,
I have a requirement to capture the Traceroute command output through EEM Script.
---------------------------------------------------------------------------------------------
Applet needs to be converted in to TCL script & add the below code:
set fd [open "flash:log-failure.txt" "a"]
puts $fd $_cli_result
close $fd
----------------------------------------------------------------------------------------------
It would be really great, if you share the remaining steps for achieving this task.
Best Regards,
Manjesh Michael
07-20-2016 04:43 AM
Take the code you have pasted here and paste it to the bottom of the Tcl script you get back from my conversion tool. Then follow the link I included above for how you can register the resulting EEM Tcl policy.
07-20-2016 07:02 AM
Thanks Joe for the quick response. I referred the URL, however it seems a bit difficult. Could you please assist with the steps, if its readily available ?
07-23-2016 03:43 AM
Create flash:/eem
Configure:
event manager directory user policy flash:/eem
Copy your Tcl policy into that directory.
Configure:
event manager policy mypol.tcl
Where mypol.tcl is the name of the Tcl policy file.
12-18-2017 09:33 AM
Just adding another solution.
Here is my EEM script that:
1. Triggers on a Syslog event
2. Writes the current time and date to a file on flash:
3. Performs a traceroute and dumps the output to the same file.
event manager applet CaptureIPSLAsyslogs
event syslog pattern "%TRACK-6-STATE:" maxrun 300
action 1.0 cli command "enable"
action 1.1 cli command "show clock | append flash:/IPSLA.TXT"
action 1.2 cli command "traceroute vrf IWAN-Internet 10.10.10.10 numeric source 10.10.10.1"
action 1.3 file open fd IPSLA.TXT a
action 1.4 file write fd "$_cli_result"
action 1.5 file close fd
I hope this helps.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide