Below you will find some very basic Cisco IOS EEM applets which can be used as a module in more complex applets, such as configuration wizards.
Obviously, EEM applets are able to be implemented for many automation use cases; i.e. monitoring SLA/tracks, making actions based on syslog patterns, re-configuring route-maps, ACLs, BGP configuration and whatever you can imagine…
Have in mind that in the first applet, I’ve used different values for each result, just to have it more clear and understandable; though as a matter of fact, from a Programming/Performance point of view, the less variables we use, the better it is. Also, these can be better tuned and get shortened based on specific scenarios and requirements, which I leave to the reader.
event manager applet PING_TEST event none sync yes default 100 maxrun 150 action 1 cli command "enable" action 10 puts nonewline "\rPLEASE ENTER DESTINATION IP ADDRESS: " action 11 gets IP action 12 cli command "ping $IP" action 13 set C_RESULT "$_cli_result" action 14 string match "*100 percent*" "$C_RESULT" action 15 set M_RESULT "$_string_result" action 20 if $M_RESULT eq "0" action 21 puts "\rFIRST PING FAILED with MATCH result of $M_RESULT !" action 22 puts "HERE IS THE CLI RESULT FOR 1ST PING" action 23 puts "$_cli_result" action 24 puts "\rNOW I AM TRYING FOR 2ND PING" action 25 cli command "ping $IP" action 26 set C_RESULT "$_cli_result" action 27 string match "*100 percent*" "$C_RESULT" action 28 set M_RESULT_2 "$_string_result" action 30 if $M_RESULT_2 eq "0" action 31 puts "\r2ND STRING MATCH RESULT IS $M_RESULT_2" action 32 puts "BOTH 1ST and 2ND PING FAILED!!!" action 33 puts "\rHERE IS FAILED THE CLI RESULT FOR 2ND PING" action 34 puts "$_cli_result" action 35 puts "\r!!!!!! DESTINATION UNREACHABLE !!!!!!" action 40 else action 41 puts "2ND PING WORKED!" action 42 puts "2ND STRING MATCH RESULT IS $M_RESULT_2" action 43 puts "\rHERE IS THE SUCCESSFULL CLI RESULT FOR 2ND PING" action 44 puts "$_cli_result" action 45 puts "\r!!!!!! DESTINATION IS REACHABLE !!!!!!" action 46 end action 50 else action 51 puts "\rFIRST STRING MATCH RESULT IS $M_RESULT" action 52 puts "\rHERE IS THE SUCCESSFUL CLI RESULT FOR 1ST PING" action 53 puts "$_cli_result" action 54 puts "\r!!!!!! DESTINATION IS REACHABLE !!!!!!" action 99 end