-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path__init__.py
More file actions
84 lines (65 loc) · 2.72 KB
/
__init__.py
File metadata and controls
84 lines (65 loc) · 2.72 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
import logging
from urllib.parse import urlencode
log = logging.getLogger("socketdev")
class Historical:
def __init__(self, api):
self.api = api
self.snapshots = self.Snapshots(api)
def list(self, org_slug: str, query_params: dict = None) -> dict:
"""Get historical alerts list for an organization.
Args:
org_slug: Organization slug
query_params: Optional dictionary of query parameters
"""
path = f"orgs/{org_slug}/historical/alerts"
if query_params:
path += "?" + urlencode(query_params)
response = self.api.do_request(path=path)
if response.status_code == 200:
return response.json()
log.error(f"Error getting historical alerts: {response.status_code}")
log.error(response.text)
return {}
def trend(self, org_slug: str, query_params: dict = None) -> dict:
"""Get historical alert trends data for an org.
Args:
org_slug: Organization slug
query_params: Optional dictionary of query parameters
"""
path = f"orgs/{org_slug}/historical/alerts/trend"
if query_params:
path += "?" + urlencode(query_params)
response = self.api.do_request(path=path)
if response.status_code == 200:
return response.json()
log.error(f"Error getting historical trend: {response.status_code}")
log.error(response.text)
return {}
class Snapshots:
"""Submodule for managing historical snapshots."""
def __init__(self, api):
self.api = api
def create(self, org_slug: str) -> dict:
"""Create a new snapshot for an organization.
Args:
org_slug: Organization slug
data: Dictionary containing snapshot data
"""
path = f"orgs/{org_slug}/historical/snapshots"
response = self.api.do_request(path=path, method="POST")
if response.status_code == 200:
return response.json()
log.error(f"Error creating snapshot: {response.status_code}")
log.error(response.text)
return {}
def list(self, org_slug: str, query_params: dict = None) -> dict:
"""List historical snapshots for an organization."""
path = f"orgs/{org_slug}/historical/snapshots"
if query_params:
path += "?" + urlencode(query_params)
response = self.api.do_request(path=path)
if response.status_code == 200:
return response.json()
log.error(f"Error listing snapshots: {response.status_code}")
log.error(response.text)
return {}