Skip to content

Commit da17194

Browse files
waleedlatif1claude
andcommitted
fix(grafana): address PR review feedback
- Drop hardcoded orgID: 1 fallback; only send orgID when organizationId is provided, so token-scoped org context drives rule placement. - Surface invalid JSON for notificationSettings/record on alert rule create/update instead of silently dropping the input. - Fix execErrState description in update_alert_rule to include Error. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent de3caeb commit da17194

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

apps/sim/tools/grafana/create_alert_rule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ export const createAlertRuleTool: ToolConfig<
163163
}
164164

165165
const body: Record<string, unknown> = {
166-
orgID: params.organizationId ? Number(params.organizationId) : 1,
167166
title: params.title,
168167
folderUID: params.folderUid,
169168
ruleGroup: params.ruleGroup,
170169
data: dataArray,
171170
}
171+
if (params.organizationId) body.orgID = Number(params.organizationId)
172172

173173
if (params.condition) body.condition = params.condition
174174
if (params.uid) body.uid = params.uid
@@ -201,15 +201,15 @@ export const createAlertRuleTool: ToolConfig<
201201
try {
202202
body.notification_settings = JSON.parse(params.notificationSettings)
203203
} catch {
204-
// skip invalid notification settings JSON
204+
throw new Error('Invalid JSON for notificationSettings parameter')
205205
}
206206
}
207207

208208
if (params.record) {
209209
try {
210210
body.record = JSON.parse(params.record)
211211
} catch {
212-
// skip invalid record JSON
212+
throw new Error('Invalid JSON for record parameter')
213213
}
214214
}
215215

apps/sim/tools/grafana/update_alert_rule.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const updateAlertRuleTool: ToolConfig<GrafanaUpdateAlertRuleParams, ToolR
8080
type: 'string',
8181
required: false,
8282
visibility: 'user-only',
83-
description: 'State on execution error (Alerting, OK)',
83+
description: 'State on execution error (Error, Alerting, OK)',
8484
},
8585
annotations: {
8686
type: 'string',
@@ -195,15 +195,23 @@ export const updateAlertRuleTool: ToolConfig<GrafanaUpdateAlertRuleParams, ToolR
195195
try {
196196
updatedRule.notification_settings = JSON.parse(params.notificationSettings)
197197
} catch {
198-
// keep existing notification_settings if parse fails
198+
return {
199+
success: false,
200+
output: {},
201+
error: 'Invalid JSON for notificationSettings parameter',
202+
}
199203
}
200204
}
201205

202206
if (params.record) {
203207
try {
204208
updatedRule.record = JSON.parse(params.record)
205209
} catch {
206-
// keep existing record if parse fails
210+
return {
211+
success: false,
212+
output: {},
213+
error: 'Invalid JSON for record parameter',
214+
}
207215
}
208216
}
209217

0 commit comments

Comments
 (0)