Skip to content

Instantly share code, notes, and snippets.

@zerosoul13
Created October 5, 2022 00:06
Show Gist options
  • Save zerosoul13/16f594728d23458c18f5833a8a57a96e to your computer and use it in GitHub Desktop.
Save zerosoul13/16f594728d23458c18f5833a8a57a96e to your computer and use it in GitHub Desktop.
test loki messages
#!/usr/bin/python3
import datetime
import pytz
import json
import requests
from faker import Faker
fake = Faker()
def getEmployees(count: int) -> list:
if count == 0:
count == 100
names = []
for _ in range(count):
names.append("{0} {1}".format(fake.first_name(), fake.last_name()))
return names
# Number of employees to generate
employeesCount = 100
def main():
curr_datetime = datetime.datetime.now(pytz.timezone('America/Tijuana'))
curr_datetime = curr_datetime.isoformat('T')
url = 'http://localhost:3100/api/prom/push'
headers = {
'Content-type': 'application/json'
}
payload = {
'streams': [
{
'labels': '{event="action=entry", location="icon-tj"}',
'entries': [
{
'ts': curr_datetime,
'line': "",
}
]
}
]
}
entries = []
for id, employee in enumerate(getEmployees(employeesCount)):
msg = "Employee {1} with badge id {0} registered an entry' ".format(id,employee)
entries.append({
'ts': curr_datetime,
'line': msg,
})
payload["entries"] = entries
payload = json.dumps(payload)
requests.post(url, data=payload, headers=headers)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment