Skip to content

Commit

Permalink
Merge pull request #1 from dnmvisser/dv_support_useragent
Browse files Browse the repository at this point in the history
Support user agent
  • Loading branch information
dnmvisser authored Jul 26, 2022
2 parents 862e20a + dfa9cc9 commit 08a1e59
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions check_time_http
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ try:
'Check time offset of the HTTP "Date" response header against the local time')
parser.add_argument('--url', '-u',
help='the URL to check', required=True)
parser.add_argument('--useragent', '-a',
help='the User-Agent string to use', required=False, default='check_time_http')
# https://kantarainitiative.github.io/SAMLprofiles/saml2int.html#_clock_skew
parser.add_argument('--warn', '-w',
help='Offset to result in warning (seconds, default 180)',
Expand Down Expand Up @@ -73,20 +75,27 @@ try:
args = parser.parse_args()

url = args.url
useragent = args.useragent
warn = args.warn
crit = args.crit
timeout = args.timeout
verify = args.verify
verbose = args.verbose

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
req = requests.head(url, timeout=timeout, verify=verify)
req = requests.head(
url,
timeout=timeout,
verify=verify,
headers={'User-Agent': useragent}
)

# Date with time zone
utc_now = pytz.utc.localize(datetime.datetime.utcnow().replace(microsecond=0))

if 'Date' in req.headers:
http_date = email.utils.parsedate_to_datetime(req.headers['Date'])
# this is case insensitive
if 'date' in req.headers:
http_date = email.utils.parsedate_to_datetime(req.headers['date'])
offset = int((http_date - utc_now).total_seconds())
message = "Offset is {0} seconds".format(offset)
if(verbose):
Expand Down

0 comments on commit 08a1e59

Please sign in to comment.