cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2912
Views
10
Helpful
9
Replies

EEM Script to set port names from CDP results

Leo Laohoo
Hall of Fame
Hall of Fame

I've been using THIS, which Joe has modified.  The script checks the CDP table and only works on routers, switches and wireless access points.  The problem is that the access point doesn't seem to work.  Here's Joe's script: 

 

event manager applet update-port
 event neighbor-discovery interface regexp GigabitEthernet.* cdp add
 action 100 regexp "(Switch|Router|Trans-Bridge)" "$_nd_cdp_capabilities_string"
 action 110 if $_regexp_result eq "1"
 action 200  cli command "enable"
 action 210  cli command "config t"
 action 220  cli command "interface $_nd_local_intf_name"
 action 230  regexp "^([^\.]+)\." "$_nd_cdp_entry_name" match host
 action 240  cli command "description $host"
 action 500 end

And the error I am getting is:  

May  5 12:23:48 AEST: %HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: host
May  5 12:23:48 AEST: %HA_EM-3-FMPD_ERROR: Error executing applet update-port statement 240

The "sh cdp neighbors detail" result of a wireless access point is: 

Device ID: Device
Entry address(es): 
  IP address: 10.227.99.249
Platform: cisco AIR-LAP1142N-N-K9,  Capabilities: Router Trans-Bridge 
Interface: GigabitEthernet4/48,  Port ID (outgoing port): GigabitEthernet0.1
Holdtime : 158 sec

Version :
Cisco IOS Software, C1140 Software (C1140-K9W8-M), Version 15.2(4)JB4, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2014 by Cisco Systems, Inc.
Compiled Thu 06-Mar-14 11:37 by prod_rel_team

advertisement version: 2
Duplex: full
Power drawn: 15.400 Watts
Power request id: 33353, Power management id: 2
Power request levels are:15400 14500 0 0 0 
Management address(es): 

Would appreciate if someone can help me fix this.  

 

Thanks in advance.

1 Accepted Solution

Accepted Solutions

There is no trailing dot.  So you need to use a regexp of either:

"^([^\.]+)\.?"

 

Or:

 

"^([^\.]+)"

View solution in original post

9 Replies 9

Joe Clarke
Cisco Employee
Cisco Employee

If you're ID is really

Device ID: Device

Then your regexp won't match.  You could likely add a '?' at the end of the pattern to indicate the trailing '.' is not required.

Joe, 

 

I substituted the Device ID of the wireless access point.  Device ID is the hostname of the wireless access point which has the following syntax:  SITEasset.  

 

Best Regards/Leo

If you print the value of $_nd_cdp_entry_name, what do you get?  Do not sanitize this as it will be important to see why the regexp is not matching.

If you print the value of $_nd_cdp_entry_name, what do you get? 

Hi Joe, 


Thanks.  

 

EEM is totally out of my league here.  How do I "print the value of $_nd_cdp_entry_name"?

Add:

 

action 221 syslog msg "XXX: '$_nd_cdp_entry_name'"

May  6 08:56:54 AEST: %HA_EM-6-LOG: update-port: XXX: 'CLRM197230'
May  6 08:56:54 AEST: %HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: host
May  6 08:56:54 AEST: %HA_EM-3-FMPD_ERROR: Error executing applet update-port statement 240

Un-sanitized output above, Joe.  

Thanks for sharing your expertise here.  laugh

There is no trailing dot.  So you need to use a regexp of either:

"^([^\.]+)\.?"

 

Or:

 

"^([^\.]+)"

This is in line 230, right Joe? 

 

I'll give this a try tomorrow.  

 

Thanks Joe!  laugh

Thanks Joe.  It's working.  laughlaughlaugh

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: