#!/bin/bash

help="Usage: [-H hostname] [-k keyfile with path] [-u username]"

tmplog=/tmp/$$



while getopts ":k:H:u:" option
do
		case $option in
		k) keyfile=$OPTARG
		;;
		H) host=$OPTARG
		;;
		u) user=$OPTARG
		;;
		*) echo "Invalid Options"
		   echo "$help" 1>&2;exit 1
		;;
		esac
done

#keyfile="$PWD/collectd_rsa.key"
#host="na1-ui-nbg3.ui"
#user="collectd"



command="cf status"




ssh -i $keyfile $user@$host $command > $tmplog

if grep -q "(link 0 up, link 1 down)" $tmplog;then
        echo "Critical: Link 1 down"
                exit 2
fi
if grep -q "(link 0 down, link 1 up)" $tmplog; then
                echo "Critical: Link 0 down" 
                exit 2
fi
if grep -q "(link 0 down, link 1 down)" $tmplog; then
                echo "Critical: Alles Kaputt!!!!"
                exit 2
fi

if grep -v "link" $tmplog; then
                #echo "OK"
                exit 0
fi
