07-01-2016 08:13 AM
Hi All,
I have some branch offices with a Cable ISP company with dynamic IP address, I'm trying to create a script to automatically send an email if the interface get a new IP address if the interface get the previous IP do not send an email .
So far this is the script I created :
event manager applet TEST2
event syslog pattern "Interface FastEthernet1 assigned DHCP"
action 1.1 cli command "enable"
action 1.2 cli command "show int FastEthernet1 | i Internet address"
action 1.51 regexp "Internet address is 9.9.9.9 /30" "$_cli_result"
action 1.6 if $_regexp_result eq "0"
action 2.0 mail from testevent@anydomain.com to emai@anydomain.com subject "NEW IP ADDRESS " server SMTP.ANYDOMAIN.COM body "$_syslog_msg"
action 2.1 end
The only issue with the script is that if the interface get a new IP address I need to update the script in action 1.51 regexp with the new IP address so next time the interface change the IP compare with the variable Internet address is ...
Thank you,
Solved! Go to Solution.
07-01-2016 11:06 AM
There are a number of ways to do what you want. A file on flash is probably the easiest given it will persist across reboots.
event manager applet check-ip
event syslog pattern "Interface FastEthernet1 assigned DHCP"
action 1.0 cli command "enable"
action 2.0 handle-error type ignore
action 3.0 file open fd flash:myip.txt r
action 4.0 if $_error ne FH_EOK
action 4.1 set currip "0.0.0.0"
action 4.2 else
action 4.3 file gets fd currip
action 4.4 file close fd
action 4.5 end
action 4.6 handle-error type exit
action 4.7 cli command "show int Fa1 | inc Internet address"
action 4.8 regexp "Internet address is ([0-9\.]+)" "$_cli_result" match myip
action 4.9 if $myip ne $currip
action 5.0 mail from testevent@anydomain.com to emai@anydomain.com subject "NEW IP ADDRESS " server SMTP.ANYDOMAIN.COM body "$_syslog_msg"
action 5.1 file open fd flash:myip.txt w
action 5.2 file puts fd nonewline $myip
action 5.3 file close fd
action 5.4 end
07-01-2016 11:06 AM
There are a number of ways to do what you want. A file on flash is probably the easiest given it will persist across reboots.
event manager applet check-ip
event syslog pattern "Interface FastEthernet1 assigned DHCP"
action 1.0 cli command "enable"
action 2.0 handle-error type ignore
action 3.0 file open fd flash:myip.txt r
action 4.0 if $_error ne FH_EOK
action 4.1 set currip "0.0.0.0"
action 4.2 else
action 4.3 file gets fd currip
action 4.4 file close fd
action 4.5 end
action 4.6 handle-error type exit
action 4.7 cli command "show int Fa1 | inc Internet address"
action 4.8 regexp "Internet address is ([0-9\.]+)" "$_cli_result" match myip
action 4.9 if $myip ne $currip
action 5.0 mail from testevent@anydomain.com to emai@anydomain.com subject "NEW IP ADDRESS " server SMTP.ANYDOMAIN.COM body "$_syslog_msg"
action 5.1 file open fd flash:myip.txt w
action 5.2 file puts fd nonewline $myip
action 5.3 file close fd
action 5.4 end
07-01-2016 12:45 PM
I'm getting this error *Jul 1 19:31:01.152: %HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: myip
07-01-2016 12:49 PM
Never mine ... I just have the incorrect interface
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