gs_check -i CheckNetSpeed 使用报错
This commit is contained in:
parent
27510aaca9
commit
b04059e6da
@ -28,6 +28,8 @@ from gspylib.inspection.common.CheckResult import ResultStatus
|
|||||||
from gspylib.common.ErrorCode import ErrorCode
|
from gspylib.common.ErrorCode import ErrorCode
|
||||||
from base_utils.os.net_util import NetUtil
|
from base_utils.os.net_util import NetUtil
|
||||||
|
|
||||||
|
PING_CMD_IPV4 = "ping"
|
||||||
|
PING_CMD_IPV6 = "ping6"
|
||||||
DEFAULT_PARALLEL_NUM = 12
|
DEFAULT_PARALLEL_NUM = 12
|
||||||
DEFAULT_LISTEN_PORT = 20000
|
DEFAULT_LISTEN_PORT = 20000
|
||||||
DEFINE_DELAY_WARNING = 1000
|
DEFINE_DELAY_WARNING = 1000
|
||||||
@ -108,8 +110,13 @@ class CheckNetSpeed(BaseItem):
|
|||||||
global MaxDelayFailFlag
|
global MaxDelayFailFlag
|
||||||
global errorMsg
|
global errorMsg
|
||||||
global serviceIP
|
global serviceIP
|
||||||
cmd = "ping -s 8192 -c 10 -i 0.3 %s|awk -F / '{print $7}'|" \
|
global pingCmd
|
||||||
"awk '{print $1}'" % ip
|
if NetUtil.get_ip_version(ip) == NetUtil.NET_IPV6:
|
||||||
|
pingCmd = PING_CMD_IPV6
|
||||||
|
else:
|
||||||
|
pingCmd = PING_CMD_IPV4
|
||||||
|
cmd = "%s -s 8192 -c 10 -i 0.3 %s|awk -F / '{print $7}'|" \
|
||||||
|
"awk '{print $1}'" % (pingCmd, ip)
|
||||||
output = SharedFuncs.runShellCmd(cmd)
|
output = SharedFuncs.runShellCmd(cmd)
|
||||||
if (output.strip() != ""):
|
if (output.strip() != ""):
|
||||||
try:
|
try:
|
||||||
@ -122,8 +129,8 @@ class CheckNetSpeed(BaseItem):
|
|||||||
return
|
return
|
||||||
if (max_delay > DEFINE_DELAY_WARNING):
|
if (max_delay > DEFINE_DELAY_WARNING):
|
||||||
g_lock.acquire()
|
g_lock.acquire()
|
||||||
string = "%s ping %s max delay is %.3fms" % (
|
string = "%s %s %s max delay is %.3fms" % (
|
||||||
serviceIP, ip, max_delay)
|
serviceIP, pingCmd, ip, max_delay)
|
||||||
errorMsg.append(string)
|
errorMsg.append(string)
|
||||||
g_lock.release()
|
g_lock.release()
|
||||||
|
|
||||||
|
@ -19,19 +19,32 @@
|
|||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
import ipaddress
|
||||||
from base_utils.os.net_util import NetUtil
|
|
||||||
|
|
||||||
listen_ip = "localhost"
|
listen_ip = "localhost"
|
||||||
listen_port = 31111
|
listen_port = 31111
|
||||||
run_mode = 0 # 0:connect, 1:send, 2:recv
|
run_mode = 0 # 0:connect, 1:send, 2:recv
|
||||||
|
NET_IPV4 = "ipv4"
|
||||||
|
NET_IPV6 = "ipv6"
|
||||||
|
|
||||||
|
def get_sockects(ip_address):
|
||||||
|
try:
|
||||||
|
ip = ipaddress.ip_address(ip_address)
|
||||||
|
if ip.version == 6:
|
||||||
|
sockets = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||||
|
return sockets
|
||||||
|
else:
|
||||||
|
sockets = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
return sockets
|
||||||
|
except ValueError:
|
||||||
|
print("ip_address:%s is unvalid ip.")
|
||||||
|
|
||||||
def send_main():
|
def send_main():
|
||||||
try:
|
try:
|
||||||
global listen_ip
|
global listen_ip
|
||||||
global listen_port
|
global listen_port
|
||||||
buf = "this is a test !" * 512 # buf 8192 block
|
buf = "this is a test !" * 512 # buf 8192 block
|
||||||
sockets = NetUtil.get_sockects(listen_ip)
|
sockets = get_sockects(listen_ip)
|
||||||
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||||
print(listen_ip+":"+listen_port)
|
print(listen_ip+":"+listen_port)
|
||||||
while(sockets.connect_ex((listen_ip, int(listen_port))) != 0):
|
while(sockets.connect_ex((listen_ip, int(listen_port))) != 0):
|
||||||
@ -54,7 +67,7 @@ def recv_main():
|
|||||||
try:
|
try:
|
||||||
global listen_ip
|
global listen_ip
|
||||||
global listen_port
|
global listen_port
|
||||||
sockets = NetUtil.get_sockects(listen_ip)
|
sockets = get_sockects(listen_ip)
|
||||||
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
|
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
|
||||||
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||||
sockets.bind((listen_ip, int(listen_port)))
|
sockets.bind((listen_ip, int(listen_port)))
|
||||||
@ -72,7 +85,7 @@ def recv_main():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
def connect_main():
|
def connect_main():
|
||||||
sockets = NetUtil.get_sockects(listen_ip)
|
sockets = get_sockects(listen_ip)
|
||||||
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||||
if sockets.connect_ex((listen_ip, int(listen_port))) != 0:
|
if sockets.connect_ex((listen_ip, int(listen_port))) != 0:
|
||||||
print("Failed to connect %s:%d on %s mode:%m.\n",
|
print("Failed to connect %s:%d on %s mode:%m.\n",
|
||||||
|
@ -467,8 +467,8 @@ class Kerberos():
|
|||||||
# Every 1000 records merged into one"
|
# Every 1000 records merged into one"
|
||||||
ipstring = ""
|
ipstring = ""
|
||||||
for ip in self.__allIps:
|
for ip in self.__allIps:
|
||||||
|
submask_length = NetUtil.get_submask_len(ip)
|
||||||
if not isUninstall:
|
if not isUninstall:
|
||||||
submask_length = NetUtil.get_submask_len(ip)
|
|
||||||
ipstring += " -h 'host all all " \
|
ipstring += " -h 'host all all " \
|
||||||
" %s/%s gss " \
|
" %s/%s gss " \
|
||||||
"include_realm=1 krb_realm=%s'" % \
|
"include_realm=1 krb_realm=%s'" % \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user