Repository navigation
CLI application
Cloud-infra-visualization is a Python program that visualizes the resources in your Azure environment. It generates a JSON file containing all the resources and their properties, which can be further converted to an Excel or DrawIO file for easy visualization.
The program requires certain arguments to run:
-
--tenant_id: Your Azure tenant ID. -
--client_id: Your Azure client ID. -
--client_secretor--certificate_path: Your Azure client secret or the path to your certificate file. -
--use_device_codeor--interactive_login: If you want to log in interactively or use a device code. -
--subscription_id(optional): The ID of the subscription you want to visualize. If not provided, all subscriptions will be visualized. -
--resource_group(optional): The name of the resource group you want to visualize. If not provided, all resource groups will be visualized. -
--rgtag_keyand--rgtag_value(optional): Filter resource groups by this case-sensitive resource group Tag Key and Value. -
--rtag_keyand--rtag_value(optional): Filter resources by this case-sensitive resource Tag Key and Value. -
--output_xlsx(optional): Output to Excel. -
--output_folder(optional): The folder where the output files will be saved. If not provided, the files will be saved in the current directory. -
--output_drawio(optional): Output to XML for DrawIO. -
--output_docx(optional): Output to DOCX.
To run the program, use the following command:
python main.py --tenant_id YOUR_TENANT_ID --client_id YOUR_CLIENT_ID --client_secret YOUR_CLIENT_SECRETReplace YOUR_TENANT_ID, YOUR_CLIENT_ID, and YOUR_CLIENT_SECRET with your actual Azure tenant ID, client ID, and client secret.
If you want to output to Excel, add the --output_xlsx flag:
python main.py --tenant_id YOUR_TENANT_ID --client_id YOUR_CLIENT_ID --client_secret YOUR_CLIENT_SECRET --output_xlsxIf you want to output to DrawIO, add the --output_drawio flag:
python main.py --tenant_id YOUR_TENANT_ID --client_id YOUR_CLIENT_ID --client_secret YOUR_CLIENT_SECRET --output_drawioThe program outputs a JSON file named output.json containing all the resources and their properties. If the --output_xlsx flag is used, it also outputs an Excel file named output.xlsx. If the --output_drawio flag is used, it also outputs a DrawIO file named output.drawio.
The JSON file has the following structure:
-
Properties: Contains metadata about the script execution, such as the script version, the date and time when the script was run, and the duration of the script execution. -
Objects: Contains the resources. Each resource is represented as a dictionary with the following keys:-
ResourceType: The type of the resource. -
Details: A dictionary containing the properties of the resource.
-
The Excel file has one sheet for each resource type. Each sheet contains a table with the properties of the resources of that type.
The DrawIO file can be opened in DrawIO to visualize the resources.
This includes several relationships built in:
- VM to disk
- VM to network interface
- Database to server
- ...
The program uses resource handlers to process different types of resources. A resource handler is a function that takes a resource and returns a dictionary containing the properties of the resource. The program has built-in resource handlers for many Azure resource types, such as virtual machines, storage accounts, and SQL servers.
You can add your own resource handlers by modifying the get_resource_handlers function in main.py. Each resource handler should take three arguments: the resource, the resource group, and the client. It should return a dictionary containing the properties of the resource.
The program logs its progress to a file named CloudInfraViz.log. You can change the log level by using the --log_level argument when running the program. The available log levels are DEBUG, INFO, WARNING, ERROR, and CRITICAL.
The program requires several python packages since Microsoft does not have a metapackage.
You can install these packages using pip:
pip install -r requirements.txtThe program only visualizes resources that have a resource handler. If a resource does not have a resource handler defined, it will not be included in the output.