Skip to content

Commit 4a37565

Browse files
HowardGMacdan-snelson
authored andcommitted
Update checkuptime function with new functionality
Extends the Uptime check with a Maximum uptime setting. This allows uptime to show as warning after 7 days for example, and show a failure after 30 days. The Maximum uptime can be turned off if desired by setting the value as `maxUptimeMinutes=""`
1 parent 4f97a16 commit 4a37565

1 file changed

Lines changed: 23 additions & 24 deletions

File tree

Mac-Health-Check.zsh

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,10 @@ sofaCacheMaximumAge="1d"
391391
# Allowed number of uptime minutes
392392
# - 1 day = 24 hours × 60 minutes/hour = 1,440 minutes
393393
# - 7 days, multiply: 7 × 1,440 minutes = 10,080 minutes
394+
# - 30 days, multiply: 30 × 1,440 minutes = 43,200 minutes
395+
# Use maxUptimeMinutes="" to turn the max uptime check off if desired.
394396
allowedUptimeMinutes="10080"
397+
maxUptimeMinutes="43200"
395398

396399
# Should excessive uptime result in a "warning" or "error" ?
397400
excessiveUptimeAlertStyle="warning"
@@ -6600,13 +6603,12 @@ function checkFirewall() {
66006603
function checkUptime() {
66016604

66026605
local humanReadableCheckName="Uptime"
6603-
local footerStatusColor="${statusColorSuccess}"
6604-
notice "Check ${humanReadableCheckName}"
6606+
notice "Check ${humanReadableCheckName} ..."
66056607

66066608
dialogUpdate "icon: SF=stopwatch,${organizationColorScheme}"
6607-
dialogUpdate "listitem: index: ${1}, icon: SF=$(printf "%02d" $(($1+1))).circle.fill $(echo "${organizationColorScheme}" | tr ',' ' '), iconalpha: 1, status: wait, statustext: Checking "
6609+
dialogUpdate "listitem: index: ${1}, icon: SF=$(printf "%02d" $(($1+1))).circle.fill $(echo "${organizationColorScheme}" | tr ',' ' '), iconalpha: 1, status: wait, statustext: Checking ..."
66086610
dialogUpdate "progress: increment"
6609-
dialogUpdate "progresstext: Calculating time since last reboot "
6611+
dialogUpdate "progresstext: Calculating time since last reboot ..."
66106612

66116613
sleep "${anticipationDuration}"
66126614

@@ -6619,6 +6621,8 @@ function checkUptime() {
66196621
uptimeDays=$( uptime | awk '{ print $4 }' | sed 's/,//g' )
66206622
uptimeNumber=$( uptime | awk '{ print $3 }' | sed 's/,//g' )
66216623

6624+
uptimeExtendedStatus="Thanks for restarting your Mac regularly."
6625+
66226626
if [[ "${uptimeDays}" = "day"* ]]; then
66236627
if [[ "${uptimeNumber}" -gt 1 ]]; then
66246628
uptimeHumanReadable="${uptimeNumber} days"
@@ -6631,40 +6635,35 @@ function checkUptime() {
66316635
uptimeHumanReadable="${uptimeNumber} (HH:MM)"
66326636
fi
66336637

6634-
if [[ "${upTimeMin}" -gt "${allowedUptimeMinutes}" ]]; then
6635-
6638+
if [[ "${upTimeMin}" -gt "${maxUptimeMinutes}" ]] && [[ -n "${maxUptimeMinutes}" ]]; then
6639+
uptimeExtendedStatus="Your Mac's uptime is beyond the maximum 30 days allowed."
6640+
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}: "
6642+
overallHealth+="${humanReadableCheckName}; "
6643+
elif [[ "${upTimeMin}" -gt "${allowedUptimeMinutes}" ]]; then
6644+
uptimeExtendedStatus="Please restart your Mac regularly. "
66366645
case ${excessiveUptimeAlertStyle} in
66376646

6638-
"warning" )
6639-
dialogUpdate "listitem: index: ${1}, icon: SF=$(printf "%02d" $(($1+1))).circle.fill weight=bold colour=${statusColorError}, iconalpha: 1, subtitle: Please restart your Mac regularly, status: error, statustext: ${uptimeHumanReadable}"
6640-
footerStatusColor="${statusColorError}"
6641-
warning "${humanReadableCheckName}: ${uptimeHumanReadable}"
6647+
"warning" )
6648+
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}: "
66426650
;;
66436651

6644-
"error" | * )
6645-
dialogUpdate "listitem: index: ${1}, icon: SF=$(printf "%02d" $(($1+1))).circle.fill weight=bold colour=${statusColorFail}, iconalpha: 1, subtitle: Please restart your Mac regularly, status: fail, statustext: ${uptimeHumanReadable}"
6646-
footerStatusColor="${statusColorFail}"
6647-
errorOut "${humanReadableCheckName}: ${uptimeHumanReadable}"
6652+
"error" )
6653+
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}: "
66486655
overallHealth+="${humanReadableCheckName}; "
66496656
;;
66506657

66516658
esac
6652-
66536659
else
6654-
6655-
dialogUpdate "listitem: index: ${1}, icon: SF=$(printf "%02d" $(($1+1))).circle.fill weight=semibold colour=${statusColorSuccess}, iconalpha: 0.9, subtitle: Thanks for restarting your Mac regularly, status: success, statustext: ${uptimeHumanReadable}"
6656-
footerStatusColor="${statusColorSuccess}"
6657-
info "${humanReadableCheckName}: ${uptimeHumanReadable}"
6658-
6660+
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}: "
66596662
fi
66606663

6661-
dialogUpdate "icon: SF=stopwatch,weight=semibold,colour=${footerStatusColor}"
6662-
sleep $((anticipationDuration / 2))
6663-
66646664
}
66656665

66666666

6667-
66686667
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
66696668
# Check Free Disk Space
66706669
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

0 commit comments

Comments
 (0)