Ori.livneh has submitted this change and it was merged.

Change subject: check_puppetrun: use human-readable units in alerts
......................................................................


check_puppetrun: use human-readable units in alerts

Because '14 hours' is much more readable '50995 seconds'.
Also removed the expected recency from the message format, since it didn't seem
to be useful.

Change-Id: I85ac32a6b1ee4afbdacc51e2a79eed76b4156fc8
---
M modules/base/files/monitoring/check_puppetrun
1 file changed, 13 insertions(+), 5 deletions(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/base/files/monitoring/check_puppetrun 
b/modules/base/files/monitoring/check_puppetrun
index a9078c1..b8fd053 100755
--- a/modules/base/files/monitoring/check_puppetrun
+++ b/modules/base/files/monitoring/check_puppetrun
@@ -94,15 +94,23 @@
     failcount = :nostatefile
 end
 
+def time_ago(s)
+  units = {86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second'}
+  units.sort.reverse.each do |len, unit|
+    return "#{s / len} #{unit}#{'s' if s / len > 1}" if s > len
+  end
+end
+
 time_since_last_run = Time.now.to_i - lastrun
+human_time_since_last_run = time_ago(time_since_last_run)
 
 if enabled_only && enabled == false
-    puts "OK: Puppet is currently disabled, not alerting. Last run 
#{time_since_last_run} seconds ago with #{failcount} failures"
+    puts "OK: Puppet is currently disabled, not alerting. Last run 
#{human_time_since_last_run} ago with #{failcount} failures"
     exit 0
 end
 
 if not enabled
-    puts "WARNING: Puppet is currently disabled, last run 
#{time_since_last_run} seconds ago with #{failcount} failures"
+    puts "WARNING: Puppet is currently disabled, last run 
#{human_time_since_last_run} ago with #{failcount} failures"
     exit 1
 end
 
@@ -122,14 +130,14 @@
 end
 
 if time_since_last_run >= crit
-    puts "CRITICAL: Puppet last ran #{time_since_last_run} seconds ago, 
expected < #{crit}"
+    puts "CRITICAL: Puppet last ran #{human_time_since_last_run} ago"
     exit 2
 end
 
 if time_since_last_run >= warn
-    puts "WARNING: Puppet last ran #{time_since_last_run} seconds ago, 
expected < #{warn}"
+    puts "WARNING: Puppet last ran #{human_time_since_last_run} ago"
     exit 1
 end
 
-puts "OK: Puppet is currently enabled, last run #{time_since_last_run} seconds 
ago with #{failcount} failures"
+puts "OK: Puppet is currently enabled, last run #{human_time_since_last_run} 
ago with #{failcount} failures"
 exit 0

-- 
To view, visit https://gerrit.wikimedia.org/r/170291
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I85ac32a6b1ee4afbdacc51e2a79eed76b4156fc8
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to