cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
692
Views
1
Helpful
4
Replies

EEM Could Not Find Environment Variable - Using $_cli_result

Hello all. I have been bashing my head on the desk all day trying to solve this issue. I feel like im just an inch away from figuring it out but I keep getting the same error which is stopping me dead in my EEM test I'm trying to do. What I am trying to do is capture the OUI of a device connected to an interface and compare it with a known value, if it matches it will do something. Below is the configuration on my test EEM as well as the error message I am getting when I run the applet. If you would happen to know what I am missing I would appreciate it greatly! Please let me know if you would like any additional information. I have been scouring the forums and other sources looking for answers and have adjusted the regex a few times.

** CONFIG **

event manager applet TEST
event none
action 0.0 cli command "enable"
action 1.0 cli command "show mac add int g1/0/3"
action 1.1 regexp "(a-f0-9){4}(\.)(a-f0-9){2}" "$_cli_result" mac_address
action 1.2 if $mac_address eq "7c57.58"
action 1.3 syslog msg "Found $mac_address - Proceeding with configuration"
action 1.4 end

 

** ERROR WHEN RUNNING APPLET **

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

4 Replies 4

Been a while since I’ve done any EEM.

The error message "%HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: mac_address" means that the EEM applet is trying to use an environment variable called mac_address, but that environment variable does not exist. This is because the regexp action in the applet is trying to extract the MAC address from the output of the show mac add int g1/0/3 command, but it is not storing the output of the command in an environment variable.

To fix this error, you need to add an action to the applet to store the output of the show mac add int g1/0/3 command in an environment variable. The following action will do this:

action 1.0 cli command "show mac add int g1/0/3" store output into $_cli_result

This will store the output of the show mac add int g1/0/3 command in an environment variable called $_cli_result. The regexp action can then use this environment variable to extract the MAC address.

The updated EEM applet would look like

event manager applet TEST
event none
action 0.0 cli command "enable"
action 1.0 cli command "show mac add int g1/0/3" store output into $_cli_result
action 1.1 regexp "(a-f0-9){4}(\.)(a-f0-9){2}" "$_cli_result" mac_address
action 1.2 if $mac_address eq "7c57.58"
action 1.3 syslog msg "Found $mac_address - Proceeding with configuration"
action 1.4 end

Once you have updated the applet, It should work. LMK

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Thank you for helping with this beard! I did try to modify my applet, but it is giving me invalid input at store. Looks like it is expecting "pattern" or enter. This is being setup on a WS-C3560CX-12PC-S Version: 15.2(7)E7.

So after playing with it a little longer and doing a few more tests. I can say it is for some reason not liking my regex syntax and is not finding the match it is expecting. So below are the tests im doing.

MAC Being used: 0050.db01.0203

When using 

action 1.3 regexp "(0-9a-f){4}(\.)(0-9a-f){2}" "$_cli_result" mac_address

action 1.4 syslog msg "$mac_address is the matched MAC Address"

Result: getting reported error

 

However when I use specific parts of the MAC (in todays case "0050.db") with the below regex:

action 1.3 regexp "0050" "$_cli_result" mac_address

action 1.4 syslog msg "$mac_address is the matched MAC Address"

Result: %HA_EM-6-LOG: TEST: 0050 is the matched MAC Address

 

 

If anyone might be able to identify what is incorrect in the regex it would be appreciated. I will also keep this updated if I happen to find a fix for other learners sake.

Additional Info:
It seems like the regex is not finding matches with the {4} expression. Tests and Results below:

Test 1: Without {4}

action 1.3 regexp "(.*)" $_cli_result mac_address

Result:

Aug 9 13:19:39.809 EDT: %HA_EM-6-LOG: TEST: Mac Address Table
-------------------------------------------

Vlan Mac Address Type Ports
---- ----------- -------- -----
10 0050.db01.0203 DYNAMIC Gi0/3
Total Mac Addresses for this criterion: 1
C3560X-13-101# is the matched MAC Address

 

Test 2: With (00.*)

action 1.3 regexp "(00.*)" $_cli_result mac_address

Result: 

Aug 9 13:20:14.032 EDT: %HA_EM-6-LOG: TEST: 0050.db01.0203 DYNAMIC Gi0/3
Total Mac Addresses for this criterion: 1
C3560X-13-101# is the matched MAC Address

Test 3: With {4}

action 1.3 regexp "(00.*){4}" $_cli_result mac_address

Result:
Aug 9 13:20:50.766 EDT: %HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: mac_address