Create an API Parser
This section introduces how to create an API Parser to extract key metrics from a Cisco ACI network.
- Select Logic Nodes from the Node Type list, select Cisco ACI from the second list and then select a specific node type.
- Define the functions to retrieve data from devices. This step contains three functions. Define these functions step by step:
No. | Function Name | Explanation |
1 | Declare Parameters | This function is to declare the parameters from user inputs at runtime. This function is in the JSON format, and a sample code is as follows: ''' The item name defined in this function refers to the name of the parameters (variables) that receives values from user input. |
2 | def BuildParameters (context, device_name, params) | This function declares the parameters from GDR, DeviceSetting, and SDN. It contains three fixed parameters:
This function also supports calling built-in APIs to get device or interface parameters:
The type of returned values by this function is tuple (bool, list). def BuildParameters(context, device_name, params): |
3 | def RetrieveData(devices) | This function is used to retrieve the data of devices based on the parameters declared in the Declare Parameters and BuildParameters functions. This function contains one parameter. The following is a sample code of this function: def RetrieveData(rtn_params): |
- Click Retrieve and select a device to retrieve sample data.
- Define the functions to parse key metrics from the retrieved data. This step contains two functions. Define these functions step by step:
No. | Function Name | Explanation |
1) | Declare variable tree | This function declares the metrics (variables) and the types you want to parse from the retrieved device data and generates a variable tree. The following parameters of a variable are defined:
This function is in the JSON format, and a sample code is as follows: ''' |
2) | def ParseText(original_result) | This function returns the specific metric values and assigns the values to corresponding variables in the variable tree. The following is a sample code of this function: import re |
- Click Save on the upper right corner of the page. The Parser will be saved in the Parser Library.
See also: