Async single threaded connector to Splunk HEC using an asyncio session
Project description
Splunk HEC for Home Assistant
A Splunk HTTP Event Collector library that follows best practices by opening a single connection to Splunk, and reuses it. When sending large or high volumes of events, or Splunk is slow, the events are batched together. This also allows events to be resent in the case of failures, as they are simply returned to the queue.
Requires you create an aiohttp Client Session, or reuse your applications existing one. From Home Assistant this would be homeassistant.helpers.aiohttp_client.async_get_clientsession
Methods
hass_splunk(session,token,host,port=8088,use_ssl=True,verify_ssl=True,endpoint="collector/event",timeout=5)
Session, token, and host are required, all other parameters are optional, and will be set to defaults shown.
check(connectivity=True, token=True, busy=True)
Returns True if the parameter conditions are okay, False if any fail or any other error is raised. You can selectively ignore certain conditions by setting them to False.
queue(payload, send=True)
The String or Dictionary to be sent to Splunk. By default it will be sent as soon as possible, but you can instead set send=False and it only be queued.
send()
The sends whatever data is in the queue, is what queue() uses internally when send=True.
Example
import asyncio
import aiohttp
import time
from hass_splunk import hass_splunk
async def main():
async with aiohttp.ClientSession() as session:
splunk = hass_splunk(
session=session,
host="http-inputs-stack.splunkcloud.com",
use_ssl=True,
verify_ssl=True,
token="private",
)
print(await splunk.check(connectivity=True, token=True, busy=True))
await splunk.queue(
{
"time": time.time(),
"host": "name",
"event": {
"meta": "TEST",
},
},
send=False,
)
await splunk.send()
asyncio.run(main())
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hass_splunk-0.1.2.tar.gz
.
File metadata
- Download URL: hass_splunk-0.1.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b987399dfc473bd0e3f543b37518bf0f463ef432775858e24dcf3b7dd859aec8 |
|
MD5 | 949e91cf86bac21dae53717dd61d96f7 |
|
BLAKE2b-256 | c55317b6e7952723c71f70cb455ec9d4f9b54414d2d9ea0fb147846a1980a0dc |
File details
Details for the file hass_splunk-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: hass_splunk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cea5906d181c64d38ac67f4d60b7e3bd3dfc823485f199aeab35654c19dff13 |
|
MD5 | 2eb03b9ce0c04c0ae3b15b82860c240f |
|
BLAKE2b-256 | 424bce8e238913d02eb8e2fcfa3f2f29595ab1a74f758fc8de6174b20db29170 |