/usr/local/nagios/etc
规则:
1.以#开头的行不处理
2.变量名必须从行的开头开始,不允许有空格
3.变量名大小写敏感
nagios.cfg 控制nagios deamon运行的参数
log_file 日志文件位置
例:log_file=/usr/local/nagios/var/nagios.log
cfg_file 对象配置文件
例:cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_file=/usr/local/nagios/etc/services.cfg
cfg_file=/usr/local/nagios/etc/commands.cfg
cfg_dir 对象配置目录
例: cfg_dir=/usr/local/nagios/etc/commands
cfg_dir=/usr/local/nagios/etc/services
cfg_dir=/usr/local/nagios/etc/hosts
object_cache_file 对象定义缓存文件,可以修改配置文件,而不影响运行
例:object_cache_file=/usr/local/nagios/var/objects.cache
precached_object_file 对象定义预缓存文件,可以加速nagios的启动
例:precached_object_file=/usr/local/nagios/var/objects.precache
resource_file 指定资源文件
cfg_file或cfg_dir 指定对象定义文件
cgi操作相关的配置,并且也指向主配置文件,可以得到主配置文件信息
resource.cfg 存储用户敏感的配置信息(如:密码)
objects文件夹下的文件, 主要用来定义hosts, services, hostgroups, contacts, contactgroups, commands等
对象定义:
host
hostgroup
service
servicegroup
contact
contactgroup
timeperiod
对象的定义可以继承
基本的对象定义在文件templates.cfg文件中,如:linux-server,这个可以被其他的对象定义继承
示例:
define host{
use linux-server (继承linux-server定义)
host_name fedora10-server
alias my fedora10 server
address 127.0.0.1
}
define hostgroup{
hostgroup_name linux-servers-monitor
alias Linux Servers monitored
members fedora10-server
}
define service{
use local-service (继承local-service定义)
host_name fedora10-server
service_description Mysql
check_command check_mysql!127.0.0.1!3306!root!password
notifications_enabled 1
}
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$
}
其中$USER1$定义在resources.cfg中,是一个路径$USER1$=/usr/local/nagios/libexec
配置文件举例:
host,service定义:
define host{ use linux-server host_name fedora10-server alias my fedora10 server address 127.0.0.1 } define hostgroup{ hostgroup_name linux-servers-monitor alias Linux Servers monitored members fedora10-server } define service{ use local-service host_name fedora10-server service_description Apache HTTP Server Check check_command check_http notifications_enabled 1 } define service{ use local-service host_name fedora10-server service_description Mysql check_command check_mysql!127.0.0.1!3306!root!123456 notifications_enabled 1 } define service{ use local-service host_name fedora10-server service_description Tomcat check_command check_tcp!8080!4 notifications_enabled 0 } define service{ use local-service host_name fedora10-server service_description Memcached check_command check_tcp!11211!4 notifications_enabled 1 } define service{ use local-service host_name fedora10-server service_description Local C check_command check_local_disk!4000M!2000M!/mnt/c notifications_enabled 0 } define service{ use local-service host_name fedora10-server service_description Local D check_command check_local_disk!4000M!2000M!/mnt/d notifications_enabled 0 } define service{ use local-service host_name fedora10-server service_description Local E check_command check_local_disk!4000M!2000M!/mnt/e notifications_enabled 0 } define service{ use local-service host_name fedora10-server service_description Local F check_command check_local_disk!4000M!2000M!/mnt/f notifications_enabled 0 } define service{ use local-service host_name fedora10-server service_description Local / check_command check_local_disk!2000M!1000M!/ notifications_enabled 0 } define service{ use local-service host_name fedora10-server service_description Mediawiki check_command check_url!127.0.0.1!/mediawiki/index.php notifications_enabled 0 }
command定义:
define command{ command_name check_mysql command_line $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ } define command{ command_name check_url command_line $USER1$/check_http -I $ARG1$ -u $ARG2$ }
nagios检查脚本文件路径:/usr/local/nagios/libexec
查看检查脚本命令的参数:可以运行 命令 -h,如:check_disk -h