Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a dashboard should use /api/dashboards/import #50

Open
ghmeier opened this issue Mar 11, 2019 · 6 comments
Open

Creating a dashboard should use /api/dashboards/import #50

ghmeier opened this issue Mar 11, 2019 · 6 comments
Labels

Comments

@ghmeier
Copy link

ghmeier commented Mar 11, 2019

👋 Hi! Playing around with the module a bit, I noticed that attempting to create a dashboard with alerts preconfigured always returns a 422 Unprocesssable Entity. However, making the same dashboard without the alerts works as expected. The dashboard JSON with alerts is importable via the UI with no problem. I've tested this on Grafana 5.0.1 and 5.4.3, though it looks to be a continual (and undocumented) issue based on this closed issue. I'd propose that we switch this provider to use api/dashboards/import API as recommended in that issue.

I think this would be the intended use of that API since it has the same format and is specifically for uploading JSON dashboard configs.

@ghmeier
Copy link
Author

ghmeier commented Mar 11, 2019

Merging this PR in go-grafana-api and upgrading it here, should do the trick.

@mlclmj
Copy link
Contributor

mlclmj commented Mar 19, 2019

Hey @ghmeier! That sounds good to me, I'll go look at that PR in the upstream API repo as well. Would you happen to have an example dashboard that could be used to reproduce this?

@ghmeier
Copy link
Author

ghmeier commented Mar 19, 2019

Yep! Here's an example:

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations and Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "gnetId": null,
  "graphTooltip": 0,
  "id": 256,
  "links": [],
  "panels": [
    {
      "alert": {
        "conditions": [
          {
            "evaluator": {
              "params": [
                100
              ],
              "type": "gt"
            },
            "operator": {
              "type": "and"
            },
            "query": {
              "params": [
                "A",
                "5m",
                "now"
              ]
            },
            "reducer": {
              "params": [],
              "type": "avg"
            },
            "type": "query"
          }
        ],
        "executionErrorState": "alerting",
        "for": "5m",
        "frequency": "1m",
        "handler": 1,
        "message": "Test message",
        "name": "Delayed alert",
        "noDataState": "no_data",
        "notifications": [
          {
            "id": 7
          }
        ]
      },
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": null,
      "fill": 1,
      "gridPos": {
        "h": 5,
        "w": 8,
        "x": 0,
        "y": 0
      },
      "id": 2,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null as zero",
      "percentage": false,
      "pointradius": 5,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "refCount": 0,
          "refId": "A",
          "target": "aliasByMetric(stats.gauges.delayed)"
        }
      ],
      "thresholds": [
        {
          "colorMode": "critical",
          "fill": true,
          "line": true,
          "op": "gt",
          "value": 100
        }
      ],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "Delayed",
      "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": "0",
          "show": true
        },
        {
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": "0",
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    }
  ],
  "schemaVersion": 16,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "5s",
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ],
    "time_options": [
      "5m",
      "15m",
      "1h",
      "6h",
      "12h",
      "24h",
      "2d",
      "7d",
      "30d"
    ]
  },
  "timezone": "",
  "title": "Test Dashboard"
}

This should be correctly created without panels[0].alerts but fail with 422 when panels[0].alerts is included.

@inkel inkel added the bug label Dec 21, 2021
@reloadedd
Copy link

Hi, any progress on this? I have made a terraform module that recursively imports dashboards from some folders and it always fails when importing dashboards containing alerts. The error is the same:

│ Error: status: 422, body: [{"fieldNames":["Dashboard"],"classification":"RequiredError","message":"Required"}]

@fraserc182
Copy link

I'm also running into this issue when creating dashboards with some jsonencode loops in them.

@Hronom
Copy link

Hronom commented May 24, 2023

Hello is there any progress on this?

I tried to upload json from Grafana dashboards marketplace and seems like it not able to process legacy dashboards datasources.

For example this dashboard https://grafana.com/grafana/dashboards/16237-cluster-capacity/

But if I import it in UI of Grafana - works.

This is a blocker if you wanna work with old dashboards. Also relates to this task that was closed without resolution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants