-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegrations_config.py
More file actions
282 lines (204 loc) · 7.47 KB
/
integrations_config.py
File metadata and controls
282 lines (204 loc) · 7.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
"""
External integrations configuration for production mode.
Connects with real monitoring, logs and deploy APIs.
"""
import os
from pydantic_settings import BaseSettings
from pydantic import Field
from typing import Optional
class DatadogConfig(BaseSettings):
"""Datadog configuration for metrics and logs."""
enabled: bool = Field(default=False)
api_key: str = Field(default="")
app_key: str = Field(default="")
site: str = Field(default="datadoghq.com")
metrics_api: str = Field(default="https://api.datadoghq.com/api/v1/query")
logs_api: str = Field(default="https://api.datadoghq.com/api/v2/logs/events/search")
class Config:
env_prefix = "DATADOG_"
env_file = ".env"
extra = "ignore"
class PrometheusConfig(BaseSettings):
"""Prometheus configuration for metrics."""
enabled: bool = Field(default=False)
url: str = Field(default="http://localhost:9090")
class Config:
env_prefix = "PROMETHEUS_"
env_file = ".env"
extra = "ignore"
class GrafanaConfig(BaseSettings):
"""Grafana configuration for dashboards and alerts."""
enabled: bool = Field(default=False)
url: str = Field(default="http://localhost:3000")
api_key: str = Field(default="")
class Config:
env_prefix = "GRAFANA_"
env_file = ".env"
extra = "ignore"
class ElasticsearchConfig(BaseSettings):
"""Elasticsearch/OpenSearch configuration for logs."""
enabled: bool = Field(default=False)
url: str = Field(default="http://localhost:9200")
username: str = Field(default="")
password: str = Field(default="")
index_pattern: str = Field(default="logs-*")
class Config:
env_prefix = "ELASTICSEARCH_"
env_file = ".env"
extra = "ignore"
class LokiConfig(BaseSettings):
"""Loki configuration for logs."""
enabled: bool = Field(default=False)
url: str = Field(default="http://localhost:3100")
class Config:
env_prefix = "LOKI_"
env_file = ".env"
extra = "ignore"
class CloudWatchLogsConfig(BaseSettings):
"""AWS CloudWatch Logs configuration."""
enabled: bool = Field(default=False)
region: str = Field(default="us-east-1")
log_group: str = Field(default="")
access_key_id: str = Field(default="") # Optional if using IAM role
secret_access_key: str = Field(default="") # Optional if using IAM role
class Config:
env_prefix = "CLOUDWATCH_LOGS_"
env_file = ".env"
extra = "ignore"
class CloudWatchMetricsConfig(BaseSettings):
"""AWS CloudWatch Metrics configuration."""
enabled: bool = Field(default=False)
region: str = Field(default="us-east-1")
namespace: str = Field(default="AWS/ECS") # or AWS/EKS, custom, etc.
access_key_id: str = Field(default="") # Optional if using IAM role
secret_access_key: str = Field(default="") # Optional if using IAM role
class Config:
env_prefix = "CLOUDWATCH_METRICS_"
env_file = ".env"
extra = "ignore"
class KubernetesConfig(BaseSettings):
"""Kubernetes configuration for cluster resources."""
enabled: bool = Field(default=False)
kubeconfig_path: str = Field(default="~/.kube/config")
context: str = Field(default="")
namespace: str = Field(default="default")
class Config:
env_prefix = "K8S_"
env_file = ".env"
extra = "ignore"
class ArgoConfig(BaseSettings):
"""ArgoCD configuration for deploys."""
enabled: bool = Field(default=False)
url: str = Field(default="http://localhost:8080")
token: str = Field(default="")
class Config:
env_prefix = "ARGO_"
env_file = ".env"
extra = "ignore"
class GitHubConfig(BaseSettings):
"""GitHub configuration for commits/deploys history."""
enabled: bool = Field(default=False)
token: str = Field(default="")
org: str = Field(default="")
class Config:
env_prefix = "GITHUB_"
env_file = ".env"
extra = "ignore"
class GitLabConfig(BaseSettings):
"""GitLab configuration for commits/deploys history."""
enabled: bool = Field(default=False)
url: str = Field(default="https://gitlab.com")
token: str = Field(default="")
class Config:
env_prefix = "GITLAB_"
env_file = ".env"
extra = "ignore"
class PagerDutyConfig(BaseSettings):
"""PagerDuty configuration for incidents."""
enabled: bool = Field(default=False)
api_key: str = Field(default="")
class Config:
env_prefix = "PAGERDUTY_"
env_file = ".env"
extra = "ignore"
class OpsGenieConfig(BaseSettings):
"""OpsGenie configuration for incidents."""
enabled: bool = Field(default=False)
api_key: str = Field(default="")
class Config:
env_prefix = "OPSGENIE_"
env_file = ".env"
extra = "ignore"
class SentryConfig(BaseSettings):
"""Sentry configuration for error tracking."""
enabled: bool = Field(default=False)
dsn: str = Field(default="")
auth_token: str = Field(default="") # For API access
org_slug: str = Field(default="")
project_slug: str = Field(default="")
base_url: str = Field(default="https://sentry.io/api/0")
class Config:
env_prefix = "SENTRY_"
env_file = ".env"
extra = "ignore"
class SlackConfig(BaseSettings):
"""Slack configuration for notifications."""
enabled: bool = Field(default=False)
webhook_url: str = Field(default="")
bot_token: str = Field(default="")
channel: str = Field(default="#incidents")
class Config:
env_prefix = "SLACK_"
env_file = ".env"
extra = "ignore"
class IntegrationsConfig:
"""Centralized configuration for all integrations."""
def __init__(self):
# Metrics
self.datadog = DatadogConfig()
self.prometheus = PrometheusConfig()
self.grafana = GrafanaConfig()
self.cloudwatch_metrics = CloudWatchMetricsConfig()
# Logs / Errors
self.elasticsearch = ElasticsearchConfig()
self.loki = LokiConfig()
self.sentry = SentryConfig()
self.cloudwatch_logs = CloudWatchLogsConfig()
# Kubernetes
self.kubernetes = KubernetesConfig()
# Deploy/CI-CD
self.argo = ArgoConfig()
self.github = GitHubConfig()
self.gitlab = GitLabConfig()
# Incidents
self.pagerduty = PagerDutyConfig()
self.opsgenie = OpsGenieConfig()
# Notifications
self.slack = SlackConfig()
# Global instance
integrations = IntegrationsConfig()
def get_metrics_provider() -> str:
"""Returns the configured metrics provider."""
if integrations.datadog.enabled:
return "datadog"
if integrations.prometheus.enabled:
return "prometheus"
return "mock"
def get_logs_provider() -> str:
"""Returns the configured logs provider."""
if integrations.datadog.enabled:
return "datadog"
if integrations.elasticsearch.enabled:
return "elasticsearch"
if integrations.loki.enabled:
return "loki"
return "mock"
def get_deploy_provider() -> str:
"""Returns the configured deploy provider."""
if integrations.argo.enabled:
return "argo"
if integrations.github.enabled:
return "github"
if integrations.gitlab.enabled:
return "gitlab"
return "mock"