transitioned to python
This commit is contained in:
25
src/restic/loki.py
Normal file
25
src/restic/loki.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
from time import time
|
||||
|
||||
import requests
|
||||
|
||||
from .console import logger
|
||||
|
||||
|
||||
def send_to_loki(loki_url: str, line: str, backup: str):
|
||||
ns = round(time() * 1_000_000_000)
|
||||
|
||||
payload = {
|
||||
'streams': [
|
||||
{
|
||||
'stream': {'host': os.environ['HOSTNAME'], 'backup': backup},
|
||||
'values': [[str(ns), line]],
|
||||
}
|
||||
]
|
||||
}
|
||||
try:
|
||||
resp = requests.post(loki_url, json=payload, timeout=1)
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
else:
|
||||
logger.info(f'Sent line to loki at {loki_url} {resp.text}')
|
||||
Reference in New Issue
Block a user