Skip to main content

PyngClient to MonitoringService

Project description

PyngClient

About

PyngClient can be used to periodically send a ping to the GenericPingMonitoring service.

Features

  • Support python 3.6+
  • Send a 'GenericPing' update to the GenericPingMonitoringService.
  • Automatically create a new ping monitor if it does not exist yet

Installation

pip install pyngclient

# Directly from our private repo
pipenv install -e git+ssh://git@github.com/Connecterra/PyngClient.git#egg=pyngclient
# or with pip
python -m pip install git+ssh://git@github.com/Connecterra/PyngClient.git#egg=pyngclient

Notes

  • PyngClient is supported for python 3.6+ (due to usage of f-strings)
  • Automatic re-authentication after token expiration is not supported if another odata client is used to authenticate and the token is passed in.
  • By default, the ping will not update the server's alertTimeoutFrequency (ping timeout) after initial creation. To force modifying the interval from your application, include the override_ping_timeout flag to True.
  • The alertFrequencyTimeout (ping timeout) is always at least 5minutes (300 seconds)

How to use

Basic example

The most basic example assumes you have odataUrl, authUrl, username and password set as environment variables (for example with a .env file if using pipenv)

oDataUrl="https://odata.yourdomain.com",
authUrl="https://auth.yourdomain.com",
authUsername="",
authPassword="",
from pyngclient import GenericPingClient

# Initialize the pingClient
client = GenericPingClient()

# Send it a ping, and set the alertFrequencyTimeout to 1 hour
client.send_ping("YourMonitorName", 3600)

# Alternatively, ISO Durations are supported as an alertFrequencyTimeout as well.
client.send_ping("YourMonitorName, "PT1H")

# By default, the frequencyTimeout will not update after creation of the monitor.
# If it is for some reason changed at the server, the definition in your code will not update it.
# This behavior can be overridden by setting the override_timeout flag:
client.send_ping("YourMonitorName, "PT1H", override_timeout=True)

Disabling pings in local environment

You can integrate a pyngclient in your code but make all its operations a no-op by setting envvar pingServiceDisabled to True. This might be useful for local development.

Instantiation behavior

In additiona to environment variables, it is possible to initialize the GenericPingClient variables instead. Also, if your application already has odata authentication, and you have a authentication token, it can be passed in directly and used without reauthentication.

# Authenticate without using env vars:
client = GenericPingClient(username=sername, password=password, odata_url=odata_url, auth_url=auth_url)

# Instantiate the client with an already valid auth token
# Note that this method will not allow re-authentication to happen automatically after token expiration as GenericPingClient will not be aware of it.
client = GenericPingClient(token=auth_token)

Usage in long running application

PyngClient also supports long running applications and async behavior. Instead of calling the send_ping() command manually in your code, you can at an async task. Below is the minimum boilerplate in combination with asyncio. (with added logging, just to see what's going on.)

from pyngclient import GenericPingClient
import asyncio
import logging

client = GenericPingClient()
logging.basicConfig(level=logging.INFO)


async def main(loop):
    loop.create_task(client.run_async("testMonitor", "PT5M", "PT1H"))

    while True:
        logging.info("Running...")
        await asyncio.sleep(10)


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main(loop))

Maintenance

Package is uploaded on PyPI when pushing a new tag to github. The version tag should be a valid semantic version tag without pre or suffixes, such as "0.0.1".

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

pyngclient-0.0.3.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

pyngclient-0.0.3-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file pyngclient-0.0.3.tar.gz.

File metadata

  • Download URL: pyngclient-0.0.3.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pyngclient-0.0.3.tar.gz
Algorithm Hash digest
SHA256 f7195f1db21b865a92e99499c4c4d14050ab652af472620d7119118d61241c95
MD5 fabd90707029a8ce994713ae3078f645
BLAKE2b-256 fd8fc0ce3ff258dd9b80f39ad809e97f42f6c06ca3f80ebacf660b3521db313a

See more details on using hashes here.

File details

Details for the file pyngclient-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyngclient-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pyngclient-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e49102c12500fe9cbf65a92c51224ac89da057ffbb8e55a64780f3a378f47f54
MD5 d51e6fcd94d16658fc21123a308510b9
BLAKE2b-256 bf048066ca5ebb1c31ace13f7e46b6a9aeec225f3f7a8d6d08984a83d03cf114

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page