#!/bin/bash


offline_nodes=$(sudo corosync-cmapctl \
| grep members \
| fgrep -e .ip -e .status \
| fgrep -B 1 left \
| grep -Po '(\d+\.){3}\d+' \
| xargs -n1 -I {} echo Node {} left cluster)

if [[ -n "$offline_nodes" ]]; then
    echo "CRITICAL - $offline_nodes"
    exit 2
else
    echo "OK"
    exit 0
fi
