Skip to content

Commit 83409db

Browse files
committed
chore(hook): remove create contact_points
1 parent 4740c9a commit 83409db

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

charts/grafana/templates/grafana-configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ data:
1414
output stdout
1515
}
1616
}
17-
:5000 {
17+
:80 {
1818
handle /oauth2/* {
1919
reverse_proxy 127.0.0.1:4000
2020
}

rootfs/usr/share/grafana/oauth2/hook/grafana.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import time
23
import json
34
import httpx
45
from string import Template
@@ -83,25 +84,44 @@ async def sync_role(context: dict, token: dict, userinfo: dict):
8384

8485

8586
async def sync_default(context: dict, token: dict, userinfo: dict):
87+
alertmanager_default_config = json.dumps({
88+
"alertmanager_config": {
89+
"route": {
90+
"receiver": "grafana-default-email",
91+
"group_by": ["grafana_folder", "alertname"]
92+
},
93+
"receivers": [{
94+
"name": "grafana-default-email",
95+
"grafana_managed_receiver_configs": [{
96+
"uid": "",
97+
"name": "email receiver",
98+
"type": "email",
99+
"settings": {
100+
"addresses": f"{userinfo["email"]}"
101+
}
102+
}]
103+
}]
104+
}
105+
})
86106
async with httpx.AsyncClient() as client:
87107
await client.post(
88108
api_url("/api/folders"),
89109
headers=api_headers(context, userinfo),
90110
json={"uid": "drycc", "title": "drycc"},
91111
)
92-
await client.post(
93-
api_url("/api/v1/provisioning/contact-points"),
94-
headers=api_headers(context, userinfo),
95-
json={
96-
"uid": "grafana-default-email",
97-
"name": "grafana-default-email",
98-
"type": "email",
99-
"settings": {
100-
"addresses": f"{userinfo["email"]}"
101-
},
102-
"disableResolveMessage": False
103-
},
104-
)
112+
sql_tpl = f"""
113+
INSERT INTO alert_configuration (
114+
alertmanager_configuration, configuration_version, created_at, "default", org_id
115+
)
116+
VALUES (
117+
'{alertmanager_default_config}', 'v1', {int(time.time())}, TRUE, {context["org_id"]}
118+
)
119+
ON CONFLICT (org_id) DO NOTHING;
120+
"""
121+
async with await AsyncConnection.connect(os.environ.get("GF_DATABASE_URL")) as conn:
122+
async with conn.cursor() as cursor:
123+
await cursor.execute(sql_tpl)
124+
await conn.commit()
105125

106126

107127
async def sync_alerting(context: dict, token: dict, userinfo: dict):

0 commit comments

Comments
 (0)