Statement
The Stars last night
Blog:http://yestreenstars.blog.51cto.com/
This article by oneself creation, if need reprint, please indicate source, thank cooperation!
Objective
Create Nagios monitoring host scripts with one click.
Environment
Os:centos 6.6 64
Configuration
#!/bin/bash# script Name: One-click Create Nagios Monitoring Host script # script Description: The script is used to automatically create the Nagios monitoring host, currently only for the creation of a system type Linux monitoring host, and only support a small number of common services. # creation Time:2015-04-07# Modify Time:2015-04-07echo ' Select the operating system type of the target monitoring host: ' Select os in linux Windowsdocase $OS inlinux) host_template= ' linux-server ' break;; Windows) host_template= ' windows-server ' break;; *) echo ' no this type! Please re-enter! ‘;; esacdonewhile read -p ' Please enter the host name of the target monitoring host: ' host_namedoif [ -n $host _name ' ]; thenbreakfiecho ' host name cannot be empty! Please re-enter! ' doneread -p ' Please enter an alias for the host (the same as the hostname): ' aliasif [ -z $alias ]; thenalias= $host _namefiwhile read -p ' Please enter the IP address of the target monitoring host: ' addressdoif [ -n $address ' ]; thenbreakfiecho ' IP address cannot be empty! Please re-enter! ' doneecho ' cfg_file=/usr/local/nagios/etc/objects/$address. Cfg " >> /usr/local/nagios/etc/ nagios.cfgecho "Define host{use$host_templatehost_name$host_namealias$aliasaddress$address}" > /usr/local/nagios/etc/objects/$address. cfghead= "define service{usegeneric-servicehost_name$ Host_name "Tail="} "services[1]=" service_descriptionpingcheck_commandcheck_ping!100.0,20%!500.0,60% "services[2]= "service_descriptionroot partitioncheck_commandcheck_local_disk!20%!10%!/" services[3]= "Service_ Descriptioncurrent userscheck_commandcheck_local_users!20!50 "services[4]=" service_descriptionTotal processescheck_commandcheck_local_procs!250!400! Rszdt "services[5]=" service_descriptioncurrent loadcheck_commandcheck_local_load!5.0,4.0,3.0!10.0,6.0,4.0 " services[6]= "service_descriptionswap usagecheck_commandcheck_local_swap!20!10" services[7]= "Service_ Descriptionsshcheck_commandcheck_ssh "services[8]=" service_descriptionhttpcheck_commandcheck_http "echo ' 1) PING2) root partition3) current users4) total processes5) current load6) Swap Usage7) HTTP ' echo ' please choose a way to enter according to the actual needs: first, if you only need to monitor a service, then you only need to enter the service corresponding serial number, second, if you need to monitor more services, then you can use a comma to(such as 1,3,5), if you need to monitor more services, and their serial number is continuous, then you can use a dash to connect the starting and ending sequence number (such as 1-3); four, if you need to monitor more services, and some services are sequential, some are discontinuous, Then you can mix commas and dashes (such as 1,3,5-7,9). ' while read -p ' Please select the service you want to monitor: ' choosedoif [ -n $choose ' ]; thenchoose=$ (awk -f, ' {for (i=0;i++<nf;) {if ($i ~/-/) {split ($i, a,/-/); for (j=a[1];j<=a[2];j++) print j;continue}print $i}} ' <<< $choose) for no in ${choose[@]} doecho "$head ${services[$no]} $tail" >> /usr/local/nagios/etc/objects/$ address.cfgdonebreakfiecho ' You did not enter the service serial number, please re-enter! ' Done
This article is from the "Last Night Stars" blog, please make sure to keep this source http://yestreenstars.blog.51cto.com/1836303/1629452
Create Nagios monitoring host script with one click