cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
584
Views
3
Helpful
2
Replies

EEM Script for FQDN Translation into IP Address and Static Route

at
Level 1
Level 1

Hello

We want to minimize manual configuration via cli on our cisco cube (ISR8000). The cube is connected between CUCM and SIP-Provider (one internal interface with a default route, one external route with a static route to the sip-server). Our SIP-provider will deliver the sip registrar only via FQDN like "sip.provider.de"! Provider will not tell us the IP Address! Normally this FQDN has one IP-Address  like "110.110.110.1". The  Provider told us, that this Address is not fix and it is possilbe that the address changed, maybe to "120.120.120.1".

On our cisco cube, we have configured on an external Interface a static route to the IP-Address of the sip-server of the provider.

Now we are looking for a EEM  Script,  that automates this step. That means, we look for a Script which will look for the IP Address of the FQDN (show hosts) periodically. If the IP Address does not change no action is required but if the IP Address changes the Script should add/change the static route entry. 

normal entry : "ip route 110.110.110.1 255.255.255.255 190.190.190.1"

if ip address changes the new entry is

"ip route 120.120.120.1 255.255.255.255 190.190.190.1" 

Any Ideas for a EEM Script which realize this change ?

 

Greets

Alex

 

1 Accepted Solution

Accepted Solutions

Dan Frey
Cisco Employee
Cisco Employee

Try this policy.

event manager applet fqdnHost
 event timer watchdog time 300
 action 010 cli command "enable"
 action 030 handle-error type ignore
 action 040 context retrieve key key1 variable "fqdnHost"
 action 050 set previousFqdnHost "$fqdnHost"
 action 055 puts "$previousFqdnHost"
 action 060 cli command "show hosts sip.provider.us | inc sip.provider.us"
 action 070 regexp "([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)" "$_cli_result"" match fqdnHost
 action 075 puts "$fqdnHost"
 action 080 if $_regexp_result eq "0"
 action 090  puts "No regular expression match for FQDN"
 action 095  exit
 action 100 else
 action 110  if $fqdnHost eq "$previousFqdnHost"
 action 120   puts "No change in A record"
 action 125  end
 action 130 else
 action 140  cli command "conf t"
 action 145  cli command "no ip route $previousFqdnHost 255.255.255.255 192.168.0.1"
 action 150  cli command "ip route $fqdnHost 255.255.255.255 192.168.0.1"
 action 160 end
 action 170 context save key key1 variable "fqdnHost"

View solution in original post

2 Replies 2

Dan Frey
Cisco Employee
Cisco Employee

Try this policy.

event manager applet fqdnHost
 event timer watchdog time 300
 action 010 cli command "enable"
 action 030 handle-error type ignore
 action 040 context retrieve key key1 variable "fqdnHost"
 action 050 set previousFqdnHost "$fqdnHost"
 action 055 puts "$previousFqdnHost"
 action 060 cli command "show hosts sip.provider.us | inc sip.provider.us"
 action 070 regexp "([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)" "$_cli_result"" match fqdnHost
 action 075 puts "$fqdnHost"
 action 080 if $_regexp_result eq "0"
 action 090  puts "No regular expression match for FQDN"
 action 095  exit
 action 100 else
 action 110  if $fqdnHost eq "$previousFqdnHost"
 action 120   puts "No change in A record"
 action 125  end
 action 130 else
 action 140  cli command "conf t"
 action 145  cli command "no ip route $previousFqdnHost 255.255.255.255 192.168.0.1"
 action 150  cli command "ip route $fqdnHost 255.255.255.255 192.168.0.1"
 action 160 end
 action 170 context save key key1 variable "fqdnHost"

Hi,

that script works perfect !!!

great job !!! 

I had problems with my own script because we always start with the same ip address - I did not know how to save the last known address  - you will solve this very smart (action 0170 context save key key1 ... and actoin 0040) 

We tested successfully

(changing the ip address and looked to the output/static route) 

733146: Mar 14 17:01:12.219 MET: %HA_EM-6-LOG: fqdnHost: x.x.x.60
733147: Mar 14 17:01:42.111 MET: %HA_EM-6-LOG: fqdnHost: x.x.x.60
733148: Mar 14 17:01:42.221 MET: %HA_EM-6-LOG: fqdnHost: x.x.x.60
733149: Mar 14 17:01:42.221 MET: %HA_EM-6-LOG: fqdnHost: No change in A record
733151: Mar 14 17:02:12.111 MET: %HA_EM-6-LOG: fqdnHost: x.x.x..60
733152: Mar 14 17:02:12.222 MET: %HA_EM-6-LOG: fqdnHost: x.x.x.61
733153: Mar 14 17:02:42.109 MET: %HA_EM-6-LOG: fqdnHost: x.x.x.61
733154: Mar 14 17:02:42.219 MET: %HA_EM-6-LOG: fqdnHost: x.x.x.61
733155: Mar 14 17:02:42.220 MET: %HA_EM-6-LOG: fqdnHost: No change in A record
 

again - great job

thank you very much 

Greets

Alex