- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 05:16 AM - edited 06-20-2023 05:17 AM
Payload:
{"receiver":"","status":"firing","alerts":[{"status":"firing","labels":{"alertname":"TestAlert","instance":"Grafana"},"annotations":{"summary":"Notification test"},"startsAt":"2023-06-20T10:19:31.207102004Z","endsAt":"0001-01-01T00:00:00Z","generatorURL":"","fingerprint":" ","silenceURL":"httpence/new?alertmanager=grafana\u0026matcher=alertname%3DTestAlert\u0026matcher=instance%3DGrafana","dashboardURL":"","panelURL":"","values":null,"valueString":"[ metric='foo' labels={instance=bar} value=10 ]"}],"groupLabels":{},"commonLabels":{"alertname":"TestAlert","instance":"Grafana"},"commonAnnotations":{"summary":"Notification test"},"externalURL":"https://sao/","version":"1","groupKey":"{alertname=\"TestAlert\", instance=\"Grafana\"}2023-06-20 10:19:31.207102004 +0000 UTC m=+6508.07","truncatedAlerts":0,"orgId":1,"title":"[FIRING:1] (TestAlert Grafana)","state":"alerting","message":"**Firing**\n\nValue: [no value]\nLabels:\n - alertname = TestAlert\n - instance = Grafana\nAnnotations:\n - summary = Notification test\nSilence: h?alertmanager=grafana\u0026matcher=alertname%3DTestAlert\u0026matcher=instance%3DGrafana\n"}
Issue to parse the values using scripted rest resource from above payload
script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 06:08 AM
Hi @Vamshi_ch123 ,
you can replace the below code. we need to get the values like below and use.
var reqbody = request.body.dataString;
var parser = new global.JSON();
var parsedData = JSON.parse(reqbody);
gs.info("Grafana : REQ " + reqbody);
var Source = parsedData.commonLabels.instance;
var Node = parsedData.state;
var Description = parsedData.alerts[0].annotations.summary;//not sure which summary you need but you can the summary of commonAnnotations also
var Additional_Info = parsedData.commonLabels.alertname;
var Source_Instance = parsedData.alerts[0].annotations.summary;
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 06:08 AM
Hi @Vamshi_ch123 ,
you can replace the below code. we need to get the values like below and use.
var reqbody = request.body.dataString;
var parser = new global.JSON();
var parsedData = JSON.parse(reqbody);
gs.info("Grafana : REQ " + reqbody);
var Source = parsedData.commonLabels.instance;
var Node = parsedData.state;
var Description = parsedData.alerts[0].annotations.summary;//not sure which summary you need but you can the summary of commonAnnotations also
var Additional_Info = parsedData.commonLabels.alertname;
var Source_Instance = parsedData.alerts[0].annotations.summary;
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2023 09:03 AM - edited 06-22-2023 09:07 AM
from the payload can we update the URL to the string field?
{
"receiver":"Servicenow DEV",
"status":"firing",
"alerts":[
{
"status":"resolved",
"labels":{
"Customer":"SS",
"Customer_Code":"XX",
"EventType":"Application",
"Severity":"Critical",
"alertname":"Response Time (90pct)",
"grafana_folder":"XP -S"
},
"annotations":{
"grafana_state_reason":"Updated"
},
"silenceURL":"https://sae/new?alertmanager=grafana\u0026matcication\u0026matatcher=alertname%3DApplicatio890pct%29\u0026matcher=",
"dashboardURL":"https://saro/d/JDyyBMQ4z?orgId=1",
"panelURL":"https://orgId=1\u0026viewPanel=44",
"values":null,"valueString":"[ var='B' labels={} value=null ], [ var='C' labels={} value=null ]"
},
From the payload I was trying to update the dashboard URL to the description but it is showing undefined
var Description = parsedData.alerts[0].annotations.dashboardURL;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2023 10:44 PM
Hi @Vamshi_ch123 ,
use as below
var Description = parsedData.alerts[0].dashboardURL;
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 04:23 AM