Level Verified

macOS Monitor - Device Standards Script

Automatically verify that macOS devices meet minimum CPU, RAM, and storage requirements using Level’s custom fields. Use this script within a script-based monitor to detect non-compliant devices and trigger alerts.

Import into Level

Problem overview

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.

Bash 100s timeout Runs as Local system macOS
#!/bin/bash

# This resource is provided as a convenience for Level users. We cannot 
# guarantee it will work in all environments. Please test before deploying 
# to your production environment. We welcome contributions to our community 
# library

# Level Library
# https://level.io/library/script-macos-monitor-device-standards

# Define minimum standards
MIN_CORES={{cf_minimum_cpu}}
MIN_RAM={{cf_minimum_ram}}  # in GB
MIN_DISK={{cf_minimum_storage}}  # in GB
STANDARDS_BYPASS={{cf_standards_bypass}}
echo "Current STANDARDS_BYPASS value: $STANDARDS_BYPASS"

# Check for standards bypass
if [ "${STANDARDS_BYPASS}" = "true" ] || [ "${STANDARDS_BYPASS}" = "1" ]; then
   echo "Standards check bypassed by configuration"
   exit 0
fi

# Initialize issues array
declare -a issues

# Check CPU Cores
CPU_CORES=$(sysctl -n hw.ncpu)
if [ "$CPU_CORES" -lt "$MIN_CORES" ]; then
   issues+=("ALERT: CPU has $CPU_CORES cores, below the minimum requirement of $MIN_CORES cores.")
fi

# Check RAM
TOTAL_RAM_BYTES=$(sysctl -n hw.memsize)
TOTAL_RAM_GB=$(echo "scale=2; $TOTAL_RAM_BYTES/1024/1024/1024" | bc)
if (( $(echo "$TOTAL_RAM_GB < $MIN_RAM" | bc -l) )); then
   issues+=("ALERT: System has $TOTAL_RAM_GB GB of RAM, below the minimum requirement of $MIN_RAM GB.")
fi

# Check Disk Space
TOTAL_DISK_BLOCKS=$(df / | awk 'NR==2 {print $2}')
TOTAL_DISK_GB=$(echo "scale=2; $TOTAL_DISK_BLOCKS*512/1024/1024/1024" | bc)
if (( $(echo "$TOTAL_DISK_GB < $MIN_DISK" | bc -l) )); then
   issues+=("ALERT: Total disk space is $TOTAL_DISK_GB GB, below the minimum requirement of $MIN_DISK GB.")
fi

# Check if disk is SSD
DISK_TYPE=$(diskutil info / | grep "Solid State" | awk '{print $3}')
if [ "$DISK_TYPE" != "Yes" ]; then
   issues+=("ALERT: The primary disk is not an SSD.")
fi

# Output results
if [ ${#issues[@]} -gt 0 ]; then
   printf '%s\n' "${issues[@]}"
   exit 1
else
   echo "System check passed:
- CPU cores: $CPU_CORES (min: $MIN_CORES)
- RAM: $TOTAL_RAM_GB GB (min: $MIN_RAM GB)
- Disk space: $TOTAL_DISK_GB GB (min: $MIN_DISK GB)"
   exit 0
fi

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.

Use cases

  • Ensure company-issued macOS devices meet performance and compliance standards.
  • Identify underperforming endpoints that need hardware upgrades or replacement.
  • Reduce IT support issues caused by devices with insufficient hardware.
  • Enforce device compliance policies for MSPs and internal IT teams.
  • Integrate with Level’s device standards monitoring policy for cross-platform enforcement (Windows, macOS, Linux).

Recommendations

  • Testing: Run the script manually on a macOS test device before deploying it in a production environment.
  • Deployment: Set up a script-based monitor in Level to automatically run this script and generate alerts for non-compliant devices.
  • Customization: Modify Minimum CPU, Minimum RAM, and Minimum Storage in Level’s custom fields to align with your organization’s hardware requirements.
  • Automation: Combine this script with automated remediation actions, such as upgrade recommendations or device lifecycle tracking.
  • Monitoring Frequency: Schedule regular compliance checks to ensure ongoing adherence to hardware standards.

Frequently asked questions.

How do I set up this script in Level?

Create a script-based monitor in Level and configure it to execute this script. When a device fails compliance checks, Level will trigger an alert.

What happens if a device does not meet the minimum requirements?

The script outputs a list of non-compliant components and exits with a failure code (exit 1), which allows Level to detect and flag the issue.

Can I adjust the minimum requirements without modifying the script?

Yes, the script dynamically retrieves the minimum values from Level’s custom fields, allowing changes through Level’s configuration settings.

Does this script check all storage drives on the system?

No, it calculates total disk space from the root volume (/) and verifies whether the primary disk is an SSD.

Is there a version of this script for Windows or Linux?

Yes, Level offers equivalent device standards monitoring policies for Windows and Linux, ensuring cross-platform compliance. We also have a monitoring policy that implements cross platform device standards monitoring support.

Ready when you are.

No credit card. No sales call. Just sign up and start managing.