Cloud Managed Networks

last person joined: 2 days ago 

Forum to discuss all things related to HPE Aruba Networking Central and UXI Network Management, including deployment of managed networks, configuration, best practices, APIs, Cloud Guest, AIOps, Presence Analytics, and other included Applications
Expand all | Collapse all

Aruba Central API Gateway and how to create a CSV file using Python scripting

This thread has been viewed 12 times
  • 1.  Aruba Central API Gateway and how to create a CSV file using Python scripting

    EMPLOYEE
    Posted Oct 30, 2017 02:14 PM
      |   view attached

    In my opinion, one of the greatest Aruba Central differentiators is the ability to automate management tasks, monitoring actions, and advanced options to get infrastructure information throughout APIs.

     

    The main objective of this post is to share how to get access to API Gateway in Aruba Central and get information that APs collect that it is not shown in the Central dashboard. This information in some cases is key for our customers and, sometimes, Central cannot export in a report. In this post, for example, I will describe how to get the list of devices connected to an Aruba wireless network, in some time delta, for example 5 minutes. After that I will write how to convert this information from the JSON response body, that API Gateway shows, to a CSV file (Comma-Separated Values). CVS files can be opened by Microsoft Excel, or any spreadsheet program.

     

    If your customer has already access to API Gateway, at the customer ID level, and you know how to authenticate to API Gateway, please go to Step 5.

     

    Step 1: For our customers that have their networking infrastructure managed by Aruba Central, it is necessary to ask for “API Gateway” section enablement for the customer ID level. To complete this task, you could ask the Aruba SE assigned to the account to help you opening a TAC case. If your customer has MSP view, it is very important to send the “customer IDs”, at the customer level, that you want to get access to “API Gateway”, not the MSP level customer ID. Those ID are listed at “All customers” table. Here an example:

     

    Central IDs clientes.png

     

     

    Step2: “API Gateway” link should be displayed under the “Maintenance” section, at the customer view level. 

     

     

     

    API Gateway menu.png

     

    Step 3: As stated in Aruba Central APIs v2.3 documentation, we have different options to communicate to the API Gateway. In this case, we will do it through the API Gateway public link.

    To get authenticated by API Gateway Web access, we must generate a token, valid for a couple of hours, by default. The way to generate it directly from our customer Aruba Central interface is clicking Maintenance -> API Gateway -> "+ Add Apps and Tokens". There, you have to give a name to this token, for example, “Prueba de API” and click on “Generate” button.

    After this, the generated token looks like this:

     

    Token generado.png

    Click on “View Token”, and "Download Token", as in the image:

    Download Token.png

     

     

    Here, the important text we must copy is the “access_token” value, without “”. This will help us to authenticate to the API Gateway.

     token real.png

     

    To read an updated version of the code of this post click here.

     

     

    Step 4:

    This copied text has to be pasted at the “Token” field in the API Gateway public link.

    Now we are authenticated and ready to get advance information from our infrastructure.

     

    Step 5:

    In this post, I am going to show you how to view the “connected devices”, in a range of time, and export that information a CSV file.

    Aruba Central API has the power to give us some information from the connected devices in our network, for a period of time. To get this information navigate to “Monitoring” -> “Client” -> “Top N Clients. “Top N Clients” is URL section that shares connected clients’ information, in a period of time. If you want to get detailed client information, for example, their wireless feature and some connectivity date, it is better to use “List Wireless Clients”.

     

    Top N Clients.png

     

    “Top N Clients” has a default time period that is 3 hours. If we want to get this date from a different period we have to modify the parameters "from_timestamp" and "to_timestamp" with the "epoch" in seconds. To do so, I recommend a free Web tool Epoch Converter.

     

    It is time to get some data by clicking at the "Try" button of this section.

     

    try.png

    Now, we have got a “GET response” view in a JSON format, that shows like that:

     

     

    get response TOP N CLients.png

     

    Step 6:

    It is time to translate this information to a friendlier format, for example, CSV file that can be opened by Microsoft Excel or any spreadsheet calculator similar software.

    To do so, I wrote a Python script (attached in the .ZIP file of this post), that basically allows to paste the “RESPONSE BODY” of the last screen. In this script, I used the csv Python library and the programming language native feature to manipulate the dictionary data structure got in last step.

     

    script english.png

     

     

     

    It is as easy as to paste the "RESPONSE BODY" without the first ‘{‘, and run the script, named “aruba_central_script_csv.py”.

     

    correr script.png

     

    This Python script is attached, along with the .CSV file processed file in the .ZIP file of this post. Feel free to modify it to run on your computer environment.

     

    If you have comments or questions, please let me know.

     

    I hope this is will help our customers to get different information that is shown from the Central interface, and I hope that this could help to extend, in some way, Aruba Central reporting features.

     

    Do not hesitate to argue competitors if they are lying our customers about Aruba Central features. It is confirmed, by one large customer of us, that another vendor that rhymes with “bare rocky” does not have such an ability to export this kind of data.

     

    Do not forget that this is only an example. Our API platform is really rich in some information that is not stored at Central, but Aruba allows our customers to freely process and store it in a way they can get benefits. 

     

    If you want to read the Spanish version of this post, please, click here.

     

    To read an updated version of the code of this post click here

     

    Please, do not forget to give some kudos!

     

    Esteban Tayo.

    Systems Engineer - Aruba Mexico

    Attachment(s)



  • 2.  RE: Aruba Central API Gateway and how to create a CSV file using Python scripting

    EMPLOYEE
    Posted Nov 01, 2017 01:40 PM
      |   view attached

    Hi Tayo.

    Making some improvement, just update the access_token in the script. Other option is to take the client_id, client_secret and the refresh_token to update the access_token.

     

    I attached some images that describe the procedure and the output.

     

    Regards.

     

    Aruba_Central_Script.pngcsv_file.png

    Attachment(s)



  • 3.  RE: Aruba Central API Gateway and how to create a CSV file using Python scripting

    EMPLOYEE
    Posted Nov 01, 2017 07:43 PM

    Thanks! Looks really great!



  • 4.  RE: Aruba Central API Gateway and how to create a CSV file using Python scripting

    Posted Apr 16, 2019 11:09 AM