Module: check_mk
Branch: master
Commit: 958a5fc18c1e65241be239fd63fc528e1a9910ba
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=958a5fc18c1e65…
Author: Marcel Arentz <ma(a)mathias-kettner.de>
Date: Mon Dec 18 12:09:09 2017 +0100
5551 FIX check_mk_agent.aix: Fixed crash in uptime if the output is day instead of days
This fix should prevent the uptime service of crashing not only if the output
contains day instead of days, but also for other possible deviating output.
Change-Id: I65d12cc660b750443b3e9af037cf06411f0d1f6b
---
.werks/5551 | 11 +++++++++++
agents/check_mk_agent.aix | 43 ++++++++++++++++++++-----------------------
2 files changed, 31 insertions(+), 23 deletions(-)
diff --git a/.werks/5551 b/.werks/5551
new file mode 100644
index 0000000..f63e0df
--- /dev/null
+++ b/.werks/5551
@@ -0,0 +1,11 @@
+Title: check_mk_agent.aix: Fixed crash in uptime if the output is day instead of days
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i2
+Date: 1513595012
+Class: fix
+
+This fix should prevent the uptime service of crashing not only if the output
+contains day instead of days, but also for other possible deviating output.
diff --git a/agents/check_mk_agent.aix b/agents/check_mk_agent.aix
index 295ca3e..a823d5a 100755
--- a/agents/check_mk_agent.aix
+++ b/agents/check_mk_agent.aix
@@ -241,29 +241,26 @@ fi
# 08:47AM up 66 days, 18:34, 1 user, load average: 2.25, 2.43, 2.61 --> 5769240
# 08:45AM up 76 days, 34 mins, 1 user, load average: 2.25, 2.43, 2.61 --> 5769240
echo '<<<uptime>>>'
-UPTIME=$(uptime | sed -e 's/^.*up//g' -e 's/[0-9] user.*//g')
-if [[ $UPTIME == *"days"* ]]; then
- DAYS=$(echo $UPTIME | sed -e 's/days,.*//g')
-else
- DAYS="0"
-fi
-
-if [[ $UPTIME == *"hrs"* ]]; then
- HOURS=$(echo $UPTIME | sed -e 's/hrs,.*//g' -e 's/.*,//g')
-else
- HOURS="0"
-fi
-
-if [[ $UPTIME == *"mins"* ]]; then
- MINS=$(echo $UPTIME | sed -e 's/mins,.*//g' -e 's/.*hrs,//g' -e
's/.*days,//g')
-else
- MINS="0"
-fi
-
-if [[ $UPTIME == *":"* ]]; then
- HOURS=$(echo $UPTIME | sed -e 's/.*days,//g' -e 's/:.*//g')
- MINS=$(echo $UPTIME | sed -e 's/.*days,//g' -e 's/.*://g' -e
's/,.*//g')
-fi
+UPTIME=$(uptime | sed -e 's/^.*up//g' -e 's/[0-9]* user.*//g')
+case $UPTIME in
+ *day* ) DAYS=$(echo $UPTIME | sed -e 's/days\?,.*//g') ;;
+ * ) DAYS="0" ;;
+esac
+
+case $UPTIME in
+ *:* )
+ HOURS=$(echo $UPTIME | sed -e 's/.*days\?,//g' -e 's/:.*//g')
+ MINS=$(echo $UPTIME | sed -e 's/.*days\?,//g' -e 's/.*://g' -e
's/,.*//g') ;;
+ *hr* )
+ HOURS=$(echo $UPTIME | sed -e 's/hrs\?,.*//g' -e 's/.*,//g')
+ MINS=0 ;;
+ *min* )
+ HOURS=0
+ MINS=$(echo $UPTIME | sed -e 's/mins\?,.*//g' -e 's/.*hrs\?,//g'
-e 's/.*days\?,//g') ;;
+ * )
+ HOURS="0"
+ MINS=0 ;;
+esac
echo $(((DAYS*86400)+(HOURS*3600)+(MINS*60)))