-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
127 lines (110 loc) · 4.54 KB
/
main.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
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
# This is a sample Python script.
# Press Mayús+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import platform
import netifaces
def serverdata():
import platform
hostname=platform.node()
return(hostname)
def validatestatusc():
import docker
import schedule
import time, os
import psutil
from colorama import init, Fore, Back, Style
from pythonping import ping
import netifaces
# Define tags to review if the container it is running.
incodef="incodetech/ms-incodesmile-recognition-service:cpu"
incodeinew="incodetech/incode-ine-gateway"
incodeb="incodetech/nginx-loadbalancer"
# Define counters per each kind of container.
incodefc=0
incodeinewc=0
incodebc=0
#process to validate how many contairner are running.
client=docker.from_env()
for container in client.containers.list():
runc=container.attrs
runc=str(runc)
#print(runc )
if runc.find(incodef) != -1:
incodefc+=1
elif runc.find(incodeinew) != -1:
incodeinewc+=1
elif runc.find(incodeb) != -1:
incodebc+=1
init(autoreset=True)
alertfc="Contenedores de incodesmile corriendo: " + str(incodefc)
alertinew="Contenedores de incode ine gateway correindo: " + str(incodeinewc)
alertb="Contenedores de incode loadbalancer: " + str(incodebc)
if incodefc == 2:
alertfc=alertfc + "\t\t\tEs el numero correcto de contenedores."
print(Style.BRIGHT + Back.GREEN + Fore.WHITE + alertfc)
else:
alertfc = alertfc + "\t\t\tNO es el numero correo de contenedores."
print(Style.BRIGHT + Back.RED + Fore.WHITE + alertfc)
if incodeinewc == 1:
alertinew=alertinew + "\t\t\tEs el numero correcto de contenedores."
print(Style.BRIGHT + Back.GREEN + Fore.WHITE + alertinew)
else:
alertinew = alertinew + "\t\t\tNO es el numero correo de contenedores."
print(Style.BRIGHT + Back.RED + Fore.WHITE + alertinew)
if incodebc == 1:
alertb=alertb + "\t\t\t\tEs el numero correcto de contenedores."
print(Style.BRIGHT + Back.GREEN + Fore.WHITE + alertb)
else:
alertb = alertb + "\t\t\t\tNO es el numero correo de contenedores."
print(Style.BRIGHT + Back.RED + Fore.WHITE + alertb)
gws = netifaces.gateways()
for key, value in gws.items():
gwp=ping(gws['default'][netifaces.AF_INET][0], count=10)
if gwp.rtt_avg_ms < 0.1:
print(Style.BRIGHT+Back.GREEN+Fore.WHITE+"Se tiene acceso al GW Local")
else:
print(Style.BRIGHT + Back.RED + Fore.WHITE + "No se tiene acceso al GW Local")
f=open("network.conf","r")
while True:
count =+ 1
line=f.readline()
if not line:
break
service,data=line.split("=")
service=str(service).strip()
data = str(data).strip()
if service.find('INEGW') != -1:
inewp=ping(data,count=10)
if inewp.rtt_avg_ms < 0.1:
gwine="Se tiene acceso al GW de la red INE "+data
print(Style.BRIGHT + Back.GREEN + Fore.WHITE + gwine )
else:
gwine="No alcanza el GW o tiempos muy altos " + data
print(Style.BRIGHT + Back.RED + Fore.WHITE+ gwine)
if service.find('INCODEVPN') != -1:
inewp=ping(data,count=10)
if inewp.rtt_avg_ms < 10:
gwinc="Se tiene acceso al GW de la VPN INCODE "+data
print(Style.BRIGHT + Back.GREEN + Fore.WHITE + gwinc )
else:
gwinc="No alcanza el VPN de Incode o tiempos muy altos " + data
print(Style.BRIGHT + Back.RED + Fore.WHITE+ gwinc)
def print_menu(hostname):
import platform
# Use a breakpoint in the code line below to debug your script.
print(f'Consola de validación de servicios INCODE en el INE, Nodo - {hostname}.\n')
print("El menu tiene la finalida de facilitar el soporte remoto de los servidores de comparación de incode.\n")
print("Opciones:\n")
print("1. Revisar estado de servicio(s).\n")
print("2. Reinicar servidor.\n")
print("3. Revisar disponibilidad de disco.\n")
print("4. Recolectar bitacoras.")
#menu=input("Indica la opción desada: ")
menu="0"
if menu == "0":
validatestatusc()
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
host=serverdata()
print_menu(host)
# See PyCharm help at https://www.jetbrains.com/help/pycharm/