Relic Solution: Using NerdGraph to recover a deleted dashboard

I’ll cut right to the chase on this one…

You’ve got a dashboard* that you accidentally deleted. You have a link to that dashboard, and you want it recovered ASAP. You don’t want to sit through any of the preamble in a Relic Solution; you just want your dashboard back.

Friend, this is the post for you.

Where do I start?

By providing a GUID to the dashboardUndelete mutation, you can recover a deleted dashboard immediately. As long as you have a link to the deleted dashboard, there’s two easy options to recover the GUID:

UI

If you have quick access to a web browser, simply visit the URL that points to the deleted dashboard. You’ll see an “Entity not found” message with the GUID right next to it.

CLI

To accomplish this programmatically, you’ll want to have newrelic-cli configured and installed. Once the tool is installed, simply run this command:

echo -n "$(newrelic decode url -p="pane" -s="entityId" 'URL_GOES_HERE')" | base64 | rev | cut -d= -f2- | rev

GUIDs are Base64-encoded strings. The above command will trawl through the URL and return an entity’s decoded GUID, and as long as you have base64 installed, it will then encode the GUID back to the format we expect.

(It will also cut out a trailing equal sign if there’s one present.)

Where do I go next?

Next up, you’ll need to run a NerdGraph mutation via the API client of your choice. The mutation will need to look like this:

mutation {
  dashboardUndelete(guid: "GUID_GOES_HERE") {
    errors {
      description
      type
    }
  }
}

If the mutation is executed successfully, the errors field should return a null response. That’s how you know the dashboard has been successfully recovered.

Do I need to do anything else?

Nope! It’s that easy.

*Individual pages cannot be recovered at this time. You can only recover a full dashboard that was deleted in its entirety.

4 Likes