CMP - Discovering new Resource Types in Azure
Recently we published an article on discovering new resource types in AWS (link here :https://community.servicenow.com/community?id=community_article&sys_id=2cdb9d69db47734814d6fb2439961...) . This is the sibling article and deals with discovering new resource types in Azure.
All things applicable to that article are applicable here. Only change is that we need to refer to Azure APIs and documents in place of AWS.
Cloud Provider API can be got from Azure API like this https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/list.
We need the following for making a proper call.
- Location - the location where to discover from
- SubscriptionID - This can be sent via ${parameter.CloudServiceAccountId}
- pathDefault - the path to get to the resource like /subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Network
- resourceType - the resource type like Microsoft.Network/virtualNetworks
- versionDefault - the apiVersion of the API like 2016-03-30
If you have the above listed parameters, we can make any discovery call.
Sample Response
In this exercise we will discover and populate networks. We will set the name, object_id and state.
The above image shows the different important pieces that are needed for making a success list call for network.
Network CMDB Model:
Adding new Resource Type Discovery:
var metadata = {
"datasourceName": "Discover Azure Networks",// a unique name
"ciClass": "cmdb_ci_network", // comes from CMDB
"dependentOn" : "cmdb_ci_azure_datacenter", // dependent field used for identification. In this case we need to get the location.
"dependentOnSourceField" : "location",// response has a field called 'location'. we use it to map it to the datacenter.
"fields": [
{
"sourceField": "name",
"ciClassField": "name"
},
{
"isIdentification": true,
"sourceField": "id",
"ciClassField": "object_id"
},
{
"fixed_value": "available",
"attrMappingType" : "fixed",
"ciClassField": "state"
}
]
};
new sn_cmp.AzureDiscoveryStepCreator().addResourceTypeDiscovery(
'/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Network', // the path
'Microsoft.Network/virtualNetworks', // resource type
'2019-06-01', // versionDefault
'', // JSON Path if we are interested in a subset of data. In this case we want all.
metadata //mapping metadata
);
In the above sample, just the name, state and object_id are populated. More columns and CI relations can also be populated using the same mechanism.
The script include 'AzureDiscoveryStepCreator' is the script we will use to persist the mapping as well as create the discovery operation step to discover the resource type network. This script include has a method called 'addResourceTypeDiscovery'. This takes in the response mappings as well as the API information as described in the scriptlet above.
Run the above script in the background script and it will do the needful and you can discover from AWS via the cloud account or a service account.
To see if the data is properly set, you can do the following.
- Get to Cloud Admin Portal ==> Design ==> Resource Block ==> Azure Datacenter ==> Operations ==> Discovery Interface ==> Discover ==> Steps
- You will see the a set of steps. Look for the step which you created. The name would be 'Discover '+ $resourceType.
The Cloud API call with all pertinent information passed as parameters.
The response processing:
You woul see that the step has a association with a standard Azure Discover call and a GenericListProcessor for the response processing. All things are wired for you automatically.
That’s it. You are done. You can do a ‘Discover Now’ in the Cloud Account and your discovery will be running fine.
The same CAPI call can be used for discovering any Azure resource type. You can rinse and repeat for discovering other Azure resource types now.
The updateset for the Azure Discovery Common Cloud API is here :
https://www.servicenow.com/community/itom-articles/cmp-discovering-new-resource-types-in-azure/ta-p/2325250