black it
This commit is contained in:
parent
35631e4bc8
commit
8c6170d707
@ -26,6 +26,7 @@ WARNING = 1
|
||||
CRITICAL = 2
|
||||
UNKNOWN = 3
|
||||
|
||||
|
||||
def main():
|
||||
args = Get_Args()
|
||||
log.debug(f"args: {args}")
|
||||
@ -44,7 +45,6 @@ def main():
|
||||
|
||||
edevau = True
|
||||
|
||||
|
||||
# Create a TCP socket to OpenVPN management
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.connect((args.HOST, args.PORT))
|
||||
@ -71,58 +71,63 @@ def main():
|
||||
if args.cn:
|
||||
# search for a client
|
||||
i = 0
|
||||
performancedata['clients'] = 0
|
||||
performancedata['in'] = 0
|
||||
performancedata['out'] = 0
|
||||
for cn in clients['Common Name']:
|
||||
if re.findall(args.cn,cn):
|
||||
performancedata["clients"] = 0
|
||||
performancedata["in"] = 0
|
||||
performancedata["out"] = 0
|
||||
for cn in clients["Common Name"]:
|
||||
if re.findall(args.cn, cn):
|
||||
message += f"Client {clients['Common Name'][i]} connected since: {clients['Connected Since'][i]}"
|
||||
performancedata['clients'] += 1
|
||||
performancedata['in'] = clients['Bytes Received'][i]
|
||||
performancedata['out'] = clients['Bytes Sent'][i]
|
||||
performancedata['connectedsince'] = clients['Connected Since (time_t)'][i]
|
||||
performancedata["clients"] += 1
|
||||
performancedata["in"] = clients["Bytes Received"][i]
|
||||
performancedata["out"] = clients["Bytes Sent"][i]
|
||||
performancedata["connectedsince"] = clients["Connected Since (time_t)"][
|
||||
i
|
||||
]
|
||||
i += 1
|
||||
if performancedata['clients'] == 0:
|
||||
if performancedata["clients"] == 0:
|
||||
message += f"No Clients found matching {args.cn}."
|
||||
|
||||
STATUS = WARNING
|
||||
|
||||
elif args.route:
|
||||
# search for a specified route
|
||||
gtfo(UNKNOWN,"Not implemented yet.")
|
||||
gtfo(UNKNOWN, "Not implemented yet.")
|
||||
elif args.addr:
|
||||
# search for a specified route
|
||||
gtfo(UNKNOWN, "Not implemented yet.")
|
||||
else:
|
||||
# default: report Clientcount
|
||||
clientcount = len(clients['Common Name'])
|
||||
clientcount = len(clients["Common Name"])
|
||||
message += f"Clients connected: {clientcount}"
|
||||
if not args.nodetails:
|
||||
message += f" {clients['Common Name']}"
|
||||
performancedata['clients'] = clientcount
|
||||
performancedata["clients"] = clientcount
|
||||
|
||||
# special edevau counts
|
||||
if edevau:
|
||||
performancedata['k_clients'] = 0
|
||||
performancedata['e_clients'] = 0
|
||||
performancedata['o_clients'] = 0
|
||||
performancedata['k_in'] = 0
|
||||
performancedata['k_out'] = 0
|
||||
performancedata['e_in'] = 0
|
||||
performancedata['e_out'] = 0
|
||||
performancedata['o_in'] = 0
|
||||
performancedata['o_out'] = 0
|
||||
performancedata["k_clients"] = 0
|
||||
performancedata["e_clients"] = 0
|
||||
performancedata["o_clients"] = 0
|
||||
performancedata["k_in"] = 0
|
||||
performancedata["k_out"] = 0
|
||||
performancedata["e_in"] = 0
|
||||
performancedata["e_out"] = 0
|
||||
performancedata["o_in"] = 0
|
||||
performancedata["o_out"] = 0
|
||||
i = 0
|
||||
for cn in clients['Common Name']:
|
||||
for cn in clients["Common Name"]:
|
||||
if cn.startswith("k_"):
|
||||
performancedata['k_clients'] += 1
|
||||
performancedata['k_in'] += int(clients['Bytes Received'][i])
|
||||
performancedata['k_out'] += int(clients['Bytes Sent'][i])
|
||||
performancedata["k_clients"] += 1
|
||||
performancedata["k_in"] += int(clients["Bytes Received"][i])
|
||||
performancedata["k_out"] += int(clients["Bytes Sent"][i])
|
||||
elif cn.startswith("e_"):
|
||||
performancedata['e_clients'] +=1
|
||||
performancedata['e_in'] += int(clients['Bytes Received'][i])
|
||||
performancedata['e_out'] += int(clients['Bytes Sent'][i])
|
||||
performancedata["e_clients"] += 1
|
||||
performancedata["e_in"] += int(clients["Bytes Received"][i])
|
||||
performancedata["e_out"] += int(clients["Bytes Sent"][i])
|
||||
else:
|
||||
performancedata['o_clients'] +=1
|
||||
performancedata['o_in'] += int(clients['Bytes Received'][i])
|
||||
performancedata['o_out'] += int(clients['Bytes Sent'][i])
|
||||
performancedata["o_clients"] += 1
|
||||
performancedata["o_in"] += int(clients["Bytes Received"][i])
|
||||
performancedata["o_out"] += int(clients["Bytes Sent"][i])
|
||||
i += 1
|
||||
|
||||
# add performancedata
|
||||
@ -131,12 +136,14 @@ def main():
|
||||
message += f" |"
|
||||
for key in performancedata.keys():
|
||||
if key.endswith("clients"):
|
||||
message += f" {key}={performancedata[key]};{args.warn};{args.crit};{min};{max}"
|
||||
message += (
|
||||
f" {key}={performancedata[key]};{args.warn};{args.crit};{min};{max}"
|
||||
)
|
||||
else:
|
||||
message += f" {key}={performancedata[key]};;;;"
|
||||
|
||||
# go Home
|
||||
gtfo(STATUS,message)
|
||||
gtfo(STATUS, message)
|
||||
|
||||
|
||||
def ovpn_status2(s):
|
||||
@ -227,14 +234,16 @@ def ovpn_logon(s, password):
|
||||
return connected
|
||||
|
||||
|
||||
def save_obj(obj, name ):
|
||||
with open('obj/'+ name + '.pkl', 'wb') as f:
|
||||
def save_obj(obj, name):
|
||||
with open("obj/" + name + ".pkl", "wb") as f:
|
||||
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
|
||||
|
||||
def load_obj(name ):
|
||||
with open('obj/' + name + '.pkl', 'rb') as f:
|
||||
|
||||
def load_obj(name):
|
||||
with open("obj/" + name + ".pkl", "rb") as f:
|
||||
return pickle.load(f)
|
||||
|
||||
|
||||
def Get_Args():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="check_openvpn", usage=f"usage: {sys.argv[0]} [-v|vv|vvv] [options]"
|
||||
@ -286,8 +295,8 @@ def Get_Args():
|
||||
action="store_true",
|
||||
default=False,
|
||||
)
|
||||
parser.add_argument('-w', '--warn', help='warning limit', default=40)
|
||||
parser.add_argument('-c', '--crit', help='critical limit', default=50)
|
||||
parser.add_argument("-w", "--warn", help="warning limit", default=40)
|
||||
parser.add_argument("-c", "--crit", help="critical limit", default=50)
|
||||
# parser.add_argument('-n', '--neg ', help='negate the return code', action="store_true", dest="neg", default=False)
|
||||
args = parser.parse_args()
|
||||
if args.v > 3:
|
||||
|
Loading…
Reference in New Issue
Block a user