Skip to content

Repository files navigation

CIRelease Version

Python library for building InfraSonar Agents

This library is created for building InfraSonar agents.

Installation

pip install pylibagent

Environment variables

VariableDefaultDescription
TOKENrequiredToken to connect to.
ASSET_IDrequiredAsset Id or file location where the Agent asset Id is stored (e.g 123 or /var/infrasonar/asset_id.json).
API_URIhttps://api.infrasonar.comInfraSonar API.
VERIFY_SSL1Verify SSL certificate, 0 (=disabled) or 1 (=enabled).
LOG_LEVELwarningLog level (error, warning, info, debug).
LOG_COLORIZED0Log colorized, 0 (=disabled) or 1 (=enabled).
LOG_FMT%y%m...Default format is %y%m%d %H:%M:%S.
DISABLED_CHECKS_CACHE_AGE900Time in seconds before we poll again for reading the disabled checks.

Usage (Demonized agent)

Building an InfraSonar demonized agent.

frompylibagent.agentimportAgentfrompylibagent.checkimportCheckBase__version__="0.1.0"classSampleCheck(CheckBase):
key="sample"interval=300@classmethodasyncdefrun(cls):
return {
"type": [
{
"name": "item",
"metric": 123
}
]
}
if__name__=="__main__":
collector_key="sample"version="0.1.0"checks= [SampleCheck]
Agent(collector_key, version).start(checks)

Usage (Non-demonized agent)

Building an InfraSonar agent.

importasynciofrompylibagent.agentimportAgent__version__="0.1.0"asyncdefmain():
version="0.1.0"collector_key="sample"check_key="sample"agent=Agent(collector_key, version)
awaitagent.announce() # optionally, we can provide an initial asset nameawaitagent.send_data(check_key, {
"type": [
{
"name": "item",
"metric": 123
}
]
})
if__name__=="__main__":
asyncio.run(main())

Known issues

It might happen that a RuntimeError, "can't create new thread" is raised when using the docker agent inside docker. To solve this issue, add privileged: true to your service in docker compose or start docker with --privileged.

About

Python library for building InfraSonar agents

Resources

Code of conduct

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages