import requests from io import StringIO from lxml import etree from datetime import datetime, timedelta tree = etree.parse(StringIO(requests.get('http://127.0.0.1:8080').text), etree.HTMLParser()) date = tree.xpath('//div[@class = "tab-pane fade in active"]/pre/text()')[4][0:10] cert_date = tree.xpath('//div[@class = "tab-pane fade in active"]/pre/text()')[6][68:78] pki_date = tree.xpath('//div[@class = "tab-pane fade in active"]/pre/text()')[5][45:55] cert_date = datetime.strptime(cert_date,'%Y-%m-%d') pki_date = datetime.strptime(cert_date,'%Y-%m-%d') dd = datetime.today() + timedelta(days=30) try: date = datetime.strptime(date,'%Y-%m-%d') except ValueError: d = None if isinstance(date, datetime): msg = 'WARNING\n' else: if cert_date > dd or pki_date > dd: msg = 'WARNING\n' msg = 'OK\n' with open('utm_lastdoc_check.txt', 'w') as output_file:output_file.write(msg.encode('utf-8'))
#!/usr/bin/python # -*- coding: utf-8 -*- import requests from io import StringIO from lxml import etree from datetime import datetime, timedelta debug = 0 tree = etree.parse(StringIO(requests.get("http://127.0.0.1:8080").text), etree.HTMLParser()) date = etree.tostring(tree.xpath("//div[@class = \"tab-pane fade in active\"]")[0][5][1])[40:50] try: date = datetime.strptime(date,"%Y-%m-%d") except ValueError: date = "" if debug: print "Дата последнего не отправленного документа:", date cert_date = etree.tostring(tree.xpath("//div[@class = \"tab-pane fade in active\"]")[0][7][1])[174:184] cert_date = datetime.strptime(cert_date,"%Y-%m-%d") if debug: print "Дата сертификата FSRAR:", cert_date pki_date = etree.tostring(tree.xpath("//div[@class = \"tab-pane fade in active\"]")[0][6][1])[174:184] pki_date = datetime.strptime(pki_date,"%Y-%m-%d") if debug: print "Дата сертификата ГОСТ:", pki_date dd = datetime.today() - timedelta(days=30) if debug: print "Текущая дата:", dd if isinstance(date, datetime): if debug: print("WARNING: есть не отправленные документы") msg = "WARNING\n" else: if cert_date < dd or pki_date < dd: if debug: print("WARNING: истекает срок действия одного из сертификатов") msg = "WARNING\n" else: if debug: print("OK") msg = "OK\n" with open("utm_lastdoc_check.txt", "w") as output_file:output_file.write(msg.encode("utf-8"))