Back to Resources

Level Verified

macOS Monitor - Device Standards Script

Created by

Level

Type

Script

Category

General

Platforms
WindowsApple iOSLinux

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.

Description

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.

Script

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

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.

FAQ

  • 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.

Included with this Script:

Below is a list of what you can expect to find when importing this Script.

Script details:

The following data and settings will be imported with your script.

Script Name

macOS Monitor - Device Standards

Description

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.

Language

Bash

Timeout (In Seconds)

100

Run As

Local system

Import into Level

Related resources

Explore more automations, scripts, and policies to further enhance your IT operations.

View all resources