#!/bin/bash

# Check if all the system memory is still here.
# Ansible has a built in ansible_memtotal_mb fact so we can easily template this
# /proc/meminfo is in kB, so math happens :)

if [ -z $1 ]
then 
    echo "check_memory <amount in MB>"
    exit 3
fi

setmem=$1
curmem=$(grep MemTotal /proc/meminfo |awk '{print int($2/1024)}')

if [ $curmem = $setmem ]
then 
    echo "Ok: System memory as configured"
    exit 0
else 
    echo "WARNING: System memory $curmem MB, should be $setmem MB!"
    exit 1
fi
