Python – Auto-Populate Tag Values in Ekahau Pro

Ekahau released a new version (v10.2) last month. The best feature out of this new version (for me at least) is the ability to create personalized tags for AP objects. Each tag can have a key and a value.

​Here is an example:

DESCRIPTION

My good friend Haydn Andrews had the idea to create a script that would auto populate the value of some tags based on the AP properties. This could be used for a lot of AP related properties if you think about it:

  • Installation details
  • Special bracket needed
  • Antenna related information (internet, external, model…)
  • PoE budget information
  • Service loop required

In our case we focused on the antenna(s). So we wanted to auto populate the value of three tags that we created:

  • antenna-type
  • antenna-vendor
  • antenna-name

antenna-type would be set to “internal” or “external” depending on the type of antenna used.
antenna-vendor would be set to the antenna vendor (for external antenna only).
antenna-name would be set to the model of antenna (for external antenna only).

The script will create a modified copy of your esx project and leave the original unchanged. However, we recommend running the script against a copy of the original esx project file.

This script will only works if you create the tags within your project before running the script. The easier to do this is to create the three tags on an AP that has external antennas. The three tags to create are: “antenna-name”, “antenna-type”, and “antenna-vendor”.

THE CODE

import argparse
import time
import os
import zipfile
import json
import pathlib
import shutil
from pprint import pprint
 
 
def main():
    parser = argparse.ArgumentParser(
        description='This scrip auto configure antenna tags based on AP properties')
    parser.add_argument('file', metavar='esx_file', help='Ekahau project file')
    args = parser.parse_args()
 
    current_filename = pathlib.PurePath(args.file).stem
    working_directory = os.getcwd()
 
    # Load & Unzip the Ekahau Project File
    with zipfile.ZipFile(args.file, 'r') as myzip:
        myzip.extractall(current_filename)
 
        # Load the accessPoints.json file into the accessPoints dictionary
        with myzip.open('accessPoints.json') as json_file:
            accessPoints = json.load(json_file)
 
        # Load the simulatedRadios.json file into the simulatedRadios dictionary
        with myzip.open('simulatedRadios.json') as json_file:
            simulatedRadios = json.load(json_file)
 
        # Load the antennaTypes.json file into the antennaTypes dictionary
        with myzip.open('antennaTypes.json') as json_file:
            antennaTypes = json.load(json_file)
 
        # Load the tagKeys.json file into the tagKeys dictionary
        with myzip.open('tagKeys.json') as json_file:
            tagKeys = json.load(json_file)
 
        # Retreive the ID corresponding to each antenna related tags
        for tag in tagKeys['tagKeys']:
            if tag['key'] == 'antenna-name':
                antenna_tag_id = tag['id']
            elif tag['key'] == 'antenna-type':
                antenna_type_tag_id = tag['id']
            elif tag['key'] == 'antenna-vendor':
                antenna_vendor_tag_id = tag['id']
 
        # Loop through the AP and auto populate the tag values based on the AP properties
        for ap in accessPoints['accessPoints']:
            for radio in simulatedRadios['simulatedRadios']:
                if ap['id'] == radio['accessPointId']:
                    for antenna in antennaTypes['antennaTypes']:
                        if radio['antennaTypeId'] == antenna['id']:
                            if antenna['frequencyBand'] == "FIVE":
                                if antenna['apCoupling'] == "EXTERNAL_ANTENNA":
                                    ext_antenna_name = antenna['name'].split(' ')[1]
                                    ext_antenna_vendor = antenna['name'].split(' ')[0]
                                    ap['tags'].append(
                                        {"tagKeyId": antenna_tag_id, "value": ext_antenna_name})
                                    print(
                                        f"{ap['name']}: 'antenna-name' tag set to '{ext_antenna_name}'")
                                    ap['tags'].append(
                                        {"tagKeyId": antenna_type_tag_id, "value": "External"})
                                    print(
                                        f"{ap['name']}: 'antenna-type' tag set to 'External'")
                                    ap['tags'].append(
                                        {"tagKeyId": antenna_vendor_tag_id, "value": ext_antenna_vendor})
                                    print(
                                        f"{ap['name']}: 'antenna-vendor' tag set to '{ext_antenna_vendor}'\n")
                                else:
                                    ap['tags'].append(
                                        {"tagKeyId": antenna_type_tag_id, "value": "Internal"})
                                    print(
                                        f"{ap['name']}: 'antenna-type' tag set to 'Internal'\n")
 
    # Write the changes into the accessPoints.json File
    with open(working_directory + '/' + current_filename + '/accessPoints.json', 'w') as file:
        json.dump(accessPoints, file, indent=4)
 
    # Create a new version of the Ekahau Project
    new_filename = current_filename + '_modified'
    shutil.make_archive(new_filename, 'zip', current_filename)
    shutil.move(new_filename + '.zip', new_filename + '.esx')
 
    # Cleaning Up
    shutil.rmtree(current_filename)
 
 
if __name__ == "__main__":
    start_time = time.time()
    print('** Creating Antenna Tags...\n')
    main()
    run_time = time.time() - start_time
    print("\n** Time to run: %s sec" % round(run_time, 2))

Feel free to modify it so you can use it with your own tags.

Note: we might update it in the future. So make sure to also check the GitHub repository to see the latest version available: https://github.com/francoisverges/semfio-ekahau

USAGE

As mentioned previously, the tags (key only) need to be created on the original project file on at least 1 AP object as shown below:

You can then create a copy of your project file (.esx file) and run the script against it:

A modified version of your project file will be created. When you open it, you should see the tags configured with the proper values on all access points:

The flexibility of creating our own tags opens a lot of opportunities for us. Feel free to take this and modify it to your needs.

LINKS & RESOURCES

Leave a Reply

Your email address will not be published. Required fields are marked *