Metadata-Version: 2.1
Name: pylibagent
Version: 0.1.0
Summary: Library for building InfraSonar agents
Home-page: https://github.com/infrasonar/python-libagent
Download-URL: https://github.com/infrasonar/python-libagent/tarball/v0.1.0
Author: Cesbit
Author-email: info@cesbit.com
License: UNKNOWN
Keywords: monitoring,infrasonar,agent
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Linguistic
Description-Content-Type: text/markdown
License-File: LICENSE

[![CI](https://github.com/infrasonar/python-libagent/workflows/CI/badge.svg)](https://github.com/infrasonar/python-libagent/actions)
[![Release Version](https://img.shields.io/github/release/infrasonar/python-libagent)](https://github.com/infrasonar/python-libagent/releases)

# Python library for building InfraSonar Agents

This library is created for building [InfraSonar](https://infrasonar.com) agents.

## Environment variables

Variable                    | Default                       | Description
----------------------------|-------------------------------|-------------------
`TOKEN`                     | _required_                    | Token to connect to.
`ASSET_ID_FILE`             | _required_                    | File where the Agent asset Id is stored _(e.g `/var/infrasonar/asset_id.json`)_.
`API_URI`                   | https://api.infrasonar.com    | InfraSonar API.
`VERIFY_SSL`                | `1`                           | Verify SSL certificate, 0 _(=disabled)_ or 1 _(=enabled)_.
`LOG_LEVEL`                 | `warning`                     | Log level _(error, warning, info, debug)_.
`LOG_COLORIZED`             | `0`                           | Log colorized, 0 _(=disabled)_ or 1 _(=enabled)_.
`LOG_FMT`                   | `%y%m...`                     | Default format is `%y%m%d %H:%M:%S`.


## Usage (Demonized agent)

Building an InfraSonar demonized agent.

```python
from pylibagent.agent import Agent
from pylibagent.check import CheckBase

__version__ = "0.1.0"


class SampleCheck(CheckBase):

    key = "sample"
    interval = 300

    @classmethod
    async def run(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.

```python
import asyncio
from pylibagent.agent import Agent

__version__ = "0.1.0"


async def main():
    version = "0.1.0"
    collector_key = "sample"
    check_key = "sample"

    agent = Agent(collector_key, version)
    await agent.announce()  # optionally, we can provide an initial asset name
    await agent.send_data(check_key, {
        "type": [
            {
                "name": "item",
                "metric": 123
            }
        ]
    })


if __name__ == "__main__":
    asyncio.run(main())
```


