Network Change & Configuration Management

Reply
Highlighted

Hostname too long : Context error

SChacon
Techie
Posts: 5
4162     0

Hello,

I have a problem with my scripts. The problem is the hostname of cisco switches in my company is between 16 and 25 characters long and, when I run a script to change the config, the script fails int timeout because the hostname change when it does the command configure terminal (the hostname is trunk to 20 characters only). I don't find a method to doesn't check the context (I already try Trigger-Context).

 

This is my script:

 


Script-Filter:
    $Vendor eq "Cisco"

###########################################################################

Action:
    Execute Command Batch 

Action-Commands: 
    sh policy-map | i Policy 

Output-Triggers:
    Find policyMap_name

###########################################################################

Trigger: 
    Find policyMap_name


Trigger-Variables: 
#This regex take the policy-map name
    $PolicyMap_name "/[^*Policy Map ](\w+|-)*/"

Trigger-Template:
    [[$PolicyMap_name]] 

Trigger-Commands: {$PolicyMap_name in ["QOS-CLIENT", "QOS-VOICE-TPHONE"]}
    show policy-map $PolicyMap_name | i Class

Output-Triggers:
    Parse classMap

###########################################################################

Trigger: 
    Parse classMap
    
Trigger-Variables: 
#This regex controls if the class names are AUDIO, VIDEO, SIGNALING, FILE-TRANSFER, APP-SHARING or class-default
    $classMap_name "/[^*Class ](\w+|-)*/"

Trigger-Template:
    [[$classMap_name]]

Trigger-Commands:
sh class-map $classMap_name | i Match

    
Output-Triggers:
    Parse accesslist
    
###########################################################################

Trigger: 
    Parse accesslist


Trigger-Variables: 
#This regex 
    $accessList_name "/[^*Match access\-group name ](\w+|-)*/"

Trigger-Template:
    [[$accessList_name]]


Trigger-Commands: {$accessList_name in ["LYNC-APP-SHARING", "LYNC-FILE-TRANSFER","LYNC-VIDEO","VOICE-SIGNALING","VOICE-SIGNALLING","VOICE-TRAFFIC"]}
conf t
no ip access-list extended $accessList_name\r
    no class-map match-all $classMap_name\r
end
     
###########################################################################

Action:
    Configure 

Action-Commands:
    configure terminal
    no policy-map $PolicyMap_name
    class-map match-all FILE-TRANSFER
     match access-group name LYNC-FILE-TRANSFER
    class-map match-all APP-SHARING
     match access-group name LYNC-APP-SHARING
    class-map match-all VIDEO
     match access-group name LYNC-VIDEO
    class-map match-all AUDIO
     match access-group name VOICE-TRAFFIC
    class-map match-all SIGNALING
     match access-group name VOICE-SIGNALING
!
    policy-map QOS-CLIENT
     class AUDIO
      set dscp ef
     class VIDEO
      set dscp af41
     class SIGNALING
      set dscp cs3
     class FILE-TRANSFER
      set dscp af11
     class APP-SHARING
      set dscp af21
     class class-default
      set dscp default

!
    end 
    wr mem

Hi Sebastian,

Adviser
Posts: 53
4163     0

Hi Sebastian,

Could you provied the Status and Session logs from a failed run? I'm pretty confident we can work around this somehow, probably using Trigger-Context. Seeing the logs from a failed run will help me to to come up with a work around.

Thanks,

- Chris

 

Status log

SChacon
Techie
Posts: 5
4163     0

Here you have the status logs:

+++ Looking up device information ...................................... OK

+++ Looking up device information ...................................... OK +++

Looking up job specification information ........................... OK +++

Loading ccs file ................................................... OK

+++ Script: Set Policy and Class Map

+++ Script-Filter ...................................................... MATCH MATCH

+++ Looking up authentication information .............................. OK

+++ Opening ssh session with 172.22.254.153 ............................ OK

+++ Got password prompt, sending '*****' ............................... OK

+++ Prompt detect round [1] ............................................ OK

+++ Prompt type [0] round times [1] [1] ................................ OK

+++ Prompt [broc-e2-c3750-48ps-s1#] verify [broc-e2-c3750-48ps-s1#] .... OK

+++ Sending 'enable' ................................................... MATCH OK

+++ Enable prompt detect round [1] ..................................... OK

+++ Prompt type [0] round times [1] [1] ................................ OK

+++ Prompt [broc-e2-c3750-48ps-s1#] verify [broc-e2-c3750-48ps-s1#] .... OK

+++ Sending 'terminal no monitor' ...................................... MATCH OK

+++ Sending 'terminal length 0' ........................................ MATCH OK

+++ Sending 'terminal no editing' ...................................... MATCH OK

+++ 1. Action: Execute Command Batch +++ 1. [Action-Commands]

+++ 1. Sending 'sh policy-map | i Policy' .............................. MATCH OK MATCH

+++ 1.1. Trigger: Find policyMap_name +++ 1.1. Trigger-Template .............................................. MATCH

+++ 1.1. [Trigger-Variables] +++ 1.1. $policymap_name = 'QOS-CLIENT'

+++ 1.1. [Trigger-Commands] +++ 1.1. Command condition ............................................. MATCH

+++ 1.1. Sending 'show policy-map QOS-CLIENT | i Class' ................ MATCH OK MATCH

+++ 1.1.1. Trigger: Parse classMap

+++ 1.1.1. Trigger-Template ............................................ MATCH

+++ 1.1.1. [Trigger-Variables] +++ 1.1.1. $classmap_name = 'AUDIO'

+++ 1.1.1. [Trigger-Commands] +++ 1.1.1. Sending 'sh class-map AUDIO | i Match' ...................... MATCH OK MATCH

+++ 1.1.1.1. Trigger: Parse accesslist

+++ 1.1.1.1. Trigger-Template .......................................... MATCH

+++ 1.1.1.1. [Trigger-Variables] +++ 1.1.1.1. $accesslist_name = 'VOICE-TRAFFIC'

+++ 1.1.1.1. [Trigger-Commands] +++ 1.1.1.1. Command condition ......................................... MATCH

+++ 1.1.1.1. Sending 'conf t' .......................................... MATCH OK MATCH

+++ Closing Cisco session ............................................. OK *** ERROR: Timeout waiting for device ***
 

Session log

SChacon
Techie
Posts: 5
4163     0

password:

 broc-e2-c3750-48ps-s1#enable

broc-e2-c3750-48ps-s1#

broc-e2-c3750-48ps-s1#terminal no monitor

broc-e2-c3750-48ps-s1#terminal length 0

broc-e2-c3750-48ps-s1#terminal no editing

broc-e2-c3750-48ps-s1#sh policy-map | i Policy Policy Map QOS-CLIENT

broc-e2-c3750-48ps-s1#show policy-map QOS-CLIENT | i Class

Class AUDIO Class VIDEO Class SIGNALING Class FILE-TRANSFER Class APP-SHARING Class class-default

broc-e2-c3750-48ps-s1#sh class-map AUDIO | i Match

Match access-group name VOICE-TRAFFIC

broc-e2-c3750-48ps-s1#conf t

Enter configuration commands, one per line. End with CNTL/Z.

broc-e2-c3750-48ps-s(config)#exit

broc-e2-c3750-48ps-s1# *** Job Failed [1] ***

 

Hi Sebastian,

Adviser
Posts: 53
4163     0

Hi Sebastian,

Thanks for the output. Let's try converting the last Action to a Trigger and see if we can get things to work using a Trigger-Context. Example follows (please note, not tested). Also, you'll need to do the "wr mem" in a subsequent trigger since the "end" command will adjust the prompt back to the pre-"configure terminal" state.

Thanks,
- Chris


Trigger:                   Configure

Trigger-Filter:            true
Trigger-Context:           true

#                          Command to enter the new context
Trigger-Context-Enter:     configure terminal

#                          Regular expression that defines what the prompt in the new context will look like
Trigger-Context-Prompt:    .*broc-e2-c3750-48ps-s.config.#

#                          Command to exit the context
Trigger-Context-Exit:      end 

# Commands to execute in the context
Trigger-Commands:
    no policy-map $PolicyMap_name
    class-map match-all FILE-TRANSFER
     match access-group name LYNC-FILE-TRANSFER
    class-map match-all APP-SHARING
     match access-group name LYNC-APP-SHARING
    class-map match-all VIDEO
     match access-group name LYNC-VIDEO
    class-map match-all AUDIO
     match access-group name VOICE-TRAFFIC
    class-map match-all SIGNALING
     match access-group name VOICE-SIGNALING
!
    policy-map QOS-CLIENT
     class AUDIO
      set dscp ef
     class VIDEO
      set dscp af41
     class SIGNALING
      set dscp cs3
     class FILE-TRANSFER
      set dscp af11
     class APP-SHARING
      set dscp af21
     class class-default
      set dscp default

Re: Hostname too long : Context error

Adviser
Posts: 60
4163     0

Hello Sebastian,

 

Can you please confirm your current version ? An improvement in recent version may be helpful for you

Re: Hostname too long : Context error

Authority
Posts: 40
4163     0

Hi Chris, Rajiv,

We have the same problem for script in perl as well.


@Rajiv wrote:

Hello Sebastian,

 

Can you please confirm your current version ? An improvement in recent version may be helpful for you


 

Specifically when the router switches to config prompt, it trims the hostname. At this point, the script goes into a hung state perhaps waiting for the full_hostname(config)# prompt. It later quits the script throwing an error, "Error due to timeout".

 

Probably, you can handle this by trimming down the hostname to <X> characters just as IOS does.

 

 

Re: Hostname too long : Context error

MilesSmith
Techie
Posts: 5
4163     0

Thank you so much for this. I was into this issue and tired to tinker around to check if its possible but couldnt get it done. Now that i have seen the way you did it, thanks guys
with
regards

Re: Hostname too long : Context error

mrqbap
Not applicable
Posts: 0
4163     0

Why you adding those Panda Helper links? There are better webpages!

Showing results for 
Search instead for 
Do you mean 

Recommended for You