-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import time | ||
import logging | ||
import urllib.request | ||
|
||
|
||
logging.basicConfig( | ||
format='%(asctime)s %(levelname)-8s %(message)s', | ||
level=logging.INFO, | ||
datefmt='%Y-%m-%d %H:%M:%S') | ||
|
||
|
||
def request(url): | ||
try: | ||
response = urllib.request.urlopen(url) | ||
logging.info(response.read().decode()) | ||
except urllib.error.HTTPError as error: | ||
logging.error(error) | ||
|
||
|
||
if len(sys.argv) < 2: | ||
print("Please specify URL") | ||
print(" EXAMPLE: check.py http://your/url") | ||
exit(1) | ||
|
||
|
||
URL = sys.argv[1] | ||
print("Checking {}\n".format(URL)) | ||
|
||
while True: | ||
request(URL) | ||
time.sleep(1) |