Skip to end of metadata
Go to start of metadata

{code:lang-bash}

#!/bin/bash

echo "Welcome to OneStepNagios."
echo "This script allows you to create a new Nagios host or re-deploy an old one."
echo "Alternatively, you can overwrite an old host with new settings (just refuse re-deployment, enter its existing name and confirm)"

while true; do
        read -e -p "Do you want to re-deploy an existing Nagios host? (y/n)" -i "y" yn
            case $yn in
                [Yy]* ) echo "Running dephost..."; ./dephost; break; exit 0;;
                [Nn]* ) echo "You will now create a new Nagios host."; break;;
                * ) echo "Please answer Y/y or N/n.";;
                    esac
            done

echo "Enter the name of the host:"
read HOST

echo "Verifying that the host $HOST doesn't exist yet."
echo "Prepare to enter your password for the VPN container:"

#ssh -p 1631 root@bluelightav.org "ls /etc/nagios3/hosts" | awk -F "." '{print $1}'
ssh -p 1631 root@bluelightav.org "if [ -f /etc/nagios3/hosts/$HOST.cfg ]; then exit 10"

if [[ $? -eq 10 ]]; then
read -e -p "Nagios host $HOST already exists! Would you like to overwrite its settings? (y/n)" -i "y" yn
            case $yn in
                [Yy]* ) echo "WARNING: host $HOST will be overwritten."; break;;
                [Nn]* ) echo "Exiting."; break; exit 1;;
                * ) echo "Please answer Y/y or N/n.";;
                    esac
fi

echo "... done."

echo "You will now choose the hours during which this host is to be monitored."

read -e -p "Enter 1 for normal (8-30 AM to 4-30 PM) and 2 for 24x7:" -i "1" 12
            case $12 in
                1 ) echo "Selecting normal monitoring schedule for host $HOST."; ; break;;
                2 ) echo "You will now create a new Nagios host."; break;;
                * ) echo "Please answer 1 for normal or 2 for 24x7 monitoring.";;
                    esac
{code}

  • No labels