summaryrefslogtreecommitdiffstats
path: root/scripts/check-uptime
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/check-uptime')
-rwxr-xr-xscripts/check-uptime/fetch.py7
-rw-r--r--scripts/check-uptime/main.yml19
-rwxr-xr-xscripts/check-uptime/report.py11
3 files changed, 37 insertions, 0 deletions
diff --git a/scripts/check-uptime/fetch.py b/scripts/check-uptime/fetch.py
new file mode 100755
index 0000000..c1cceff
--- /dev/null
+++ b/scripts/check-uptime/fetch.py
@@ -0,0 +1,7 @@
+#!/usr/bin/python3
+import crm_script
+try:
+ uptime = open('/proc/uptime').read().split()[0]
+ crm_script.exit_ok(uptime)
+except Exception as e:
+ crm_script.exit_fail("Couldn't open /proc/uptime: %s" % (e))
diff --git a/scripts/check-uptime/main.yml b/scripts/check-uptime/main.yml
new file mode 100644
index 0000000..d37f712
--- /dev/null
+++ b/scripts/check-uptime/main.yml
@@ -0,0 +1,19 @@
+version: 2.2
+category: Script
+shortdesc: Check uptime of nodes
+longdesc: >
+ Fetches the uptime of all nodes and reports which
+ node has lived longest.
+
+parameters:
+ - name: show_all
+ shortdesc: Show all uptimes
+ type: boolean
+ value: false
+
+actions:
+ - shortdesc: Fetch uptimes
+ collect: fetch.py
+
+ - shortdesc: Report uptime
+ report: report.py
diff --git a/scripts/check-uptime/report.py b/scripts/check-uptime/report.py
new file mode 100755
index 0000000..81710c8
--- /dev/null
+++ b/scripts/check-uptime/report.py
@@ -0,0 +1,11 @@
+#!/usr/bin/python3
+import crm_script
+show_all = crm_script.is_true(crm_script.param('show_all'))
+uptimes = list(crm_script.output(1).items())
+max_uptime = '', 0.0
+for host, uptime in uptimes:
+ if float(uptime) > max_uptime[1]:
+ max_uptime = host, float(uptime)
+if show_all:
+ print("Uptimes: %s" % (', '.join("%s: %s" % v for v in uptimes)))
+print("Longest uptime is %s seconds on host %s" % (max_uptime[1], max_uptime[0]))