mple: _crash_reporter_url http://customerurlloc.com/ ### interface_tm.cgi ### ### _crash_reporter_debug (optional) - Display policy debugging information. ### Example: _crash_reporter_debug 1 ### namespace import ::cisco::eem::* namespace import ::cisco::lib::* # Use the Cisco internal EEM crash reporter site if it is not defined # as an EEM environment variable if {[info exists _crash_reporter_debug]} { set crash_debug 1 } else { set crash_debug 0 } # 2. Gather crashinfo information from CLI if [catch {cli_open} result] { error $result $errorInfo } else { array set cli1 $result } if [catch {cli_exec $cli1(fd) "en"} result] { error $result $errorInfo } if [catch {cli_exec $cli1(fd) "show version"} cli_show_version] { error $cli_show_version $errorInfo } if [catch {cli_exec $cli1(fd) "show run"} cli_show_run] { error $cli_show_run $errorInfo } if [catch {cli_exec $cli1(fd) "show file sys"} cli_show_file_sys] { error $cli_show_file_sys $errorInfo } if [catch {cli_exec $cli1(fd) "end"} result] { error $result $errorInfo } if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] { error $result $errorInfo } #Determine if this is an IOS or modular IOS image set i [regexp {.*Software \([^\)]*\-[^\)]*\-([^\)]*)\).*} $cli_show_version match itype] if {$i == 1} { if {$crash_debug == 1} { if {$itype == "VM"} { action_syslog priority info msg "Image type found is modular IOS" } else { action_syslog priority info msg "Image type found is IOS" } } } else { action_syslog priority info msg "Unable to determine image type, exiting" return } #Process show information to gather failure reason set i [regexp {System returned to ROM by (.*?)\n} $cli_show_version match fail] if {$crash_debug == 1} { action_syslog priority info msg "Last restart from $fail" } set j [regexp {.*power-on.*} $fail match] if {$j == 1} { if {$crash_debug == 1} { action_syslog priority info msg "Last restart from power-on, exiting" } return } set j [regexp {.*reload at*} $fail match] if {$j == 1} { if {$crash_debug == 1} { action_syslog priority info msg "Last restart from reload, exiting" } return } #Determine URL location to send crashinfo to. if {[info exists _crash_reporter_url]} { set postUrl $_crash_reporter_url } else { action_syslog priority info msg \ "EEM environment variable _crash_reporter_url not set, exiting" return } if {$crash_debug == 1} { action_syslog priority info msg "Using crash reporter URL: $postUrl" } set latestcrash "" set i [regexp {no exception crashinfo.*\n} $cli_show_run] if {$i == 1} { if {$crash_debug == 1} { action_syslog priority info msg "No crashinfo file CLI command set" } } else { set i [regexp {exception crashinfo file (.*?)\n} $cli_show_run match cname] if {$i == 1} { if {$crash_debug == 1} { action_syslog priority info msg "CRASHINFO PREFIX: $cname" } if {[regexp {(.*:)(.*?)\r?} $cname match device prefix]} { if {$crash_debug == 1} { action_syslog priority info msg "Using prefix: $prefix" } set fileglob "$prefix*" } else { action_syslog priority info msg \ "No prefix named $cname found, exiting" return; } } else { if {$crash_debug == 1} { action_syslog priority info msg "No prefix found, using crashinfo" } set fileglob "crashinfo*" } foreach l [split $cli_show_file_sys \n] { set x "" if {$itype == "VM"} { # Modular IOS dir format set m [regexp {([_A-Za-z0-9]*:).*} $l match fsysentry] } else { # IOS dir format set m [regexp {([_A-Za-z0-9]*:).*\r} $l match fsysentry] } if {$m == 1} { if {$itype == "VM"} { set fsysentry /$fsysentry } if [file isdirectory $fsysentry] { cd $fsysentry set sortedl [lsort -decreasing -ascii \ [glob -nocomplain -- $fileglob]] if {$itype == "VM"} { # Match a modular IOS formatted crashinfo name set ioscrashformat "$fileglob\_ios\-base\-\(\[0\-9_\-\]+\)" } else { # Match an IOS formatted crashinfo name set ioscrashformat "$fileglob\_\(\[0\-9_\-\]+\)" } foreach item $sortedl { if {[regexp $ioscrashformat $item match one]} { set x $item break } } if {[string length $x] > 0} { if {[string length $latestcrash] <= 0} { set latestcrash $x set latestcrashloc $fsysentry } else { if {[string compare $latestcrash $x]} { set latestcrash $x } if {[string equal $x $latestcrash]} { set latestcrashloc $fsysentry } } } } } } if {[info exists latestcrashloc] && [info exists latestcrash]} { if {$crash_debug == 1} { action_syslog priority info msg \ "Latest crashinfo file:$latestcrashloc$latestcrash" } } else { action_syslog priority info msg "Unable to find crash file, exiting" return } } #Fill in crashd, which with data to send to URL array set boxname [sys_reqinfo_routername] set crashd "$boxname(routername)\n" append crashd "$fail\n" append crashd "$latestcrashloc/$latestcrash\n" if {$itype == "VM"} { set crashfinal $latestcrashloc/$latestcrash } else { set crashfinal $latestcrashloc$latestcrash } if [catch {open $crashfinal r} filed] { action_syslog priority info msg \ "Unable to open $crashfinal, exiting" return } else { if {$crash_debug == 1} { action_syslog priority info msg "Opened $crashfinal for reading, success" } foreach line [split [read $filed] \n] { append crashd "$line\n" } } for {set i 0} {($i < 5) && \ [catch {http::geturl $postUrl -query $crashd -queryblocksize 50 -type \ "text/plain" } token]} {incr i} { after 2000 } if {$crash_debug == 1} { action_syslog priority info msg \ "Response from URL: [http::data $token]" } # 6. if the transmission to the crash reporter site was successful, # log a message if {$i < 5} { if {[http::error $token] == ""} { if {[regexp {data successfully received.*} [http::data $token] match]} { action_syslog priority notice msg \ [concat "Crash report" \ "delivered succesfully"] } else { action_syslog priority notice msg \ "Crash report delivery failed" } if {$_cerrno != 0} { set result [format \ "component=%s; subsys err=%s; posix err=%s;\n%s" \ $_cerr_sub_num $_cerr_sub_err $_cerr_posix_err $_cerr_str] error $result } } http::Finish $token http::cleanup $token } else { action_syslog priority notice msg \ "Crash report delivery failed" http::Finish $token http::cleanup $token }