Skip to main content

CI Release Version

Python library for building InfraSonar Services

This library is created for building InfraSonar services.

Environment variable

You might want to implement configuration which applies for all assets in all containers, but still don't want to hard-code this setting in your check. Think for example about a API URL which is always the same, except maybe for a development environment.

The following environment variable are required for a service to work and are always set by InfraSonar:

Environment variable Default Description
THINGSDB_HOSTLIST thingsdb:9200 ThingsDB host list.
THINGSDB_TOKEN empty Token for authentication (required).
THINGSDB_SCOPE //data Collection scope for data.
HUB_HOST hub Hub host
HUB_PORT 8700 Hub port
SLEEP_TIME 2 Sleep time in seconds in each iteration.
LOG_LEVEL warning Log level (error, warning, info, debug).
LOG_COLORIZED 0 Either 0 (=disabled) or 1 (=enabled).
LOG_FMT %y%m... Default format is %y%m%d %H:%M:%S.
DRY_RUN empty If enabled, result data will be printed to stdout instead of send to the hub.

Usage

from asyncio import AbstractEventLoop
from libservice import start, Asset, CheckBase


class MyCheck(CheckBase):
    # Use CheckBaseMulti if you want to perform checks for multiple assets
    # combined. Sometimes this can be useful as you might be able to combine
    # multiple assets in a single request.
    key = 'my_check'

    @classmethod
    async def run(cls, ts: float, asset: Asset) -> tuple[
            dict | None, dict | None]:
        # Return with the state and optionally an error dict which can be
        # created using CheckException(my_error_message).to_dict().
        # Alternatively, you can rase a CheckException. The return error is
        # especially useful with CheckBaseMulti where only a single asset might
        # fail or to return an error together with the result.
        # For example:
        #
        #   return state, CheckException('Incomplete result').to_dict()
        #
        return {
          'my_type': [
            {'name': 'my_item'}
          ]
        }, None


def start_func(loop: AbstractEventLoop):
    pass  # optional init function

def close_func(loop: AbstractEventLoop):
    pass  # optional close function


if __name__ == '__main__':
    start(
      collector_key='my_server',
      version='0.1.0',
      checks=(MyCheck, ),
      start_func=start_func,
      close_func=close_func,
      no_count=False)  # When True, the check(s) do not count (counter + lastseen)

ASCII item names

InfraSonar requires each item to have a unique name property. The value for name must be a string with ASCII compatible character. When your name is not guaranteed to be ASCII compatible, the following code replaces the incompatible characters with question marks (?):

name = name.encode('ascii', errors='replace').decode()

Check is an asset Id is scheduled

In some cases, the dmarc service as an example, you might want to check if an asset Id is scheduled and ask for the container Id. As the Asset() instance is only available during the check process, you need to verify this in a different way.

from libservice.serviceroom import service_room

container_id = service_room.get_container_id(asset_id)
if container_id is None:
    # missing asset ID
    ...

Metadata

Release files for libservice 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for libservice 1.0.3
File Size Uploaded
libservice-1.0.3.tar.gz 28.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for libservice 1.0.3
File Interpreter ABI Platform
libservice-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 59.1 kB

Release files / libservice-1.0.3.tar.gz

Download URL libservice-1.0.3.tar.gz
Size 28.5 kB
Tags Source
SHA-256 checksum
How to use checksums
637d6a814a3ab32a878583f42f11942a1c2aab0612176703e40172144cc268da
BLAKE2b-256 checksum
How to use checksums
cba80e1a00ad9eb5ce2921cb87b1050e8cc62dc3b5068be6d1616aae57db6a44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / libservice-1.0.3-py3-none-any.whl

Download URL libservice-1.0.3-py3-none-any.whl
Size 30.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7354e6c0bc024e9637df73bcb958175843eaed3a3f908e1bce1a9dd53edbb040
BLAKE2b-256 checksum
How to use checksums
b6cd5940697786646f1c1ad40ea5ee99dddb84bd7bd19da02bac09edd5b322e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

1 release file

1.0.0

1 release file

0.1.17

1 release file

0.1.16

1 release file

0.1.15

1 release file

0.1.14

1 release file

0.1.13

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page