I need to add hosts quickly to Nagios, I do this by scanning the hosts using nmap and generating a config with the output. ThenĀ IĀ setup a Nagios client on the host and monitor the vitals.
This process takes time, so i wrote a script which will generate the configuration for me using the nmap results. see below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#!/bin/bash ip=$1 hostname=$2 output="$hostname.cfg" echo " define host{ use generic-host ; Name of host template to use host_name $hostname alias $hostname address $ip } define hostextinfo { host_name $hostname icon_image base/modem.png icon_image_alt Router vrml_image base/modem.png statusmap_image base/modem.gd2 2d_coords 300,550 3d_coords 100.0,50.0,75.0 } define service { host_name $hostname service_description PING check_command check_ping!100.0,20%!500.0,60% use generic-service } " > $output for i in `nmap $ip| grep tcp| awk -F '/' '{print $1}'` do echo " define service { host_name $hostname service_description Port $i check_command check_tcp!$i! use generic-service } " >> $output done |