- API script to create metric alert rules on all projects for quota management.
- When defined critical and warning thresholds are met, alerts will send email notifications to all teams assigned to that project.
To setup the python env for this script:
- Create env -
python3 -m venv env
- Activate venv -
source env/bin/activate
- Install requirements -
pip install -r ./requirements.txt
Prior to running create_alerts.py, you can configure the following fields in the config.properties file:
-
ORG_NAME= <org name>
- This should be assigned to your Organization Slug, found underSettings
-->General Settings
. -
AUTH_KEY= <auth_key>
- Your org level auth key can be found underSettings
-->Developer Settings
-->Internal Integrations
.a. If you don't have Internal Integrations set up, select
New Internal Integrations
and provide a Name for your integration.b. The
Project
andOrganization
permissions should be set to Read & Write.c. Once the above fields have been configured, click on Save Changes.
d. This should redirect you to your Internal Integrations page with a token. This token is your org level auth key.
-
CRITICAL=10000
- Critical threshold is set in the config file. No need to modify this value. -
WARNING=8000
- Warning threshold is set in the config file. No need to modify this value. -
ALERT_RULE_SUFFIX=_quota_limit
- If you would like to rename the alert rule suffix, this can be done in the config file.
-
Create Alerts for All Projects
python3 create_alerts.py
- To confirm via UI navigate to the Alerts page to view the created alerts.
- By running python3 create_alerts.py a second time you can confirm if the alert already exists. (Check the log file for
"alert already exists for + [project name]!"
)
After running the script you will see a log file created with the following naming convention - alert_logfile_{current_datetime}.log
Potential error and info logs will be displayed here.
To successfully create a metric alert make sure each project has at least one team assigned to it!