cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1707
Views
0
Helpful
7
Replies

EEM Applet for Autodiscovery of LLDP Neighbors

iancresswell
Level 1
Level 1

I have created an EEM script that auto update the description of a port base don the attached device.

 

My script works fine if I clear the lldp table

However if I remove and re-add a device I get an error

 

I am not going to include the entire script as it is quite lengthy, however this is the section it fails on when a device is added:

 

event manager applet auto-update-lldp-port-description authorization bypass
 event neighbor-discovery interface regexp .*Ethernet.*$ lldp add

  action 2.4      regexp "^(.*)" "$$_nd_lldp_system_name" match System Name:

 

I get the following error:

%HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: _nd_lldp_system_name

 

If I clear the lldp table it updates all ports, however if I remove a device and then add it back in I get the above error

 

Anyone got any ideas?

7 Replies 7

Joe Clarke
Cisco Employee
Cisco Employee

The two '$' are wrong.  But I'm not sure what you're trying to achieve here since you only have one parenthetical grouping but two kind-of variable names.  I say kind-of because the ':' at the end of Name is not going to work.  Moreover, the regexp just matches everything within $_nd_lldp_system_name, so I'm not sure why you need this at all.  You could just use $_nd_lldp_system_name as-is.

yeah sorry that's a typo, should be:

action 2.4      regexp "^(.*)" "$_nd_lldp_system_name" match System Name:

 

The above command matches everything after System Name:

 

So I use this to add a description to my ports, what is confusing me is why I get an error saying it cannot find environment variable _nd_lldp_system_name

This will not do what you want.  You want something like:

action 2.4 regexp "System Name: (.*)" "$_nd_lldp_system_name" match sname

Then you can use $sname.

That said, in my tests, the $_nd_lldp_system_name variable does not contain the string "System Name:".  I wouldn't expect it to, either.  While you might see this in "show lldp nei" it wouldn't make sense to show up here.

So I would just forgo action 2.4 and use $_nd_lldp_system_name as-is.

Yeah thanks, I will do that and just use $_nd_lldp_system_name as-is.

 

I am still confused as to why I get the error:

%HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: _nd_lldp_system_name

It would be helpful to see the whole applet. 

An LLDP event should always expose this variable, but perhaps there is some race condition where it is not being set.

Hi Joe

 

Its a long script, it is also configuring the corresponding port on the second member of the stack as well as the associated port channel.

There are probably better and easier ways of doing this but this is what I have come up with.

 

event manager applet auto-update-lldp-port-description authorization bypass
 event neighbor-discovery interface regexp .*Ethernet.*$ lldp add
 action 1.1     comment "If No AP connected then EXIT"
 action 1.2     regexp "(ArubaOS)" "$_nd_lldp_system_description"
 action 1.3     if $_regexp_result eq "0"
 action 1.4      exit 10
 action 1.5     end
 action 2.0     comment "Check which interface has an AP connected to auto update description on"
 action 2.1     regexp "(ArubaOS)" "$_nd_lldp_system_description"
 action 2.2     comment "If AP is connected get interface details
 action 2.3     if $_regexp_result eq "1"
 action 2.4      regexp "^(.*)" "$_nd_lldp_system_name" match System Name:
 action 2.5      set APname "$System"
 action 3.0      comment "Get remote Port name"
 action 3.1      set Remoteport "$_nd_lldp_port_description"
 action 4.0      comment "Check existing description, if any, and skip if descriptions are the same"
 action 4.02     cli command "enable"
 action 4.04     cli command "config t"
 action 4.06     cli command "do show interface $_nd_local_intf_name"
 action 4.07     syslog msg "Interface Name: $_nd_local_intf_name"
 action 4.1      set olddesc "<none>"
 action 4.1.2    regexp "Description: ([a-zA-Z0-9:/\-\ \.]*)" "$_cli_result" olddesc
 action 4.1.4    syslog msg "Existing Description: $olddesc"
 action 4.2      comment "Find Switch and Port Numbers"
 action 4.2.1    regexp "([^GigabitEthernet])" "$_nd_local_intf_name" SwitchNumber
 action 4.2.2    syslog msg "Switch Number: $SwitchNumber"
 action 4.2.3    regexp "([0-9]+$)" "$_nd_local_intf_name" PortNumber
 action 4.2.4    syslog msg "Port Number: $PortNumber"
 action 4.3      set Remoteport "$_nd_lldp_port_description"
 action 4.3.2    syslog msg "Remote Port: $Remoteport"
 action 4.3.3   end
 action 4.9     set NewDescription "Description: $APname:$Remoteport"
 action 4.9.1   syslog msg "OldDescript: $olddesc"
 action 4.9.2   syslog msg "NewDescript: $NewDescription"
 action 4.9.3   if $olddesc eq "$NewDescription"
 action 4.9.4    syslog msg "EEM script did NOT change desciption on $_nd_local_intf_name, since remote host and interface is unchanged"
 action 4.9.6   else
 action 4.9.7    comment "Apply description to interface"
 action 4.9.8    cli command "interface $_nd_local_intf_name"
 action 4.9.9    cli command "description $APname:$Remoteport"
 action 4.9.9.1 end
 action 5.0     comment Set description on Port Channel
 action 5.1     cli command "do show interface Port-channel$PortNumber"
 action 5.1.1   set PortChannelDescription "<none>"
 action 5.1.2   regexp "Description: ([a-zA-Z0-9:/\-\ \.]*)" "$_cli_result" PortChannelDescription
 action 5.1.4   if $PortChannelDescription eq "Description: $APname"
 action 5.5      syslog msg "EEM script did NOT change desciption on Port-channel$PortNumber, remote host unchanged"
 action 5.6     else
 action 5.7.1    cli command "interface Port-channel$PortNumber"
 action 5.7.3    cli command "description $APname"
 action 5.9.1   end
 action 6.0     comment "Get interface details to configure description on second port"
 action 6.1     comment "Action if Switch Number = 1 and remote port = eth0"
 action 6.1.1   if $SwitchNumber eq "1"
 action 6.1.3    comment "Switch number = 1"
 action 6.1.5    if $Remoteport eq "eth0"
 action 6.1.6     set 2ndPort "<none>"
 action 6.1.6.1   cli command "do show interface GigabitEthernet2/0/$PortNumber"
 action 6.1.6.2   regexp "Description: ([a-zA-Z0-9:/\-\ \.]*)" "$_cli_result" 2ndPort
 action 6.1.6.3   syslog msg "2ndPort: $2ndPort"
 action 6.1.6.4   if $2ndPort eq "Description: $APname:eth1"
 action 6.1.6.5    syslog msg "EEM script did NOT change desciption on GigabitEthernet2/0/$PortNumber, remote host unchanged"
 action 6.1.6.6    exit 1
 action 6.1.6.7   else
 action 6.1.7.1    cli command "interface GigabitEthernet2/0/$PortNumber"
 action 6.1.7.2    cli command "description $APname:eth1"
 action 6.1.7.3    exit 1
 action 6.1.9.2    comment "We are skipping as Switch Number is not 1 and Remote Port is not eth0"
 action 6.1.9.3   end
 action 6.1.9.4  end
 action 6.1.9.5 end
 action 6.2     comment "Action if Switch Number = 1 and remote port = eth1"
 action 6.2.1   if $SwitchNumber eq "1"
 action 6.2.3    comment "Switch number = 1"
 action 6.2.5    if $Remoteport eq "eth1"
 action 6.2.6     set 2ndPort "<none>"
 action 6.2.6.1   cli command "do show interface GigabitEthernet2/0/$PortNumber"
 action 6.2.6.2   regexp "Description: ([a-zA-Z0-9:/\-\ \.]*)" "$_cli_result" 2ndPort
 action 6.2.6.3   syslog msg "2ndPort: $2ndPort"
 action 6.2.6.4   if $2ndPort eq "Description: $APname:eth0"
 action 6.2.6.5    syslog msg "EEM script did NOT change desciption on GigabitEthernet2/0/$PortNumber, remote host unchanged"
 action 6.2.6.6    exit 1
 action 6.2.6.7   else
 action 6.2.7.1    cli command "interface GigabitEthernet2/0/$PortNumber"
 action 6.2.7.2    cli command "description $APname:eth0"
 action 6.2.7.3    exit 1
 action 6.2.9.2    comment "We are skipping as Switch Number is not 1 and Remote Port is not eth1"
 action 6.2.9.3   end
 action 6.2.9.4  end
 action 6.2.9.5 end
 action 6.3     comment "Action if Switch Number = 2 and remote port = eth0"
 action 6.3.1   if $SwitchNumber eq "2"
 action 6.3.3    comment "Switch number = 2"
 action 6.3.5    if $Remoteport eq "eth0"
 action 6.3.6     set 2ndPort "<none>"
 action 6.3.6.1   cli command "do show interface GigabitEthernet1/0/$PortNumber"
 action 6.3.6.2   regexp "Description: ([a-zA-Z0-9:/\-\ \.]*)" "$_cli_result" 2ndPort
 action 6.3.6.3   syslog msg "2ndPort: $2ndPort"
 action 6.3.6.4   if $2ndPort eq "Description: $APname:eth1"
 action 6.3.6.5    syslog msg "EEM script did NOT change desciption on GigabitEthernet1/0/$PortNumber, remote host unchanged"
 action 6.3.6.6    exit 1
 action 6.3.6.7   else
 action 6.3.7.1    cli command "interface GigabitEthernet1/0/$PortNumber"
 action 6.3.7.2    cli command "description $APname:eth1"
 action 6.3.7.3    exit 1
 action 6.3.9.2    comment "We are skipping as Switch Number in not 1 and Remote Port is not eth0"
 action 6.3.9.3   end
 action 6.3.9.4  end
 action 6.3.9.5 end
 action 6.4     if $SwitchNumber eq "2"
 action 6.4.1    comment "Action if Switch Number = 2 and remote port = eth1"
 action 6.4.3    syslog msg "Switch number = 2"
 action 6.4.5    if $Remoteport eq "eth1"
 action 6.4.6     cli command "do show interface GigabitEthernet1/0/$PortNumber"
 action 6.4.6.1   set 2ndPort "<none>"
 action 6.4.6.2   regexp "Description: ([a-zA-Z0-9:/\-\ \.]*)" "$_cli_result" 2ndPort
 action 6.4.6.3   syslog msg "2ndPort: $2ndPort"
 action 6.4.6.4   if $2ndPort eq "Description: $APname:eth0"
 action 6.4.6.5    syslog msg "EEM script did NOT change desciption on GigabitEthernet1/0/$PortNumber, remote host unchanged"
 action 6.4.6.6    exit 1
 action 6.4.6.7   else
 action 6.4.7.1    cli command "interface GigabitEthernet1/0/$PortNumber"
 action 6.4.7.2    cli command "description $APname:eth0"
 action 6.4.7.3    exit 1
 action 6.4.9.2    syslog msg "We are skipping as Switch Number in not 1 and Remote Port is not eth1"
 action 6.4.9.3   end
 action 6.4.9.4  end
 action 6.4.9.5 end
 action 8.0     exit 1

It looks like you have not changed action 2.4 yet.  But I don't see why _nd_lldp_system_name would not be set (especially when _nd_lldp_system_description is).  But action 2.4 is invalid anyway, so I'd change that and see if the behavior persists.