diff --git a/knowledge base/jq.md b/knowledge base/jq.md index 506dcd3..4cc005c 100644 --- a/knowledge base/jq.md +++ b/knowledge base/jq.md @@ -135,12 +135,15 @@ yq -e '(.backend.url|test("^file://")?)|not' 'Pulumi.yaml' ## Further readings +- [Website] +- [Codebase] - [JQ recipes] [jq recipes]: https://remysharp.com/drafts/jq-recipes ### Sources +- [Documentation] - [Filter objects list with regex] - [Select multiple conditions] - [Change multiple values at once] @@ -155,6 +158,11 @@ yq -e '(.backend.url|test("^file://")?)|not' 'Pulumi.yaml' ═╬═Time══ --> + +[codebase]: https://github.com/jqlang/jq +[documentation]: https://jqlang.org/manual/ +[website]: https://jqlang.org/ + [an introduction to jq]: https://earthly.dev/blog/jq-select/ [change multiple values at once]: https://stackoverflow.com/questions/47355901/jq-change-multiple-values#47357956 diff --git a/snippets/grafana.sh b/snippets/grafana.sh index 4e15f17..ef6e561 100644 --- a/snippets/grafana.sh +++ b/snippets/grafana.sh @@ -1,13 +1,34 @@ #!/usr/bin/env sh +# List dashboards +curl -sS 'http://grafana:3000/api/search' -H 'Authorization: Basic YWRtaW46YWRtaW4=' +curl -sS 'https://g-0123456789.grafana-workspace.eu-west-1.amazonaws.com/api/dashboards/uid/abcdefghijklmn' \ + -H 'Authorization: Bearer glsa_0123456789AbcdEfghIjklMnopQrstUv_0123abcd' + +# Get dashboards' json definition +curl -sS 'https://g-0123456789.grafana-workspace.eu-west-1.amazonaws.com/api/dashboards/uid/abcdefghijklmn' \ + -H 'Authorization: Bearer glsa_0123456789AbcdEfghIjklMnopQrstUv_0123abcd' + # Export all existing dashboards by ID -curl -sS \ - -H 'Authorization: Basic YWRtaW46YWRtaW4=' \ - 'http://grafana:3000/api/search' \ +curl -sS 'http://grafana:3000/api/search' -H 'Authorization: Basic YWRtaW46YWRtaW4=' \ | jq -r '.[].uid' - \ | parallel " \ - curl -sS \ - -H 'Authorization: Basic YWRtaW46YWRtaW4=' \ - 'http://grafana:3000/api/dashboards/uid/{}' \ + curl -sS 'http://grafana:3000/api/dashboards/uid/{}' -H 'Authorization: Basic YWRtaW46YWRtaW4=' \ > '{}.json' \ " + +# Get the UID of all dashboards using specific data sources +curl -Ss 'https://g-0123456789.grafana-workspace.eu-west-1.amazonaws.com/api/search' \ + -H 'Authorization: Bearer glsa_0123456789AbcdEfghIjklMnopQrstUv_0123abcd' \ +| jq -r '.[].uid' \ +| parallel " \ + curl -Ss 'https://g-0123456789.grafana-workspace.eu-west-1.amazonaws.com/api/dashboards/uid/{}' \ + -H 'Authorization: Bearer glsa_0123456789AbcdEfghIjklMnopQrstUv_0123abcd' \ +" \ +| jq -rs ' + .[].dashboard + | select( + (.panels[]? | if .datasource|type == "string" then .datasource else .datasource?.uid end) == "abcdefghi" + ).uid +' - \ +| sort -u