This repository contains a Python script that automates Azure cost reporting by fetching cost usage data from the Azure Management API and sending a daily cost report via email.
Before running the script, ensure you have the following prerequisites:
- Python 3.x installed on your system.
- An Azure subscription with the necessary permissions to access the Cost Management API.
- Azure AD credentials:
subscription_id
,tenant_id
,client_id
, andclient_secret
.
- Clone this repository to your local machine using
git clone
. - Navigate to the repository's directory.
- Open the Python script
azure_cost_report.py
in a text editor. - Replace the placeholder values for
subscription_id
,tenant_id
,client_id
, andclient_secret
with your Azure AD credentials.subscription_id = 'YOUR_SUBSCRIPTION_ID' tenant_id = 'YOUR_TENANT_ID' client_id = 'YOUR_CLIENT_ID' client_secret = 'YOUR_CLIENT_SECRET'
- Modify the
email_recipients
variable with the email addresses of the recipients you want to send the cost report to.python
email_recipients = ['recipient1@example.com', 'recipient2@example.com']
- Run the script using
python azure_cost_report.py
. - The script will fetch the cost data and send the cost report via email to the specified recipients.
The script allows you to configure the following parameters:
subscription_id
: Your Azure subscription ID.tenant_id
: Your Azure AD tenant ID.client_id
: Your Azure AD application/client ID.client_secret
: Your Azure AD application/client secret.monthly_budget
: The monthly budget amount in your local currency (e.g., INR).email_sender
: The email address from which the cost report will be sent.email_password
: The password for the email sender account.email_smtp_server
: The SMTP server address for the sender email account.email_smtp_port
: The SMTP port number for the sender email account.email_recipients
: A list of email addresses to which the cost report will be sent.