or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

admin-tools.mdapi-health.mdarchive-management.mdbackup-operations.mdcloud-storage.mdconfiguration.mddelete-operations.mdindex.mdmonitoring.mdrestore-operations.md

configuration.mddocs/

0

# Configuration Management

1

2

Comprehensive configuration loading and processing system that handles JSON files, environment variables, and default settings. The configuration system manages Grafana API connections, authentication methods, cloud storage credentials, and operational parameters.

3

4

## Capabilities

5

6

### Main Configuration Loader

7

8

The primary configuration function that loads settings from multiple sources with environment variable override support.

9

10

```python { .api }

11

def main(config_path):

12

"""

13

Load and process configuration from JSON file with environment variable overrides

14

15

Args:

16

config_path (str): Path to JSON configuration file

17

18

Returns:

19

dict: Complete configuration dictionary with all settings processed

20

"""

21

```

22

23

### Configuration Helper Functions

24

25

```python { .api }

26

def load_config(path=None):

27

"""

28

Load JSON configuration file with error handling

29

30

Module: grafana_backup.commons

31

Args:

32

path (str): Path to JSON configuration file

33

34

Returns:

35

dict: Parsed JSON configuration data

36

"""

37

```

38

39

## Configuration Structure

40

41

### Grafana Connection Settings

42

43

```python { .api }

44

# Configuration keys for Grafana API connection

45

GRAFANA_URL: str # Grafana server URL (e.g., "http://localhost:3000")

46

TOKEN: str # API token for authentication

47

SEARCH_API_LIMIT: int # Search result limit (default: 5000)

48

DEFAULT_USER_PASSWORD: str # Default password for restored users

49

GRAFANA_VERSION: str # Optional Grafana version override

50

GRAFANA_ADMIN_ACCOUNT: str # Admin username for basic auth operations

51

GRAFANA_ADMIN_PASSWORD: str # Admin password for basic auth operations

52

GRAFANA_BASIC_AUTH: str # Base64 encoded basic auth credentials

53

```

54

55

### General Operation Settings

56

57

```python { .api }

58

# General configuration keys

59

DEBUG: bool # Enable debug logging

60

API_HEALTH_CHECK: bool # Perform API health checks

61

API_AUTH_CHECK: bool # Verify API authentication

62

VERIFY_SSL: bool # Enable SSL certificate verification

63

CLIENT_CERT: str # Path to client certificate file

64

BACKUP_DIR: str # Backup output directory (default: "_OUTPUT_")

65

BACKUP_FILE_FORMAT: str # Timestamp format for backup files

66

UID_DASHBOARD_SLUG_SUFFIX: bool # Include UID in dashboard filenames

67

PRETTY_PRINT: bool # Format JSON output with indentation

68

EXTRA_HEADERS: dict # Custom HTTP headers for API requests

69

```

70

71

### HTTP Headers Configuration

72

73

```python { .api }

74

# HTTP header dictionaries for API requests

75

HTTP_GET_HEADERS: dict # Headers for GET requests

76

HTTP_POST_HEADERS: dict # Headers for POST requests

77

HTTP_GET_HEADERS_BASIC_AUTH: dict # GET headers with basic auth

78

HTTP_POST_HEADERS_BASIC_AUTH: dict # POST headers with basic auth

79

```

80

81

### AWS S3 Configuration

82

83

```python { .api }

84

# AWS S3 cloud storage settings

85

AWS_S3_BUCKET_NAME: str # S3 bucket name

86

AWS_S3_BUCKET_KEY: str # S3 key prefix for backups

87

AWS_DEFAULT_REGION: str # AWS region

88

AWS_ACCESS_KEY_ID: str # AWS access key

89

AWS_SECRET_ACCESS_KEY: str # AWS secret key

90

AWS_ENDPOINT_URL: str # Custom S3 endpoint URL (for S3-compatible services)

91

```

92

93

### Azure Storage Configuration

94

95

```python { .api }

96

# Azure Storage cloud storage settings

97

AZURE_STORAGE_CONTAINER_NAME: str # Azure container name

98

AZURE_STORAGE_CONNECTION_STRING: str # Azure storage connection string

99

```

100

101

### Google Cloud Storage Configuration

102

103

```python { .api }

104

# Google Cloud Storage settings

105

GCS_BUCKET_NAME: str # GCS bucket name

106

GOOGLE_APPLICATION_CREDENTIALS: str # Path to GCS service account key file

107

```

108

109

### InfluxDB Monitoring Configuration

110

111

```python { .api }

112

# InfluxDB metrics collection settings

113

INFLUXDB_MEASUREMENT: str # InfluxDB measurement name

114

INFLUXDB_HOST: str # InfluxDB server hostname

115

INFLUXDB_PORT: int # InfluxDB server port

116

INFLUXDB_USERNAME: str # InfluxDB username

117

INFLUXDB_PASSWORD: str # InfluxDB password

118

INFLUXDB_DATABASE: str # InfluxDB database name

119

```

120

121

### Timestamp Configuration

122

123

```python { .api }

124

# Timestamp generation

125

TIMESTAMP: str # Current timestamp using BACKUP_FILE_FORMAT

126

```

127

128

## Configuration File Format

129

130

### Basic Configuration Example

131

132

```json

133

{

134

"general": {

135

"debug": true,

136

"verify_ssl": true,

137

"api_health_check": true,

138

"api_auth_check": true,

139

"backup_dir": "_OUTPUT_",

140

"backup_file_format": "%Y%m%d%H%M",

141

"uid_dashboard_slug_suffix": false,

142

"pretty_print": false

143

},

144

"grafana": {

145

"url": "http://localhost:3000",

146

"token": "{YOUR_GRAFANA_TOKEN}",

147

"search_api_limit": 5000,

148

"default_user_password": "00000000",

149

"admin_account": "admin",

150

"admin_password": "admin"

151

}

152

}

153

```

154

155

### Cloud Storage Configuration Example

156

157

```json

158

{

159

"aws": {

160

"s3_bucket_name": "my-grafana-backups",

161

"s3_bucket_key": "grafana-backup",

162

"default_region": "us-east-1",

163

"access_key_id": "AKIAIOSFODNN7EXAMPLE",

164

"secret_access_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"

165

},

166

"azure": {

167

"container_name": "grafana-backups",

168

"connection_string": "DefaultEndpointsProtocol=https;AccountName=..."

169

},

170

"gcp": {

171

"gcs_bucket_name": "my-grafana-backups",

172

"google_application_credentials": "/path/to/service-account.json"

173

}

174

}

175

```

176

177

### InfluxDB Monitoring Configuration Example

178

179

```json

180

{

181

"influxdb": {

182

"measurement": "grafana_backup",

183

"host": "localhost",

184

"port": 8086,

185

"username": "monitoring",

186

"password": "monitoring_password",

187

"database": "grafana_metrics"

188

}

189

}

190

```

191

192

## Environment Variable Overrides

193

194

All configuration values can be overridden using environment variables:

195

196

### Grafana Settings

197

```bash

198

export GRAFANA_URL="https://grafana.example.com"

199

export GRAFANA_TOKEN="eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk"

200

export SEARCH_API_LIMIT=1000

201

export DEFAULT_USER_PASSWORD="newuserpass"

202

export GRAFANA_ADMIN_ACCOUNT="admin"

203

export GRAFANA_ADMIN_PASSWORD="admin123"

204

export GRAFANA_BASIC_AUTH="YWRtaW46YWRtaW4xMjM="

205

```

206

207

### General Settings

208

```bash

209

export DEBUG=true

210

export VERIFY_SSL=false

211

export BACKUP_DIR="/custom/backup/path"

212

export BACKUP_FILE_FORMAT="%Y-%m-%d_%H-%M-%S"

213

export PRETTY_PRINT=true

214

```

215

216

### AWS Settings

217

```bash

218

export AWS_S3_BUCKET_NAME="production-grafana-backups"

219

export AWS_DEFAULT_REGION="us-west-2"

220

export AWS_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE"

221

export AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"

222

```

223

224

### Custom Headers

225

```bash

226

export GRAFANA_HEADERS="X-Custom-Header:value,X-Another-Header:value2"

227

```

228

229

## Configuration File Locations

230

231

The configuration system searches for configuration files in this order:

232

233

1. **Command line specified**: `--config=/path/to/config.json`

234

2. **User home directory**: `~/.grafana-backup.json`

235

3. **Package default**: `grafana_backup/conf/grafanaSettings.json`

236

237

## Usage Examples

238

239

### Load Configuration from Default Location

240

```python

241

from grafana_backup.grafanaSettings import main as load_config

242

243

# Load from default locations (searches in order)

244

settings = load_config(None)

245

```

246

247

### Load Configuration from Specific File

248

```python

249

# Load from specific file path

250

settings = load_config('/path/to/custom-config.json')

251

```

252

253

### Access Configuration Values

254

```python

255

# Access configuration values

256

grafana_url = settings['GRAFANA_URL']

257

backup_dir = settings['BACKUP_DIR']

258

aws_bucket = settings.get('AWS_S3_BUCKET_NAME', '')

259

debug_mode = settings['DEBUG']

260

```

261

262

### Configuration with Environment Variables

263

```python

264

import os

265

266

# Set environment variables

267

os.environ['GRAFANA_URL'] = 'https://grafana.production.com'

268

os.environ['DEBUG'] = 'false'

269

270

# Load configuration (environment variables take precedence)

271

settings = load_config('/path/to/config.json')

272

```

273

274

## Authentication Configuration

275

276

### API Token Authentication (Recommended)

277

```json

278

{

279

"grafana": {

280

"url": "http://localhost:3000",

281

"token": "eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk"

282

}

283

}

284

```

285

286

### Basic Authentication (Required for User/Org Operations)

287

```json

288

{

289

"grafana": {

290

"url": "http://localhost:3000",

291

"token": "eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk",

292

"admin_account": "admin",

293

"admin_password": "admin123"

294

}

295

}

296

```

297

298

### Environment Variable Authentication

299

```bash

300

export GRAFANA_TOKEN="eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk"

301

export GRAFANA_BASIC_AUTH="YWRtaW46YWRtaW4xMjM=" # Base64 of "admin:admin123"

302

```

303

304

## Configuration Validation

305

306

The configuration system includes automatic validation:

307

308

- **Required fields**: URL and token validation

309

- **Type conversion**: String environment variables to appropriate types

310

- **SSL certificate**: Client certificate file existence check

311

- **Cloud credentials**: Basic credential format validation

312

- **Directory creation**: Backup directory creation if it doesn't exist

313

314

## Security Considerations

315

316

- **Credentials**: Never commit configuration files with real credentials

317

- **File permissions**: Restrict access to configuration files (600 recommended)

318

- **Environment variables**: Use environment variables in production

319

- **SSL verification**: Always enable SSL verification in production

320

- **Token rotation**: Regularly rotate API tokens and credentials