Data collector for Azure
- Data collector for Azure
- Synchronize a set of Microsoft Azure CIs into iTop
- PHP 7.4
This collector enables administrators to automatically feed iTop with relevant and accurate Azure cloud computing information. It relies on the Azure modelization that the Data model for Microsoft Azure extension is bringing to iTop CMDB.
The Data collector for Azure is a stand-alone PHP software that connects to Azure, retrieves objects from a set of subscriptions, all belonging to a given Tenant, and synchronize them with iTop's CMDB.
Connection to Azure is made through Azure OAUTH2 authentication,
Retrieval of objects relies on Azure REST API that extracts data in JSON format,
Selection of Subscriptions to consider is made in iTop,
Synchronization follows iTop's built-in Data Synchronization mechanism.
The Data collector for Azure relies on the Data model for Microsoft Azure extension where Azure objects are modelized for iTop. The number of object types being significant within Azure cloud computing, the extension only focuses on a subset of these objects:
Collection of resources that belong to a given subscription can be enabled or disabled on a per subscription basis
Azure DB Server
MS SQL Database
Azure Load Balancer
Data collection can be enhanced by adding further Azure classes to this list. Please, refer to the “how to” chapter below.
The collector is only synchronizing a limited subset of Azure objects (see above).
Collection of IP resources (addresses, subnets…) is not done in this current version.
Usage of the collector requires you to comply with a few points:
The Azure objects synchronized by the collector must exist in iTop as CMDB CIs. This can be done with the Data model for Microsoft Azure extension that precisely enhanced iTop CMDB with Azure objects.
In order to browse Azure computing environment, you'll need an Azure account (see service principal) that allows you to read Azure resources.
From a system standpoint, you'll need to comply with the requirements expressed in the Data collector Base documentation.
Just expand the content of the zip archive in a folder on the machine were the collector will run.
Like every iTop collector, the configuration of the application is built by concatenating 3 files:
collectors/params.disctrib.xml that holds the entries that are specific to the Data collector for Azure. It should not be modified.
conf/params.distrib.xml that is provided by the collector framework, Data collector Base. It should not be modified.
conf/params.local.xml where the collector can be adapted to the specific customer needs.
The first configuration file holds parameters that must (for some) or can (for others) be changed when configuring the collector, through the 3rd file, conf/params.local.xml.
<?xml version="1.0" encoding="UTF-8"?><!-- Default values for parameters. Do NOT alter this file, use params.local.xml instead --> <parameters> <!-- *** Connection parameters *** --> <!-- iTop Parameters --> <itop_url>http://myitop.com</itop_url> <itop_login>admin</itop_login> <itop_password>admin</itop_password> <!-- Microsoft links --> <microsoft_login_url>https://login.microsoftonline.com/</microsoft_login_url> <microsoft_auth_mode>/oauth2/token</microsoft_auth_mode> <microsoft_resource>https://management.azure.com/</microsoft_resource> <!-- Client's credentials --> <ms_clientid></ms_clientid> <ms_clientsecret></ms_clientsecret> <ms_tenantid></ms_tenantid> <!-- *** Azure Class Parameters *** --> <!-- App Services --> ... List of Azure classes to collect ... <!-- *** Synchro data source parameters *** --> <contact_to_notify></contact_to_notify> <synchro_user>admin</synchro_user> <json_placeholders> <!-- For compatibility with the version 1.1.x of the collector, define the data table names as following: <prefix></prefix> <persons_data_table>synchro_data_PersonAD</persons_data_table> <users_data_table></users_data_table> --> <ms_tenantid_short></ms_tenantid_short> <azureappservice_synchro_name>Azure App Services Discovery</azureappservice_synchro_name> ... Placeholders for other classes ... <synchro_status>production</synchro_status> <full_load_interval>604800</full_load_interval><!-- 7 days (in seconds): 7*24*60*60 --> </json_placeholders> <!-- *** Mapping tables *** --> <subscription_status_mapping type="array"> <pattern>/Deleted/obsolete</pattern> <pattern>/Disabled/implementation</pattern> <pattern>/Enabled/production</pattern> <pattern>/PastDue/obsolete</pattern> <pattern>/Warned/implementation</pattern> </subscription_status_mapping> <disk_encryption_mapping type="array"> <pattern>/true/enabled</pattern> <pattern>/false/disabled</pattern> <pattern>/.*/disabled</pattern> </disk_encryption_mapping> </parameters>
Some of these parameters must (bold) or may (italic) be adjusted to meet customers' own environment.
This set of parameters is required to connect to iTop application or to Microsoft Azure environment.
|itop_url||URL to the iTop Application.||https://localhost/myitop|
|itop_login||Login (user account) for connecting to iTop. Must have admin rights with rest profile for executing the data synchro.||admin|
|itop_password||Password for the iTop account.||admin_pwd|
|microsoft_login_url||URL to be used by the collector to log into Azure and start the authentication process||https://login.microsoftonline.com/|
|microsoft_auth_mode||Secifies the authentication process - OAUTH2 for the Azure collector||/oauth2/token|
|microsoft_resource||URL to the Azure REST API||https://management.azure.com/|
|ms_tenantid||Tenant ID is the unique identifier of your Azure Active Directory instance. A Tenant ID allow you to register and manage your apps.||2d74zb091-b7fe-4e14-868b-4e9a3f887a60|
|ms_clientid||Client ID is the unique identifier of your application created in Azure Active Directory.||7ed0fdef-abcd-4fd0-8364-da5fde498765|
|ms_clientsecret||Secret key associated to the Client ID||fJ4eQ~rG75DPd4aadrBodZvKxFtxOhnX2XrO|
Synchro data source parameters
These are dedicated to the synchronization data sources that the collector create.
|contact_to_notify||The email address of an existing contact in TeemIp to be notified of the results of the email@example.com|
|synchro_user||If the user account used for running this synchronization is not an Administrator, then its login must be specified here, since iTop allows only the administrators and the specified user to run the synchronization.|
|<Azure_Class>_synchro_name||Name of the synchro data source for the given Azure Class||Azure App Services Discovery|
|ms_tenantid_short||Sub string of the Tenant ID that allows you to
differentiate different synchro data sources working on different
Tenants (1 collector should be used per Tenant - see above).
That string is appended to the name of the synchro data source, in iTop.
|full_load_interval||The delay (expressed in seconds) between two complete imports of the data. The objects which have not been detected by the collector during a timespan longer than this interval will be considered as obsolete and marked as such in iTop. Adjust this value depending on the scheduling recurrence.||604800|
This section groups the mapping tables used by the collector.
|subscription_status_mapping||Mapping table for subscription status|
|disk_encryption_mapping||Mapping table for disc encryption status|
Azure Class Parameters
Next to the core parameters described here above, the collectors/params.disctrib.xml file provides the list of all Azure classes that need to be discovered together with their subset of parameters that should be synchronized within iTop. Since the retrieval of Azure data is made in JSON format, this list must be aligned with the requirements expected by the standard JSON collector defined in the data collector base.
Looking, for instance, at the App Service class, we have:
<azureappserviceazurecollector> <enable>no</enable> <ms_class>Site</ms_class> <api_version>2021-02-01</api_version> <jsonfile>data/AzureAppServices.json</jsonfile> <path>value</path> <fields> <primary_key>id</primary_key> <app_service_plan>app_service_plan</app_service_plan> <azureid>id</azureid> <azureresourcegroup_id>azureresourcegroup_id</azureresourcegroup_id> <azuresubscription_id>azuresubscription_id</azuresubscription_id> <business_criticity>business_criticity</business_criticity> <ftps_hostname>ftps_hostname</ftps_hostname> <location_id>location</location_id> <name>name</name> <org_id>org_id</org_id> <provisioning_status>provisioning_status</provisioning_status> <status>state</status> <url>url</url> </fields> <defaults> <app_service_plan></app_service_plan> <azureresourcegroup_id></azureresourcegroup_id> <azuresubscription_id></azuresubscription_id> <business_criticity>medium</business_criticity> <ftps_hostname></ftps_hostname> <org_id>Demo</org_id> <provisioning_status>ready</provisioning_status> <status>implementation</status> <url></url> </defaults> </azureappserviceazurecollector>
|enable||Enable the discovery of the class||yes / no|
|ms_class||Name of the Azure class||AppService|
|api_version||Version of the Microsoft REST API used to retrieve class data||2021-02-01|
|jsonfile||Define the relative path to the JSON file where Azure data have been extracted||data/AzureAppServices.json|
|path||Path to find the data to synchronize in JSON file||value|
|fields||List of objects' fields to be considered by the synchro engine||See above|
|defaults||List of default values to be used, if required||See above|
On iTop side
Next to the configuration of the collector itself, actions are required on iTop, at the subscription's level, to fully enable the discovery of Azure objects:
Once subscriptions are discovered and documented in iTop, their “Discover objects” attributes is set to 'no' by default,
In order to enable their discovery by the collector, this parameter needs to be switched to 'yes'.
Launch of the Azure collector will be driven by the command and parameters defined in the usage section of iTop Data collector base. Once launched, first action of the collector will be to define its collection plan, based on the list of classes that have been enabled in the configuration file .
The very first time that the collector is running, it will focus on the Subscriptions, if these have been enabled (if not, no collection will be made). Only the subscriptions that belong to the Tenant defined in the configuration file will be discovered. Should you need to collect subscriptions belonging to different Tenants, then dedicated collectors will need to be deployed for each of these Tenants.
Once subscriptions have been discovered and synchronized in iTop, CMDB manager will need to decide whether these subscriptions will have to be further discovered or not. Refer to the previous chapter for details on that step.
At this stage, Azure data collector can be launched again in order to collect all classes that the configuration has enabled. Once again, collector will start by building its collection plan and once done:
Configuration files will be consolidated,
Synchronisation data sources will be created or updated if required,
Authentication to Azure environment will be made (see below),
Collection of Azure classes will be made by invoking Azure REST API and extracted data will be stored under the local “data” directory, in JSON format,
Synchronisation will run and Azure objects will be pushed to iTop.
As a summary:
Discover and collect Azure subscriptions on the first collector run,
Connect to iTop and check the subscriptions that need to be scanned,
Launch the collector a second time to collect the Resource Groups contained in the subscriptions to be discovered,
Run the collector subsequently to collect and synchronize the objects that belong to the different Resource Groups.
Questions & Answers
Question: how does the authentication mechanism work
Answer: Azure requests OAUTH2 authentication to retrieve data through its REST API. It allows a user to grant limited access to its protected resources:
OAuth separates the role of the client from the resource owner.
The client requests access to the resources controlled by the resource owner and hosted by the resource server. The resource server issues access tokens with the approval of the resource owner. The client uses the access tokens to access the protected resources hosted by the resource server.
Within the Azure collector, the authentication status is checked before starting the collection of every Azure class of object. This is done by reading some parameters contained in the data/BearerToken.csv file. If the file does not exits or if it doesn't contain any Bearer Token or if the token has expired, the collector is considered as disconnected from Azure and a new authentication process needs to start. Otherwise, if parameters are fine, collection may proceed with the Bearer Token used as a parameter.
If a new authentication needs to be initiated:
Collector posts an authentication request toward Azure, providing the 3 configuration parameters ms_tenantid, ms_clientid and ms_clientsecret that have been defined for that purpose,
If authentication fails, error messages is logged and collection stops.
If authentication succeeds:
A Bearer Token associated to an expiration delay is provided by Azure,
These parameters are stored in the file data/BearerToken.csv.
Data collection for the given class proceeds.
Question: how can I add Azure classes to the collection
Answer: Other classes than the ones listed by default in the collector can be added to it. For that purpose:
Make sure the class (MyNewClass) has been modelized in iTop (Through the Data model for Microsoft Azure extension for instance).
Add a class entry in the collectors/params.distrib.xml file,
Add the <mynewclass_synchro_name> in the <json_placeholders> section of the file,
Create the MyNewClassAzureCollector.json file that describes the synchro data source of the new class,
Create the MyNewClassAzureCollector.class.inc.php file that contains the collector specificities for the class (REST API URL, dependency parameters…),
Register the class in the array $aCollectorClasses defined in the collectors/main.php.
And that's it
You may refer to what already exists for other classes as examples.
Question: how can I take advantage of Azure tags within
Answer: Tags, in Azure, are name/value pairs that enable you to categorize resources and view consolidated billing by applying the same tag to multiple resources and resource groups. They can be exported as raw values, without being altered by Azure API. When modelized as new attributes in iTop, they can be used to reconcile objects, link objects together or just add information to an object.
You may create tags in Azure as follows: