cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1741
Views
0
Helpful
10
Replies

EEM to SSH and Reboot Cisco SIP Phone

David Kieu
Level 1
Level 1

Good afternoon everyone.  I have been referred to the Cisco Support Community for assistance by TAC.  I was hoping that you can help me with an EEM script that I am somewhat able to get working.  However, it does not meet my requirements 100%.  Since I am not proficient in this, I am hoping an expert out there can guide me in the right direction.

I currently have an environment where there is a Cisco 881-K9 router connected via WAN to a VSAT Internet provider.  Unfortunately, the VSAT Internet provider drops quite often.  When this outage occurs, the Cisco 8841-K9 SIP phone begins to search for a system to register the phone to.  If the outage is brief enough, the phone will automatically register again once the Internet connection is available.  However, if the outage is long enough for the phone to reach its timeout threshold, the phone will enter a state where it will require human interaction to press the RETRY button.

I am trying to automate a process where the phone will auto-register regardless of the state of the Internet.  I have decided to try to use EEM to trigger the router to log into the phone every 5 minutes via SSH and reboot the phone if the state of the device has a specific value.  Unfortunately, I have seen different values other than "REGISTERED".  I have seen values of "NONE", "REGISTERING" and "UNDEFINED".

The script below seems to work only if the phone states at a state of "REGISTERING".  But since I cannot predict the value when the router experiences a long outage, I cannot rely that the state will remain in "REGISTERING".  I am wondering if you can help me revise this script to reboot the phone if it is any value other than "REGISTERED".  I cannot seem to get this working and am seeking some help.  

Also, would a script like this that runs every 5 minutes have negative impact on the router itself?  Would this consume too much memory or halt the Cisco 881-K9 router?  Any help that you can provide would be greatly appreciated.  Thank you!

Regards,
David

EEM SCRIPT

event manager applet resetphone

event timer cron name resetphone cron-entry "5 * * * *"

action 010 cli command "enable"

action 020 cli command "ssh -l admin 10.13.30.70 " pattern "assword:"

action 030 cli command "admin" pattern "login:"

action 040 cli command "debug" pattern "assword:"

action 050 cli command "debug" pattern ">"

action 060 cli command "show register" pattern "<EOT>"

action 070 foreach line "$_cli_result"

action 080  regexp "(REGISTERING)+" "$line"

action 090  if $_regexp_result eq "1"

action 100   cli command "reset hard" pattern ">"

action 110  end

action 120 end

10 Replies 10

Francesco Molino
VIP Alumni
VIP Alumni

Hi

I think you're question is about regex on how to match any words except REGISTERED.

The regex would be:

(\b(?!REGISTERED\b)\w+)

Just a stupid question. Does your phone is powered by POE? If yes, why not just shutting down the port and unshutting it?

Thanks

PS: Please don't forget to rate and mark as correct answer if this answered your question 


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

Hello Francesco. Thank you for the reply. I have modified action 080 as you suggested, but left everything else the same.

BEFORE
action 080 regexp "(REGISTERING)+" "$line"

AFTER
action 080 regexp "(\b(?!REGISTERED\b)\w+)" "$line"

The phone currently is in the state of "NONE" and it has not rebooted so far. I will wait a little bit longer and see.

As for your question regarding POE, we had purchased these Cisco 881-K9 routers without a POE daughter card. The phone directly connects to the router. Any other switch we that we have are very low-end unmanaged switches that does not have the POE capabilities.

I will keep you updated later today to let you know if this works. Once completed, I will rate and mark the answer to this discussion.

Thank you again for your help.

Regards,
David

Ok I've to test it on a router to validate the exact thing you need to do in EEM.

The regex pattern is correct but I need to ensure if you need to add / at the beginning and /g at the end.


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

Thank you for suggesting the ELSE statement. I will actually try that when I get back in the office.  I should have thought of that!  :)

I will keep you posted.  I appreciate your time on all these suggestions!

Francesco,

Sorry for the late response.  I had been in a workshop for the last few days and have not gotten back to testing this out.  Can you review the following script and see if I have added the right ELSE statement like you suggested?  I am not proficient in EEM and hope you are not bothered by my lack of knowledge on this.  I also changed it to cycle every 1 minute for testing purposes and the phone still does not respond.

Regards,
David

event manager applet resetphone
event timer cron name resetphone cron-entry "1 * * * *"
action 010 cli command "enable"
action 020 cli command "ssh -l admin 10.13.30.70 " pattern "assword:"
action 030 cli command "admin" pattern "login:"
action 040 cli command "debug" pattern "assword:"
action 050 cli command "debug" pattern ">"
action 060 cli command "show register" pattern "<EOT>"
action 070 foreach line "$_cli_result"
action 080 regexp "(REGISTERED)+" "$line"
action 090 if $_regexp_result eq "0"
action 100 end
action 105 else
action 110 cli command "reset hard" pattern ">"
action 120 end
!

It seems OK but personally i would do nothing, for testing purpose if value is correct and then removed this line: 

action 100 end

It's just too be sure that everything works as expected. 

You can put it back after.

Thanks

PS: Please don't forget to rate and mark as correct answer if this answered your question


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

Just so we're clear, you want this to run at one minute past the hour every hour?  In general, this looks okay.  I might rewrite to:

event manager applet resetphone
event timer cron name resetphone cron-entry "1 * * * *"
action 010 cli command "enable"
action 020 cli command "ssh -l admin 10.13.30.70 " pattern "assword:"
action 030 cli command "admin" pattern "login:"
action 040 cli command "debug" pattern "assword:"
action 050 cli command "debug" pattern ">"
action 060 cli command "show register" pattern "<EOT>"
action 070 foreach line "$_cli_result"
action 080 regexp "(REGISTERED)+" "$line"
action 090 if $_regexp_result eq "1"
action 110  cli command "reset hard" pattern ">"
action 120 end

When it comes to your regexp, did you really mean to match one or more of the phrase "REGISTERED" in a row.  That is, your regular expression would match:

REGISTEREDREGISTERED

But it wouldn't match:

REGISTERED REGISTERED

Seems like an odd match to me.

Before testing it after my work, I was just thinking why don't you keep your EEM but adding a ELSE statement. If REGISTERING is matched, do nothing (or write something, doesn't matter) else reboot the phone.

Can you test it?


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

This won't actually work.  EEM applet regexp's aren't very advanced.  You can't use \b and negative lookahead assertions.  You would need Tcl for that.  And in Tcl, the word boundary pattern is \y.

Joe Clarke
Cisco Employee
Cisco Employee

Ah.  I'm answering this backwards.  You want to match if REGISTERED is not there.  The problem is, we don't know what this output looks like.  In order to be effective, we need to see the full output of the "show register" command.

Review Cisco Networking for a $25 gift card