Nagios学习笔记之(五)后期维护
- #!/bin/bash
- #author: xiaojun.wang
- usage () {
- echo -en "USAGE: $0 [host list] or $0 [template] [host list]\nFor example: $0 host.template host.list(Field : [IP] [HOST NAME])\n" 1>&2
- exit 1
- }
- if [ $# -gt 2 ];then
- usage
- exit 1
- fi
- case "$#" in
- 2)
- template=$1
- host_list=$2
- ;;
- 1)
- template='host.template'
- host_list=$1
- ;;
- 0)
- # template='host.template'
- # host_list='host.list'
- usage
- ;;
- esac
- if [ ! -f "${template}" ];then
- echo "template : ${template} not exist!" 1>&2
- exit 1
- fi
- if [ ! -f "${host_list}" ];then
- echo "host list : ${host_list} not exist!" 1>&2
- exit 1
- fi
- cat ${host_list}|\
- while read ip hostname
- do
- echo "${ip}"|grep -oP '^\d{1,3}(\.\d{1,3}){3}$' >/dev/null 2>&1 || Field='not ip'
- if [ "${Field}" = 'not ip' ];then
- echo "${ip} not ip!" 1>&2
- exit 1
- fi
- host_cfg="${hostname}-${ip}.cfg"
- cp ${template} ${host_cfg}
- sed -i "s/HOST_NAME/${hostname}/g;s/ADDRESS/${ip}/g" ${host_cfg}
- done
- define host{ #主机配置
- use linux-server,hosts-pnp
- host_name HOST_NAME #这个就是到时脚本写入的主机名
- alias HOST_NAME; A longer name for the server
- address ADDRESS ; IP address of the server #脚本要写入的ip
- }
- define service{
- use generic-service,services-pnp
- host_name HOST_NAME #同上
- service_description CPU Load
- check_command check_nrpe!check_load
- }
- define service{
- use generic-service,services-pnp
- host_name HOST_NAME
- service_description Current Users
- check_command check_nrpe!check_users
- }
- define service{
- use generic-service,services-pnp
- host_name HOST_NAME
- service_description Disk Free Space /
- check_command check_nrpe!check_root
- }
- define service{
- use generic-service,services-pnp
- host_name HOST_NAME
- service_description Total Processes
- check_command check_nrpe!check_total_procs
- }
- define service{
- use generic-service,services-pnp
- host_name HOST_NAME
- service_description Zombie Processes
- check_command check_nrpe!check_zombie_procs
- }
- define service{
- use generic-service,services-pnp
- host_name HOST_NAME
- service_description SSH
- check_command check_ssh
- register 0
- }
Nagios全系列笔记:
Nagios学习笔记之(一)最初搭建
Nagios学习笔记之(二)监控部署
Nagios学习笔记之(三)配置详解
Nagios学习笔记之(四)外部扩展
Nagios学习笔记之(五)后期维护
本文出自 “____�N.�r^随记” 博客,转载请与作者联系!