From 15a752a65d49aec71afbd7ad119df156a484a3ea Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Tue, 24 Sep 2024 22:31:01 +0200 Subject: [PATCH] Add uptime check taht warns if server has been up for too long --- templates/scriptreceiver/check_max_uptime | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 templates/scriptreceiver/check_max_uptime diff --git a/templates/scriptreceiver/check_max_uptime b/templates/scriptreceiver/check_max_uptime new file mode 100755 index 0000000..63fbb63 --- /dev/null +++ b/templates/scriptreceiver/check_max_uptime @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +import argparse +import sys + +parser = argparse.ArgumentParser() +parser.add_argument('-w', '--warning', + help='Warning threashold', + required=True) +parser.add_argument('-c', '--critical', + help='Critical threashold', + required=True) + +args = parser.parse_args() +warning = int(args.warning) +critical = int(args.critical) + +with open('/proc/uptime', 'r') as f: + uptime_seconds = float(f.readline().split()[0]) +days = int(uptime_seconds / 86400) + +status = "OK" +exit = 0 +if days > warning: + status = "WARNING" + exit = 1 +if days > critical: + status = "CRITICAL" + exit = 2 + +print(f"{status}: uptime {days} days | uptime={days};{warning};{critical};") +sys.exit(exit)