Back to Resources

Level Verified

Linux Monitor - Device Standards Script

Created by

Level

Type

Script

Category

General

Platforms
WindowsApple iOSLinux

Problem Overview

Standardizing device performance is critical for IT teams managing Linux environments. Devices with insufficient CPU, RAM, or storage can cause performance issues, security vulnerabilities, and unnecessary help desk tickets. This script provides an automated way to verify that Linux machines meet minimum hardware requirements, enabling proactive maintenance and reducing unexpected failures.

Description

This script gathers system specifications—including CPU core count, total RAM, and available disk space—and compares them to the minimum values 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, it checks whether the primary disk is an SSD and warns if an HDD is detected. When configured as a script-based monitor in Level, it allows IT teams to enforce compliance across their Linux fleet and receive alerts when devices fail 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-linux-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=$(nproc)
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_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}')
35TOTAL_RAM_GB=$((TOTAL_RAM_KB / 1024 / 1024))
36if [ "$TOTAL_RAM_GB" -lt "$MIN_RAM" ]; 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_KB=$(df / | awk 'NR==2 {print $2}')
42TOTAL_DISK_GB=$((TOTAL_DISK_KB / 1024 / 1024))
43if [ "$TOTAL_DISK_GB" -lt "$MIN_DISK" ]; 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 (handles both standard and LVM setups)
48ROOT_DEVICE=$(lsblk -no pkname,type $(df -P / | awk 'NR==2 {print $1}') 2>/dev/null | grep "disk" | awk '{print $1}')
49if [ -n "$ROOT_DEVICE" ] && [ -f "/sys/block/$ROOT_DEVICE/queue/rotational" ]; then
50   ROTATIONAL=$(cat "/sys/block/$ROOT_DEVICE/queue/rotational")
51   if [ "$ROTATIONAL" = "1" ]; then
52       issues+=("ALERT: The primary disk is not an SSD.")
53   fi
54fi
55
56# Output results
57if [ ${#issues[@]} -gt 0 ]; then
58   printf '%s\n' "${issues[@]}"
59   exit 1
60else
61   echo "System check passed:
62- CPU cores: $CPU_CORES (min: $MIN_CORES)
63- RAM: $TOTAL_RAM_GB GB (min: $MIN_RAM GB)
64- Disk space: $TOTAL_DISK_GB GB (min: $MIN_DISK GB)"
65   exit 0
66fi

Use Cases

  • Ensure Linux endpoints meet minimum hardware standards for performance and reliability.
  • Identify underperforming devices that require upgrades or replacement.
  • Reduce IT support requests caused by outdated hardware configurations.
  • Maintain compliance across a diverse Linux environment, from servers to workstations.
  • Integrate with Level’s device standards monitoring policy for cross-platform enforcement (Windows, macOS, Linux).

Recommendations

  • Testing: Run the script manually on a Linux test system before deploying it across production environments.
  • Deployment: Use a script-based monitor in Level to schedule and trigger automatic compliance checks.
  • Customization: Modify cf_minimum_cpu, cf_minimum_ram, and cf_minimum_storage in Level’s custom fields to reflect your organization’s minimum standards.
  • Automation: Combine this script with auto-remediation workflows, such as flagging non-compliant devices for upgrades.
  • Scheduled Audits: Run this script on a schedule to maintain ongoing compliance across Linux devices.

FAQ

  • How do I configure this script in Level?
    Create a script-based monitor in Level and assign this script to run at regular intervals or on-demand to ensure compliance.
  • What happens when a device fails the compliance check?
    The script outputs a list of hardware deficiencies and exits with a failure code (exit 1), allowing Level to detect and flag the issue.
  • Can I adjust the minimum hardware requirements dynamically?
    Yes, the script retrieves minimum values from Level’s custom fields, allowing changes without modifying the script itself.
  • Does this script check all storage drives?
    No, it calculates disk space based on the root (/) partition and verifies whether the primary disk is an SSD.
  • Is there a version of this script for Windows or macOS?
    Yes, Level provides equivalent device standards monitoring policies for Windows and macOS, ensuring consistent compliance across platforms.

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

Linux Monitor - Device Standards

Description

This Linux Bash script performs system requirement verification using Level Custom Fields as thresholds. It checks CPU cores using nproc, RAM via /proc/meminfo, disk space with df, and SSD status through /sys/block rotational flag. The script stores requirement violations in an array and exits with code 1 and alerts if checks fail, or code 0 with system specifications 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