Skip to content

Commit b31ee38

Browse files
author
Anze
committed
Add send_results_to_grafolean()
1 parent 871a224 commit b31ee38

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

grafoleancollector/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .collector import Collector
1+
from .collector import Collector, send_results_to_grafolean

grafoleancollector/collector.py

+16
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,22 @@ def _run_job_error(self, job_id, exc, traceback=None):
181181
open('/tmp/fail_health_check', 'a').close()
182182

183183

184+
def send_results_to_grafolean(backend_url, bot_token, account_id, values):
185+
url = '{}/accounts/{}/values/?b={}'.format(backend_url, account_id, bot_token)
186+
187+
if len(values) == 0:
188+
logging.warning("No results available to be sent to Grafolean, skipping.")
189+
return
190+
191+
logging.info("Sending results to Grafolean")
192+
try:
193+
r = requests.post(url, json=values)
194+
r.raise_for_status()
195+
logging.info("Results sent: {}".format(values))
196+
except:
197+
logging.exception("Error sending data to Grafolean")
198+
199+
184200
class Collector(object):
185201
__slots__ = 'backend_url', 'bot_token', 'scheduler', 'known_jobs', 'jobs_refresh_interval', 'user_id'
186202

0 commit comments

Comments
 (0)