Skip to content

Commit f5e21b6

Browse files
HowardGMacdan-snelson
authored andcommitted
Update checkUptime() function with additional fixes
Added suggested additional checks and fixes to the checkUptime() function
1 parent 4a37565 commit f5e21b6

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

Mac-Health-Check.zsh

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ allowedUptimeMinutes="10080"
397397
maxUptimeMinutes="43200"
398398

399399
# Should excessive uptime result in a "warning" or "error" ?
400+
# Setting this to error will disable the max uptime check above
400401
excessiveUptimeAlertStyle="warning"
401402

402403
# Completion Timer (in seconds)
@@ -6634,31 +6635,44 @@ function checkUptime() {
66346635
else
66356636
uptimeHumanReadable="${uptimeNumber} (HH:MM)"
66366637
fi
6638+
6639+
if [[ "${maxUptimeMinutes}" =~ '^[1-9][0-9]*$' ]]; then
6640+
if [[ "${allowedUptimeMinutes}" -gt "${maxUptimeMinutes}" ]]; then
6641+
warning "${humanReadableCheckName}: Error in configuration: Variable allowedUptimeMinutes is greater than maxUptimeMinutes. Maximum uptime check disabled."
6642+
maxUptimeMinutes=""
6643+
elif [[ -n "${maxUptimeMinutes}" ]] && [[ "${excessiveUptimeAlertStyle}" == "error" ]]; then
6644+
warning "${humanReadableCheckName}: Error in configuration: Variable excessiveUptimeAlertStyle is set to error instead of warning. Maximum uptime check disabled."
6645+
maxUptimeMinutes=""
6646+
fi
6647+
else
6648+
warning "${humanReadableCheckName}: Error in configuration: Variable maxUptimeMinutes is not a postive integer. Maximum uptime check disabled."
6649+
maxUptimeMinutes=""
6650+
fi
66376651

6638-
if [[ "${upTimeMin}" -gt "${maxUptimeMinutes}" ]] && [[ -n "${maxUptimeMinutes}" ]]; then
6639-
uptimeExtendedStatus="Your Mac's uptime is beyond the maximum 30 days allowed."
6652+
if [[ -n "${maxUptimeMinutes}" ]] && [[ "${upTimeMin}" -gt "${maxUptimeMinutes}" ]]; then
6653+
local uptimeExtendedStatus="Your Mac's uptime is beyond the maximum allowed by your organization."
66406654
dialogUpdate "listitem: index: ${1}, icon: SF=$(printf "%02d" $(($1+1))).circle.fill weight=bold colour=${statusColorFail}, iconalpha: 1, subtitle: ${uptimeExtendedStatus}, status: fail, statustext: ${uptimeHumanReadable}"
6641-
errorOut "${humanReadableCheckName}: ${uptimeHumanReadable}: "
6655+
errorOut "${humanReadableCheckName}: ${uptimeHumanReadable}: ${uptimeExtendedStatus}"
66426656
overallHealth+="${humanReadableCheckName}; "
66436657
elif [[ "${upTimeMin}" -gt "${allowedUptimeMinutes}" ]]; then
6644-
uptimeExtendedStatus="Please restart your Mac regularly. "
6658+
local uptimeExtendedStatus="Please restart your Mac regularly. "
66456659
case ${excessiveUptimeAlertStyle} in
66466660

66476661
"warning" )
66486662
dialogUpdate "listitem: index: ${1}, icon: SF=$(printf "%02d" $(($1+1))).circle.fill weight=bold colour=${statusColorError}, iconalpha: 1, subtitle: ${uptimeExtendedStatus}, status: error, statustext: ${uptimeHumanReadable}"
6649-
warning "${humanReadableCheckName}: ${uptimeHumanReadable}: "
6663+
warning "${humanReadableCheckName}: ${uptimeHumanReadable}: ${uptimeExtendedStatus}"
66506664
;;
66516665

6652-
"error" )
6666+
"error" | * )
66536667
dialogUpdate "listitem: index: ${1}, icon: SF=$(printf "%02d" $(($1+1))).circle.fill weight=bold colour=${statusColorFail}, iconalpha: 1, subtitle: ${uptimeExtendedStatus}, status: fail, statustext: ${uptimeHumanReadable}"
6654-
errorOut "${humanReadableCheckName}: ${uptimeHumanReadable}: "
6668+
errorOut "${humanReadableCheckName}: ${uptimeHumanReadable}: ${uptimeExtendedStatus}"
66556669
overallHealth+="${humanReadableCheckName}; "
66566670
;;
66576671

66586672
esac
66596673
else
66606674
dialogUpdate "listitem: index: ${1}, icon: SF=$(printf "%02d" $(($1+1))).circle.fill weight=semibold colour=${statusColorSuccess}, iconalpha: 0.6, subtitle: ${uptimeExtendedStatus}, status: success, statustext: ${uptimeHumanReadable}"
6661-
info "${humanReadableCheckName}: ${uptimeHumanReadable}: "
6675+
info "${humanReadableCheckName}: ${uptimeHumanReadable}: ${uptimeExtendedStatus}"
66626676
fi
66636677

66646678
}

0 commit comments

Comments
 (0)