# Using Python 3 standard library:
import socket
import urllib.request

try:
    urllib.request.urlopen("{{ ping_url }}", timeout=10)
except socket.error as e:
    # Log ping failure here...
    print("Ping failed: %s" % e)