-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmunki_health_check.sh
More file actions
executable file
·48 lines (41 loc) · 1.4 KB
/
munki_health_check.sh
File metadata and controls
executable file
·48 lines (41 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/zsh
#### Example extension attribute to get that Munki's been running okay ####
# If it's been more than this many days since the last Munki run, consider unhealthy
days_threshold=5
# Convert days to seconds for easier comparison
seconds_threshold=$days_threshold*24*60*60
report_plist='/Library/Managed Installs/ManagedInstallReport.plist'
plistbuddy='/usr/libexec/PlistBuddy'
# Initialize errors variable
errors=''
# Check the report plist exists
if [[ ! -f $report_plist ]]; then
errors="$report_plist doesn't exist, so Munki hasn't run"
else
# Get errors array items (if any)
index=0
until ! $plistbuddy -c "Print :Errors:$index" "$report_plist" > /dev/null 2>&1; do
if [[ $index -gt 0 ]]; then
errors+=', '
fi
errors+=$($plistbuddy -c "Print :Errors:$index" "$report_plist")
index=$(( index + 1))
done
# If there are no errors, see the last time Munki was run
if [[ $errors == '' ]]; then
last_run=$(/usr/bin/defaults read $report_plist StartTime)
last_epoch=$(/bin/date -j -f "%Y-%m-%d %H:%M:%S +0000" "$last_run" +%s)
current_epoch=$(/bin/date +%s)
date_threshold=$(($current_epoch-$seconds_threshold))
if [[ $last_epoch -lt $date_threshold ]]; then
errors="Last Munki run was $last_run"
else
echo "Last Munki run was $last_run"
fi
fi
fi
if [[ $errors == '' ]]; then
/bin/echo "<result>Munki healthy</result>"
else
/bin/echo "<result>Unhealthy: $errors</result>"
fi