Ping PingArk from Python
You can ping PingArk from Python with nothing but the standard library. Run your task, then open the ping URL. If you already use the requests library, a one line get call works just as well.
Before you start
You need a check and its ping URL. Create one in the dashboard, then copy the ping URL from the check page. New to PingArk? Start with the getting started guide.
Ping on success
Call the ping URL after your job finishes its work. A plain ping means success and re-arms the check for its next run.
import urllib.request # Run your job, then ping. urllib.request.urlopen("https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e", timeout=10)Copy
Report failures, starts and duration
Add a suffix to the ping URL to say more than a plain success. Call these the same way you called the success URL above. The ping API has the full reference.
https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e # success: the job finished, re-arms the timer https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/start # the run started, lets PingArk measure duration https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/fail # an explicit failure, alerts right away https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/log # a timeline note, never alerts https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/$? # a shell exit code: 0 is success, anything else failsCopy
The example uses urllib from the standard library so it runs anywhere with no install. If requests is already in your project, requests.get(url, timeout=10) is equivalent.
Always pass a timeout so a network problem cannot hang your task. PingArk answers a ping in milliseconds, so ten seconds is generous.
To report a failure from an except block, ping the /fail URL. To measure duration, ping /start when the task begins and the success URL when it finishes.
Troubleshooting
- Wrap the ping in its own try and except so a monitoring call can never crash your task. A missed ping is better than a broken job.
- Behind a corporate proxy, set the standard HTTPS_PROXY environment variable so urllib and requests can reach PingArk.