Package: pyngclient
PyngClientAboutPyngClient can be used to periodically send a ping to the GenericPingMonitoring service.FeaturesSupport python 3.6+Send a 'GenericPing' update to the GenericPingMonitoringService.Automatically create a new ping monitor if it does not exist yetInstallationpipinstallpyngclient# Directly from our private repopipenvinstall-egit+ssh://git@github.com/Connecterra/PyngClient.git#egg=pyngclient# or with pippython-mpipinstallgit+ssh://git@github.com/Connecterra/PyngClient.git#egg=pyngclientNotesPyngClient 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 theoverride_ping_timeoutflag to True.The alertFrequencyTimeout (ping timeout) is always at least 5minutes (300 seconds)How to useBasic exampleThe 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="",frompyngclientimportGenericPingClient# Initialize the pingClientclient=GenericPingClient()# Send it a ping, and set the alertFrequencyTimeout to 1 hourclient.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 environmentYou can integrate a pyngclient in your code but make all its operations a no-op by setting envvarpingServiceDisabledtoTrue.
This might be useful for local development.Instantiation behaviorIn 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 applicationPyngClient also supports long running applications and async behavior.
Instead of calling thesend_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.)frompyngclientimportGenericPingClientimportasyncioimportloggingclient=GenericPingClient()logging.basicConfig(level=logging.INFO)asyncdefmain(loop):loop.create_task(client.run_async("testMonitor","PT5M","PT1H"))whileTrue:logging.info("Running...")awaitasyncio.sleep(10)if__name__=="__main__":loop=asyncio.get_event_loop()loop.run_until_complete(main(loop))MaintenancePackage 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".