Back to Resources
Level
Script
General
Ensuring that all macOS devices in an IT environment meet minimum performance standards is crucial for productivity, security, and support efficiency. Devices that fall below a defined baseline can cause performance bottlenecks, software compatibility issues, and increased help desk tickets. This script helps IT professionals and MSPs proactively monitor macOS hardware compliance and flag devices that require upgrades or replacement.
This script checks system hardware specifications—including CPU core count, total RAM, and available disk space—and compares them to the minimum standards defined in Level’s custom fields (cf_minimum_cpu, cf_minimum_ram, and cf_minimum_storage). If a device falls short in any category, it generates an alert. Additionally, the script verifies if the primary disk is an SSD and warns if an HDD is detected. When deployed as a script-based monitor in Level, it continuously enforces device compliance and provides real-time alerts when hardware fails to meet requirements.
1#!/bin/bash
2
3# This resource is provided as a convenience for Level users. We cannot
4# guarantee it will work in all environments. Please test before deploying
5# to your production environment. We welcome contributions to our community
6# library
7
8# Level Library
9# https://level.io/library/script-macos-monitor-device-standards
10
11# Define minimum standards
12MIN_CORES={{cf_minimum_cpu}}
13MIN_RAM={{cf_minimum_ram}} # in GB
14MIN_DISK={{cf_minimum_storage}} # in GB
15STANDARDS_BYPASS={{cf_standards_bypass}}
16echo "Current STANDARDS_BYPASS value: $STANDARDS_BYPASS"
17
18# Check for standards bypass
19if [ "${STANDARDS_BYPASS}" = "true" ] || [ "${STANDARDS_BYPASS}" = "1" ]; then
20 echo "Standards check bypassed by configuration"
21 exit 0
22fi
23
24# Initialize issues array
25declare -a issues
26
27# Check CPU Cores
28CPU_CORES=$(sysctl -n hw.ncpu)
29if [ "$CPU_CORES" -lt "$MIN_CORES" ]; then
30 issues+=("ALERT: CPU has $CPU_CORES cores, below the minimum requirement of $MIN_CORES cores.")
31fi
32
33# Check RAM
34TOTAL_RAM_BYTES=$(sysctl -n hw.memsize)
35TOTAL_RAM_GB=$(echo "scale=2; $TOTAL_RAM_BYTES/1024/1024/1024" | bc)
36if (( $(echo "$TOTAL_RAM_GB < $MIN_RAM" | bc -l) )); then
37 issues+=("ALERT: System has $TOTAL_RAM_GB GB of RAM, below the minimum requirement of $MIN_RAM GB.")
38fi
39
40# Check Disk Space
41TOTAL_DISK_BLOCKS=$(df / | awk 'NR==2 {print $2}')
42TOTAL_DISK_GB=$(echo "scale=2; $TOTAL_DISK_BLOCKS*512/1024/1024/1024" | bc)
43if (( $(echo "$TOTAL_DISK_GB < $MIN_DISK" | bc -l) )); then
44 issues+=("ALERT: Total disk space is $TOTAL_DISK_GB GB, below the minimum requirement of $MIN_DISK GB.")
45fi
46
47# Check if disk is SSD
48DISK_TYPE=$(diskutil info / | grep "Solid State" | awk '{print $3}')
49if [ "$DISK_TYPE" != "Yes" ]; then
50 issues+=("ALERT: The primary disk is not an SSD.")
51fi
52
53# Output results
54if [ ${#issues[@]} -gt 0 ]; then
55 printf '%s\n' "${issues[@]}"
56 exit 1
57else
58 echo "System check passed:
59- CPU cores: $CPU_CORES (min: $MIN_CORES)
60- RAM: $TOTAL_RAM_GB GB (min: $MIN_RAM GB)
61- Disk space: $TOTAL_DISK_GB GB (min: $MIN_DISK GB)"
62 exit 0
63fi
macOS Monitor - Device Standards
This Bash script performs system requirement checks on macOS using Level Custom Fields for thresholds. It evaluates CPU cores, RAM, disk space, and SSD presence using native macOS commands like sysctl, df, and diskutil. The script stores any requirement violations in an array and outputs either the alerts with exit code 1 if checks fail, or a system specifications summary with exit code 0 if all checks pass.
Bash
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.