check_hls: Log requests longer than 5 seconds as timeout.
This commit is contained in:
@@ -2,6 +2,6 @@
|
|||||||
title = HLS m3u8 Check
|
title = HLS m3u8 Check
|
||||||
author = Markus Birth
|
author = Markus Birth
|
||||||
description = Checks m3u8 playlists and segments for availability.
|
description = Checks m3u8 playlists and segments for availability.
|
||||||
version = 2017.11.01.1
|
version = 2017.11.30.1
|
||||||
version.min_required = 1.2.8p2
|
version.min_required = 1.2.8p2
|
||||||
download_url = https://github.com/mbirth/check_mk-plugins
|
download_url = https://github.com/mbirth/check_mk-plugins
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import datetime
|
|||||||
import pytz
|
import pytz
|
||||||
import html
|
import html
|
||||||
import re
|
import re
|
||||||
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ class UrlLoader():
|
|||||||
def do_request(self, req):
|
def do_request(self, req):
|
||||||
try:
|
try:
|
||||||
start = datetime.datetime.now()
|
start = datetime.datetime.now()
|
||||||
res = urllib.request.urlopen(req)
|
res = urllib.request.urlopen(req, timeout=5)
|
||||||
end = datetime.datetime.now()
|
end = datetime.datetime.now()
|
||||||
except urllib.error.HTTPError as err:
|
except urllib.error.HTTPError as err:
|
||||||
reason = err.reason
|
reason = err.reason
|
||||||
@@ -98,6 +99,8 @@ class UrlLoader():
|
|||||||
return err.code, reason, -1
|
return err.code, reason, -1
|
||||||
except urllib.error.URLError as err:
|
except urllib.error.URLError as err:
|
||||||
return -1, err.reason, -1
|
return -1, err.reason, -1
|
||||||
|
except socket.timeout as err:
|
||||||
|
return -1, "Timeout (5 seconds)", -1
|
||||||
|
|
||||||
diff = end - start
|
diff = end - start
|
||||||
diff = round(int(diff.microseconds) / 1000)
|
diff = round(int(diff.microseconds) / 1000)
|
||||||
@@ -107,7 +110,7 @@ class UrlLoader():
|
|||||||
#req = urllib.request.Request(url=url, method="HEAD")
|
#req = urllib.request.Request(url=url, method="HEAD")
|
||||||
req = urllib.request.Request(url=url) # work around HTTP 405 "Method not allowed"
|
req = urllib.request.Request(url=url) # work around HTTP 405 "Method not allowed"
|
||||||
status, res, diff = self.do_request(req)
|
status, res, diff = self.do_request(req)
|
||||||
return status, res.info(), diff
|
return status, res, diff
|
||||||
|
|
||||||
def get_content(self, url):
|
def get_content(self, url):
|
||||||
req = urllib.request.Request(url=url)
|
req = urllib.request.Request(url=url)
|
||||||
|
|||||||
Reference in New Issue
Block a user