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