-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_testipv6
155 lines (124 loc) · 5.22 KB
/
check_testipv6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python3
#-------------------------------------------------------------------------------
import os
import sys
import time
import subprocess
import argparse
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#-------------------------------------------------------------------------------
_candebug = False
def candebug():
global _candebug
return _candebug
def setcandebug(value):
global _candebug
_candebug = value
def infomsg(msg):
if candebug() == True:
print(msg, flush=True)
def exitnagios(status,message):
if status=="OK":
exitcode = 0
elif status=="WARNING":
exitcode = 1
elif status=="CRITICAL":
exitcode = 2
elif status=="UNKNOWN":
exitcode = 3
else:
exitcode = 4
print(status+": "+message, flush=True)
sys.exit(exitcode)
#-------------------------------------------------------------------------------
def generatedriver(proxy):
chrome_options = Options()
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--disk-cache-size=0")
chrome_options.add_argument("--media-cache-size=0")
chrome_options.add_argument("--enable-features=EphemeralGuestProfilesOnStartup")
chrome_options.add_argument("--headless=new")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--in-process-gpu")
chrome_options.add_argument("--use-gl=angle")
chrome_options.add_argument("--use-angle=swiftshader-webgl")
chrome_options.add_argument("--proxy-server="+proxy)
chrome_service = webdriver.ChromeService(executable_path="/usr/bin/chromedriver")
driver = webdriver.Chrome(options=chrome_options,service=chrome_service)
#driver.implicitly_Wait(10, TimeUnit.SECONDS)
return driver
def check_page_loaded(driver):
#self.log.info("Checking if {} page is loaded.".format(self.driver.current_url))
page_state = driver.execute_script("return document.readyState;")
return page_state == "complete"
def wait_page_loaded(driver):
timestamp = time.time()
while True:
if check_page_loaded(driver) == True:
break
if time.time() - timestamp > 20:
break
#-------------------------------------------------------------------------------
def extractvalue(driver,entryname):
element = driver.find_element(By.XPATH, "//td[text()=\""+entryname+"\"]/following-sibling::td")
infomsg(value)
return value
def dotestipv6call(proxy):
try:
driver = generatedriver(proxy)
wait = WebDriverWait(driver,10)
action=ActionChains(driver)
infomsg("browser OK")
url = "https://test-ipv6.com/"
driver.get(url)
infomsg("asking for navigating "+url)
time.sleep(5)
wait_page_loaded(driver)
infomsg("page loaded")
try:
wait.until(EC.text_to_be_present_in_element((By.ID, "debugtable"),"Your readiness score"))
except Exception as e:
pass
finally:
infomsg("found element rediness score")
try:
resume = driver.find_element(By.ID, "debugtable")
except Exception as e:
exitnagios("WARNING","cannot find result element")
if resume == None:
exitnagios("WARNING","no result from page")
infomsg("test with results")
rawresult = resume.text
parts = rawresult.split()
marks = parts[3]
infomsg("raw marks is '"+marks+"'")
grading = marks.split("/")
currentmark = int(grading[0])
totalmarks = int(grading[1])
if currentmark == 0:
exitnagios("CRITICAL","The result of the test is "+str(currentmark)+"/"+str(totalmarks)+" | result="+str(currentmark)+" best="+str(totalmarks))
elif currentmark == totalmarks:
exitnagios("OK","The result of the test is "+str(currentmark)+"/"+str(totalmarks)+" | result="+str(currentmark)+" best="+str(totalmarks))
else:
exitnagios("WARNING","The result of the test is "+str(currentmark)+"/"+str(totalmarks)+" | result="+str(currentmark)+" best="+str(totalmarks))
except Exception as e:
exitnagios("CRITICAL","unexpected error during the check - "+str(e))
#-------------------------------------------------------------------------------
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--proxy", dest="proxy", default="", help="use a proxy")
parser.add_argument("-®", "--debug", action="store_true", dest="debug", default=False, help="be more verbose")
args = parser.parse_args()
setcandebug(args.debug)
dotestipv6call(args.proxy)
if __name__ == "__main__":
main()
#-------------------------------------------------------------------------------