maniu@securebrain.com:~/script# vi add_host_list.sh



#!/bin/bash
# pippo e' una lista "ip host"
# se non si dispone dell'ip, usare IPADDR 
# la mia alberatura delle conf di nagios e' 
# OS --> services/hosts
IFS=$'\n'
for i in `cat pippo| awk '{print $0}'`;
do
var=$i
varip=`echo $var|awk '{print $1}'`
varhost=`echo $var|awk '{print $2}'`
        echo "aggiunta host $i in nagios"
        cp template.cfg ./services/$varhost.cfg;
        echo "creato file ./services/$varhost.cfg"
        cp template-host.cfg ./hosts/$varhost.cfg ;
        echo "creato file ./hosts/$varhost.cfg"
#       IPADDR=`nslookup $i |tail -2 |head -1|  awk '{print $2}'`
        sed  -i "s/hostn/$varhost/g" ./services/$varhost.cfg;
        sed  -i "s/ipaddr/$varip/g"  ./hosts/$varhost.cfg ;
        sed  -i "s/hostn/$varhost/g"   ./hosts/$varhost.cfg ;
        echo "sostituzioni effettuate"
        echo ""
        echo ""
done

# cat template.cfg
define service{
      use                              Gen_Sys         ; Name of service template to use
      host_name                        hostn
      service_description              P02.01.1 Ping Ko
      check_command                    check-host-alive!hostn
}

# cat template-host.cfg
define host{
        host_name                       hostn
        alias                           switch
        address                         ipaddr
        notifications_enabled           1               ; Host notifications are enabled
        event_handler_enabled           1               ; Host event handler is enabled
        flap_detection_enabled          1               ; Flap detection is enabled
        failure_prediction_enabled      1               ; Failure prediction is enabled
        process_perf_data               1               ; Process performance data
        retain_status_information       1               ; Retain status information across program restarts
        retain_nonstatus_information    1               ; Retain non-status information across program restarts
        max_check_attempts              3
        notification_interval           0
        notification_period             24x7
        notification_options            d,u,r
        contact_groups                  admins
        }





:q!