Saturday, November 24, 2018

Check_MK downtime bash script

This for Check_MK downtime bash script from command line

#God save my hand
if [ `echo $2|sed -n '/^http/p'|wc -l` -ne 0 ];then
replace_domain=`echo $2 |awk -F "//" '{print $2}'`
hostname="$replace_domain"
else
hostname=$2
fi

duration=$3
comment=$4


calculate_duration() {
  i=`echo  $duration | sed -e 's/\(^.*\)\(.$\)/\2/'`
  j=`echo $duration | sed s'/.$//'`

   if [ "$i" == "m" ];
    then i=1
   else if [ "$i" == "h" ];
    then i=60
   else if [ "$i" == "d" ];
    then i=1440
   fi
   fi
   fi
total_time=`expr $i \* $j`
}

usage() {
    echo -e "Usage: Each Option must be delimted with single space\n"
    echo -e "To Enable Downtime\n"
    echo -e "shellcmd icinga enable <hostname> <duration> <comment>\n"
    echo -e "shellcmd icinga enable example.com 1m -upgrade\n"
    echo -e "To Disable Downtime\n"
    echo -e "shellcmd icinga disable <hostname>\n"
    echo -e "shellcmd icinga disable example.com\n"
    echo -e "\n"
    echo "Note: if you want to get hostname please use @jarvis shellcmd os <domain_name> hostname"
    exit 1
}

enable_url() {
URL="https://<hostname>/prod/check_mk/view.py?_do_confirm=Yes&view_name=hoststatus&_transid=-1&site=&host=$hostname&_down_comment=$comment&_down_from_now=yes&_down_minutes=$total_time&_do_actions=yes"
}

disable_url() {
URL="https://<hostname>/prod/check_mk/view.py?_do_confirm=Yes&view_name=downtimes&_transid=-1&site=&host=$hostname&_remove_downtimes=Remove&_do_actions=yes"
}

case $1 in
enable)
calculate_duration
enable_url
curl -k --user "user|pass"  "$URL" >> /dev/null 2>&1
echo "Downtime set for host $hostname"
;;
disable)
disable_url
curl -k --user "user|pass"  "$URL" >> /dev/null 2>&1
echo "Downtime removed for host $hostname"
;;
*)
usage
esac

No comments:

Post a Comment

Create rpm and deb using fpm

Create rpm and deb using fpm  fpm -s dir -t rpm -n unbound-exporter -v 1.0 --prefix /usr/bin unbound_exporter   fpm -s dir -t rpm -n unbound...