EEM Script to set port names from CDP results

Answered Question
May 4th, 2014
User Badges:
  • Super Gold, 25000 points or more
  • Hall of Fame,

    The Hall of Fame designation is a lifetime achievement award based on significant overall achievements in the community. 

  • Cisco Designated VIP,

    2017 LAN, Wireless

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.

Correct Answer by Joe Clarke about 3 years 3 months ago

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

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

 

Or:

 

"^([^\.]+)"

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (3 ratings)
Loading.
Joe Clarke Mon, 05/05/2014 - 10:59
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

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.

Leo Laohoo Mon, 05/05/2014 - 15:12
User Badges:
  • Super Gold, 25000 points or more
  • Hall of Fame,

    The Hall of Fame designation is a lifetime achievement award based on significant overall achievements in the community. 

  • Cisco Designated VIP,

    2017 LAN, Wireless

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

Joe Clarke Mon, 05/05/2014 - 15:32
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

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.

Leo Laohoo Mon, 05/05/2014 - 15:49
User Badges:
  • Super Gold, 25000 points or more
  • Hall of Fame,

    The Hall of Fame designation is a lifetime achievement award based on significant overall achievements in the community. 

  • Cisco Designated VIP,

    2017 LAN, Wireless

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"?

Joe Clarke Mon, 05/05/2014 - 15:50
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

Add:

 

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

Leo Laohoo Mon, 05/05/2014 - 15:59
User Badges:
  • Super Gold, 25000 points or more
  • Hall of Fame,

    The Hall of Fame designation is a lifetime achievement award based on significant overall achievements in the community. 

  • Cisco Designated VIP,

    2017 LAN, Wireless

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

Correct Answer
Joe Clarke Tue, 05/06/2014 - 10:39
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

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

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

 

Or:

 

"^([^\.]+)"

Leo Laohoo Tue, 05/06/2014 - 17:39
User Badges:
  • Super Gold, 25000 points or more
  • Hall of Fame,

    The Hall of Fame designation is a lifetime achievement award based on significant overall achievements in the community. 

  • Cisco Designated VIP,

    2017 LAN, Wireless

This is in line 230, right Joe? 

 

I'll give this a try tomorrow.  

 

Thanks Joe!  laugh

Leo Laohoo Wed, 05/07/2014 - 18:04
User Badges:
  • Super Gold, 25000 points or more
  • Hall of Fame,

    The Hall of Fame designation is a lifetime achievement award based on significant overall achievements in the community. 

  • Cisco Designated VIP,

    2017 LAN, Wireless

Thanks Joe.  It's working.  laughlaughlaugh

Actions

This Discussion