forked from ContainerSolutions/k8s-deployment-strategies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
curl.py
81 lines (65 loc) · 2.5 KB
/
curl.py
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
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import requests as rq
import time
import sys
from colorama import Fore, Back, Style
# parameters
AGIC_IP = sys.argv[1]
web_link="http://" + str(AGIC_IP)
HEADERS = {}
READTIMEOUT_COUNT = 0
CONNECTTIMEOUT_COUNT = 0
HTTPERROR_COUNT = 0
UNKNOWNERROR_COUNT = 0
output = 0
if len(sys.argv) == 3:
HEADER_HOST = sys.argv[2]
HEADERS['Host'] = HEADER_HOST
def print_green_on_default(text): return print(Fore.GREEN + text)
def print_blue_on_default(text): return print(Fore.BLUE + text)
def print_red_on_default(text): return print(Fore.RED + text)
def print_yellow_on_default(text): return print(Fore.YELLOW + text)
def main():
global HEADERS
global READTIMEOUT_COUNT
global CONNECTTIMEOUT_COUNT
global HTTPERROR_COUNT
global UNKNOWNERROR_COUNT
global output
while True:
try:
if not HEADERS:
output = rq.get(web_link, verify=False, timeout=(1, 1))
else:
output = rq.get(web_link, verify=False, timeout=(1, 1), headers=HEADERS)
except rq.exceptions.ConnectTimeout:
CONNECTTIMEOUT_COUNT += 1
print_red_on_default("Error: Connect Timeout - count: %s" % (str(CONNECTTIMEOUT_COUNT)))
except rq.exceptions.ReadTimeout:
READTIMEOUT_COUNT += 1
print_red_on_default("Error: Read Timeout - count: %s" % (str(READTIMEOUT_COUNT)))
except rq.exceptions.RequestException as e:
UNKNOWNERROR_COUNT += 1
print_red_on_default("Error: %s - count: %s" % (e + str(UNKNOWNERROR_COUNT)))
if output.status_code == 200:
result = str.strip(output.text)
if "v1.0.0" in result:
print_green_on_default(result)
elif "v2.0.0" in result:
print_blue_on_default(result)
time.sleep(0.1)
else:
HTTPERROR_COUNT += 1
print_red_on_default("Error: Status code is %s - count: %s" % (str(output.status_code), str(HTTPERROR_COUNT)))
continue
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
# print out the number of errors
print("")
print_yellow_on_default("The Amount of Read Timeout: " + str(READTIMEOUT_COUNT))
print_yellow_on_default("The Amount of Connect Timeout: " + str(CONNECTTIMEOUT_COUNT))
print_yellow_on_default("The Amount of HTTP Error: " + str(HTTPERROR_COUNT))
print_yellow_on_default("The Amount of Unknown Error: " + str(UNKNOWNERROR_COUNT))