【发布时间】:2021-05-26 20:16:19
【问题描述】:
我正在使用 JQ 调整 Grafana 仪表板。我这样做是为了可以将特定于环境的值更改为仪表板 json,然后获取修改后的 json 并将其部署到新环境中。
我想更改的一个值是 query 字段,它存储在表示 Grafana 变量的对象中。此对象的名称属性为“Environment”。我只关心这个对象,所有其他变量定义对象(附件示例仅包括一个)将保持不变。
我尝试过的 由于我需要搜索具有特定名称属性的对象,因此我正在使用 select。我使用 select 是因为我不相信有任何其他方式可以到达特定元素。
我试过这个查询
select(.templating.list[].name=="Environment").query="dev"
我正在寻找具有“环境”的“name”属性的变量定义。然后我想将其值更改为“dev”。
期望的输出
我希望返回整个 JSON 有效负载,并带有以下新查询值:dev
结果 我没有收到任何错误,但值也没有改变。
我不知道该怎么做。你能帮忙吗?
Json 跟随:
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": 5,
"iteration": 1622058997292,
"links": [],
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fieldConfig": {
"defaults": {},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 9,
"w": 12,
"x": 0,
"y": 0
},
"hiddenSeries": false,
"id": 2,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.5.4",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"alias": "",
"dimensions": {},
"expression": "",
"id": "",
"matchExact": true,
"metricName": "",
"namespace": "",
"period": "",
"refId": "A",
"region": "default",
"statistics": [
"Average"
]
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Panel Title",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"schemaVersion": 27,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"description": null,
"error": null,
"hide": 2,
"label": null,
"name": "Environment",
"query": "prod",
"skipUrlSync": false,
"type": "constant"
}
]
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "test",
"uid": "Op2N9sqGk",
"version": 1
}
【问题讨论】: