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 base_utils.os.net_util import NetUtil
|
||||
|
||||
PING_CMD_IPV4 = "ping"
|
||||
PING_CMD_IPV6 = "ping6"
|
||||
DEFAULT_PARALLEL_NUM = 12
|
||||
DEFAULT_LISTEN_PORT = 20000
|
||||
DEFINE_DELAY_WARNING = 1000
|
||||
@ -108,8 +110,13 @@ class CheckNetSpeed(BaseItem):
|
||||
global MaxDelayFailFlag
|
||||
global errorMsg
|
||||
global serviceIP
|
||||
cmd = "ping -s 8192 -c 10 -i 0.3 %s|awk -F / '{print $7}'|" \
|
||||
"awk '{print $1}'" % ip
|
||||
global pingCmd
|
||||
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)
|
||||
if (output.strip() != ""):
|
||||
try:
|
||||
@ -122,8 +129,8 @@ class CheckNetSpeed(BaseItem):
|
||||
return
|
||||
if (max_delay > DEFINE_DELAY_WARNING):
|
||||
g_lock.acquire()
|
||||
string = "%s ping %s max delay is %.3fms" % (
|
||||
serviceIP, ip, max_delay)
|
||||
string = "%s %s %s max delay is %.3fms" % (
|
||||
serviceIP, pingCmd, ip, max_delay)
|
||||
errorMsg.append(string)
|
||||
g_lock.release()
|
||||
|
||||
|
@ -19,19 +19,32 @@
|
||||
import socket
|
||||
import time
|
||||
import sys
|
||||
|
||||
from base_utils.os.net_util import NetUtil
|
||||
import ipaddress
|
||||
|
||||
listen_ip = "localhost"
|
||||
listen_port = 31111
|
||||
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():
|
||||
try:
|
||||
global listen_ip
|
||||
global listen_port
|
||||
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)
|
||||
print(listen_ip+":"+listen_port)
|
||||
while(sockets.connect_ex((listen_ip, int(listen_port))) != 0):
|
||||
@ -54,7 +67,7 @@ def recv_main():
|
||||
try:
|
||||
global listen_ip
|
||||
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_KEEPALIVE, 1)
|
||||
sockets.bind((listen_ip, int(listen_port)))
|
||||
@ -72,7 +85,7 @@ def recv_main():
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
def connect_main():
|
||||
sockets = NetUtil.get_sockects(listen_ip)
|
||||
sockets = get_sockects(listen_ip)
|
||||
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||
if sockets.connect_ex((listen_ip, int(listen_port))) != 0:
|
||||
print("Failed to connect %s:%d on %s mode:%m.\n",
|
||||
|
@ -467,8 +467,8 @@ class Kerberos():
|
||||
# Every 1000 records merged into one"
|
||||
ipstring = ""
|
||||
for ip in self.__allIps:
|
||||
submask_length = NetUtil.get_submask_len(ip)
|
||||
if not isUninstall:
|
||||
submask_length = NetUtil.get_submask_len(ip)
|
||||
ipstring += " -h 'host all all " \
|
||||
" %s/%s gss " \
|
||||
"include_realm=1 krb_realm=%s'" % \
|
||||
|
Loading…
x
Reference in New Issue
Block a user