@@ -38,11 +38,14 @@ def create_run(self, data):
38
38
headers = self ._headers ,
39
39
json = data ,
40
40
timeout = DEFAULT_API_TIMEOUT )
41
- except requests .exceptions .RequestException :
41
+ except requests .exceptions .RequestException as err :
42
+ self ._error (f"Exception creating run: { str (err )} " )
42
43
return False
43
44
44
- if response .status_code != 200 :
45
- self ._error ('Unable to reconnect to run' )
45
+ if response .status_code == 409 :
46
+ self ._error (f"Duplicate run, name { data ['name' ]} already exists" )
47
+ elif response .status_code != 200 :
48
+ self ._error (f"Got status code { response .status_code } when creating run" )
46
49
return False
47
50
48
51
return True
@@ -56,12 +59,14 @@ def update(self, data):
56
59
headers = self ._headers ,
57
60
json = data ,
58
61
timeout = DEFAULT_API_TIMEOUT )
59
- except requests .exceptions .RequestException :
60
- pass
62
+ except requests .exceptions .RequestException as err :
63
+ self ._error (f"Exception creating updating run: { str (err )} " )
64
+ return False
61
65
62
66
if response .status_code == 200 :
63
67
return True
64
68
69
+ self ._error (f"Got status code { response .status_code } when updating run" )
65
70
return False
66
71
67
72
def set_folder_details (self , data ):
@@ -73,12 +78,14 @@ def set_folder_details(self, data):
73
78
headers = self ._headers ,
74
79
json = data ,
75
80
timeout = DEFAULT_API_TIMEOUT )
76
- except requests .exceptions .RequestException :
77
- pass
81
+ except requests .exceptions .RequestException as err :
82
+ self ._error (f"Exception setting folder details: { err } " )
83
+ return False
78
84
79
85
if response .status_code == 200 :
80
86
return True
81
87
88
+ self ._error (f"Got status code { response .status_code } when updating folder details" )
82
89
return False
83
90
84
91
def save_file (self , data ):
@@ -122,16 +129,18 @@ def add_alert(self, data):
122
129
Add an alert
123
130
"""
124
131
try :
125
- response = requests .put (f"{ self ._url } /api/runs" ,
126
- headers = self ._headers ,
127
- json = data ,
128
- timeout = DEFAULT_API_TIMEOUT )
129
- except requests .exceptions .RequestException :
130
- pass
132
+ response = requests .post (f"{ self ._url } /api/alerts" ,
133
+ headers = self ._headers ,
134
+ json = data ,
135
+ timeout = DEFAULT_API_TIMEOUT )
136
+ except requests .exceptions .RequestException as err :
137
+ self ._error (f"Got exception when creating an alert: { str (err )} " )
138
+ return False
131
139
132
- if response .status_code == 200 :
140
+ if response .status_code in ( 200 , 409 ) :
133
141
return True
134
142
143
+ self ._error (f"Got status code { response .status_code } when creating alert" )
135
144
return False
136
145
137
146
def send_metrics (self , data ):
@@ -143,8 +152,15 @@ def send_metrics(self, data):
143
152
headers = self ._headers_mp ,
144
153
data = data ,
145
154
timeout = DEFAULT_API_TIMEOUT )
146
- except :
147
- pass
155
+ except requests .exceptions .RequestException as err :
156
+ self ._error (f"Exception sending metrics: { str (err )} " )
157
+ return False
158
+
159
+ if response .status_code == 200 :
160
+ return True
161
+
162
+ self ._error (f"Got status code { response .status_code } when sending metrics" )
163
+ return False
148
164
149
165
def send_event (self , data ):
150
166
"""
@@ -155,8 +171,15 @@ def send_event(self, data):
155
171
headers = self ._headers_mp ,
156
172
data = data ,
157
173
timeout = DEFAULT_API_TIMEOUT )
158
- except :
159
- pass
174
+ except requests .exceptions .RequestException as err :
175
+ self ._error (f"Exception sending event: { str (err )} " )
176
+ return False
177
+
178
+ if response .status_code == 200 :
179
+ return True
180
+
181
+ self ._error (f"Got status code { response .status_code } when sending events" )
182
+ return False
160
183
161
184
def send_heartbeat (self ):
162
185
"""
@@ -167,5 +190,12 @@ def send_heartbeat(self):
167
190
headers = self ._headers ,
168
191
json = {'name' : self ._name },
169
192
timeout = DEFAULT_API_TIMEOUT )
170
- except :
171
- pass
193
+ except requests .exceptions .RequestException as err :
194
+ self ._error (f"Exception creating run: { str (err )} " )
195
+ return False
196
+
197
+ if response .status_code == 200 :
198
+ return True
199
+
200
+ self ._error (f"Got status code { response .status_code } when sending heartbeat" )
201
+ return False
0 commit comments