Skip to content

Instantly share code, notes, and snippets.

@eeddaann
Created April 13, 2023 10:37
Show Gist options
  • Save eeddaann/3353b8d65cbc7ecc27cb331a04c64038 to your computer and use it in GitHub Desktop.
Save eeddaann/3353b8d65cbc7ecc27cb331a04c64038 to your computer and use it in GitHub Desktop.
generate random data for zincobserve
import base64, json
import requests
from requests.exceptions import HTTPError
import random
import time
user = "root@example.com"
password = "Complexpass#123"
bas64encoded_creds = base64.b64encode(bytes(user + ":" + password, "utf-8")).decode("utf-8")
headers = {"Content-type": "application/json", "Authorization": "Basic " + bas64encoded_creds}
org = "default"
stream = "demo"
zinc_host = "http://localhost:5080"
zinc_url = zinc_host + "/api/" + org + "/" + stream + "/_json"
for i in range(100):
data = [{'metric1': i, 'metric2': i*2, 'metric3': random.randint(1, 100)}]
try:
response = requests.post(zinc_url, headers=headers, data=json.dumps(data))
# If the response was successful, no Exception will be raised
response.raise_for_status()
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}') # Python 3.6
except Exception as err:
print(f'Other error occurred: {err}') # Python 3.6
else:
print('Success!')
time.sleep(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment