Imagen de joanet_9
0 puntos

Hola, soy nuevo en el foro, tengo que hacer un script para la instalación y automatización del nagios. De momento eh pensado este código, haber si entre todos me podéis ayudar a terminarlo.

gracias

código:

#!bin/bash
usuari=$(whoami)
if [[ $usuari == "root" ]] ; then

arxiu_localhost=/etc/nagios3/conf.d/localhost_nagios2.cfg
host_grups=/etc/nagios3/conf.d/hostgroups_nagios2.cfg

sudo apt-get install nagios3 -y

if [[ $? != 0 ]]; then
echo "instalación erronea"
else
echo "instalacion correcta"
fi

sudo cp /etc/nagios3/conf.d/localhost_nagios2.cfg /etc/nagios3/conf.d/cop.cfg

echo "Introduce el nombre del archivo donde se encuentran las ip y los nombres"
read ips

cat $ips | grep -v '#' | while read line
do
ip=$(echo $line | cut -f1 -d ";");
nom=$(echo $line | cut -f2 -d ";");

cat <>; $arxiu_localhost
define host{
use generic-host ; Name of host template to use
host_name $nom
alias $nom
address $ip
}
EOF

cat <>; $_host_grups
# Some generic hostgroup definitions

# A simple wildcard hostgroup
define hostgroup {
hostgroup_name all
alias All Servers
members *
}

# A list of your Debian GNU/Linux servers
define hostgroup {
hostgroup_name debian-servers
alias Debian GNU/Linux Servers
members localhost,$nom
}

# A list of your web servers
define hostgroup {
hostgroup_name http-servers
alias HTTP servers
members localhost,$nom
}

# A list of your ssh-accessible servers
define hostgroup {
hostgroup_name ssh-servers
alias SSH servers
members localhost,$nom
}

# nagios doesn't like monitoring hosts without services, so this is
# a group for devices that have no other "services" monitorable
# (like routers w/out snmp for example)
define hostgroup {
hostgroup_name ping-servers
alias Pingable servers
members gateway,$nom
}

define hostgroup {
hostgroup_name ubuntu-servers
alias Pingable servers
members gateway,$nom
}
EOF
else
echo "Permiso denegado"
fi