Skip to main content

PyngClient to MonitoringService

Project description

PyngClient

About

PyngClient can be used to periodically send a ping to the GenericPingMonitoringing 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

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)

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. Run the .setup.sh script from an active virtualenvironment after installing the dev dependencies:

pipenv install --dev
pipenv shell
./deploy.sh -t test

Note that the version info as specified in setup.py can only be used once for each upload.

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.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

pyngclient-0.0.1-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyngclient-0.0.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.6

File hashes

Hashes for pyngclient-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9b2085a03cabb89ed91800d8e696d5e4d41df5c05f75827b519104f8632c490f
MD5 cf36b050a1b234fa2078651523104bde
BLAKE2b-256 9d087001b486f2fcb5b46d350c04a88d4d20e29a25db22db1b1e1222b5497c8c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyngclient-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.6

File hashes

Hashes for pyngclient-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 52ea2fec83c7e1fb58b66f2123c42c92283d05cbf20ee2c4cc79d8e2b1d635d9
MD5 1f22c0f61b881ee85f1cf4f269c61a09
BLAKE2b-256 3867ebfbd65c7358199cfe199017e4d88397feea2b3f2a2feaa21f277e8ef902

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