or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

admin-and-rbac.mdalerting.mdauthentication.mdclient-management.mddashboards.mddata-models.mddatasources.mdindex.mdlibrary-elements.mdplugin-management.mdsnapshot-management.mdusers-and-orgs.md

snapshot-management.mddocs/

0

# Snapshot Management

1

2

Dashboard snapshot creation and management for sharing and archiving dashboard states. Snapshots allow you to capture dashboard configurations and share them with configurable expiration times and external storage options.

3

4

## Capabilities

5

6

### Snapshot Creation

7

8

Create new dashboard snapshots with flexible configuration options including expiration times and external storage.

9

10

```python { .api }

11

def create_new_snapshot(self, dashboard: dict, name: Optional[str] = None,

12

expires: Optional[int] = None, external: Optional[bool] = None,

13

key: Optional[str] = None, delete_key: Optional[str] = None):

14

"""

15

Create a new dashboard snapshot.

16

17

Parameters:

18

dashboard (dict): Required. The complete dashboard model to snapshot

19

name (str, optional): Name for the snapshot

20

expires (int, optional): Expiration time in seconds (3600=1hr, 86400=1day).

21

Default is never expire

22

external (bool, optional): Save on external server rather than locally. Default False

23

key (str, optional): Define unique key. Required if external is True

24

delete_key (str, optional): Unique key for deletion. Required if external is True

25

26

Returns:

27

dict: Snapshot creation result with URL and keys

28

"""

29

```

30

31

### Snapshot Retrieval

32

33

List and retrieve existing dashboard snapshots for viewing and management.

34

35

```python { .api }

36

def get_dashboard_snapshots(self):

37

"""

38

Get list of all dashboard snapshots.

39

40

Returns:

41

list: List of snapshot objects with metadata

42

"""

43

44

def get_snapshot_by_key(self, key: str):

45

"""

46

Retrieve a specific snapshot by its key.

47

48

Parameters:

49

key (str): The snapshot key

50

51

Returns:

52

dict: Snapshot data and dashboard configuration

53

"""

54

```

55

56

### Snapshot Deletion

57

58

Remove snapshots using either the snapshot key or delete key for different permission levels.

59

60

```python { .api }

61

def delete_snapshot_by_key(self, snapshot_id: str):

62

"""

63

Delete a snapshot using its ID/key.

64

65

Parameters:

66

snapshot_id (str): The snapshot identifier

67

68

Returns:

69

dict: Deletion result

70

"""

71

72

def delete_snapshot_by_delete_key(self, snapshot_delete_key: str):

73

"""

74

Delete a snapshot using its delete key (creator-only deletion).

75

76

Parameters:

77

snapshot_delete_key (str): The delete key for the snapshot

78

79

Returns:

80

dict: Deletion result

81

"""

82

```

83

84

## Usage Examples

85

86

### Creating Snapshots

87

88

```python

89

from grafana_client import GrafanaApi, TokenAuth

90

91

# Create API client

92

auth = TokenAuth(token="your-grafana-api-token")

93

api = GrafanaApi(auth=auth, host="your-grafana-host")

94

95

# Get a dashboard to snapshot

96

dashboard_data = api.dashboard.get_dashboard("dashboard-uid")

97

98

# Create a basic snapshot

99

snapshot_result = api.snapshots.create_new_snapshot(

100

dashboard=dashboard_data["dashboard"],

101

name="Weekly Report Snapshot"

102

)

103

print(f"Snapshot created: {snapshot_result['url']}")

104

print(f"Snapshot key: {snapshot_result['key']}")

105

print(f"Delete key: {snapshot_result['deleteKey']}")

106

107

# Create a snapshot with expiration (24 hours)

108

snapshot_result = api.snapshots.create_new_snapshot(

109

dashboard=dashboard_data["dashboard"],

110

name="Temporary Dashboard Snapshot",

111

expires=86400 # 24 hours in seconds

112

)

113

114

# Create an external snapshot

115

external_snapshot = api.snapshots.create_new_snapshot(

116

dashboard=dashboard_data["dashboard"],

117

name="External Snapshot",

118

external=True,

119

key="my-external-key",

120

delete_key="my-delete-key"

121

)

122

```

123

124

### Managing Snapshots

125

126

```python

127

# List all snapshots

128

snapshots = api.snapshots.get_dashboard_snapshots()

129

for snapshot in snapshots:

130

print(f"Snapshot: {snapshot['name']} - Key: {snapshot['key']}")

131

132

# Retrieve specific snapshot

133

snapshot_key = "AbCdEf123456"

134

snapshot_data = api.snapshots.get_snapshot_by_key(snapshot_key)

135

print(f"Retrieved snapshot: {snapshot_data['snapshot']['name']}")

136

137

# Delete snapshot by key

138

api.snapshots.delete_snapshot_by_key(snapshot_key)

139

print("Snapshot deleted")

140

141

# Delete snapshot using delete key (creator privilege)

142

delete_key = "delete-key-123"

143

api.snapshots.delete_snapshot_by_delete_key(delete_key)

144

print("Snapshot deleted using delete key")

145

```

146

147

### Sharing Workflows

148

149

```python

150

# Create a snapshot for sharing

151

dashboard_uid = "dashboard-to-share"

152

dashboard_data = api.dashboard.get_dashboard(dashboard_uid)

153

154

# Create snapshot with 7-day expiration

155

share_snapshot = api.snapshots.create_new_snapshot(

156

dashboard=dashboard_data["dashboard"],

157

name=f"Shared Dashboard - {dashboard_data['dashboard']['title']}",

158

expires=604800 # 7 days

159

)

160

161

# Share the URL

162

share_url = share_snapshot["url"]

163

print(f"Share this URL: {share_url}")

164

165

# Store delete key for later cleanup

166

delete_key = share_snapshot["deleteKey"]

167

print(f"Delete key (keep private): {delete_key}")

168

```