9. LinuxTone IT 运维专家论坛文档
command_line $USER1$/check_snmp_storage.pl -H $HOSTADDRESS$ $USER7$ $ARG1$ -
w $ARG2$ -c $ARG3$
这 里 的 $ARG1$ 即 表 示 参 数 1 , $ARG2 即 表 示 参 数 2 , $ARG3$ 即 表 示 参 数 3
而$HOSTADDRESS$是我们定义的检测对象,它的值就是我们的主机 IP 地址;$USER1$和
$USER7$为在 resource.cfg 里的定义。下面我们将参数值代入这个 command 里,最后实现的
效 果 是 :
/usr/local/nagios/libexec/check_snmp_storage.pl –H 60.222.111.83 –C mypublic -2 –m “^Virtual
Memory$” –w 70 –c 90
而 这 个 命 令 就 是 我 们 实 现 监 控 83 的 虚 拟 内 存 的 命 令 !
设置 3 个参数是为了灵活的针对不同主机的调用,如果你对不同的主机设置的阈值不同,
只需要对不同的主机定义不同的 service 即可,command 是可以通用的!而这里的参数 1 也
是为了实现不同的功能而设置的,这个脚本还可以检测物理内存,如果我们把参数 1 的值
设置为”^Phisical Memory$” 就可以针对物理内存进行检测!定义 command 的时候参数的
个数的设定是你可以根据需要设置的。只需要在后面 service 中能将参数值代到 command 中
最 终 能 实 现 你 要 检 测 的 命 令 即 可 。 到 此 为 止 你 可 以 感 受 到 nagios 的 灵 活 性 了 吧 。
到这里我们基本实现了 nagios 的监控功能,下面我们继续来看看其他设置。在定义 host 的
时候我们有个主机模板的设置,这个设置的定义在 object/template.cfg 中定义的,这是一个
系 统 自 带 的 配 置 文 件 , 关 于 我 们 所 使 用 的 Windows-Server 的 模 板 定 义 内 容 为 :
# Windows host definition template - This is NOT a real host, just a template!
define host{
name windows-server ; The name of this host template
use generic-host ; Inherit default values from the generic-host template
check_period 24x7 ; By default, Windows servers are monitored round the
clock
check_interval 5 ; Actively check the server every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 10 ; Check each server 10 times (max)
check_command check-host-alive ; Default command to check if servers are
"alive"
notification_period 24x7 ; Send notification out at any time - day or night
notification_interval 30 ; Resend notifications every 30 minutes
notification_options d,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins by default
hostgroups windows-servers ; Host groups that Windows servers should be a member
of
register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE
}
10. LinuxTone IT 运维专家论坛文档
objects 目 录 下 的 contact.cfg 中 定 义 的 是 报 警 联 系 人 。
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact
template (defined above)
alias Nagios Admin ; Full name of user
email netkey@linuxtone.com ; <<***** CHANGE THIS TO YOUR EMAIL
ADDRESS ******
address1 netkey530@hotmail.com ;这里是个自定义的变量设置,定义了
一 个 MSN 地 址 用 以 接 收 MSN 报 警 信 息 , 联 系 人 的 自 定 义 变 量 只 能 使 用 address1-
address6;通过这个设置你可以实现多种报警方式,如电话,手机短信等,通过在这里设置
你的电话,手机号,然后到报警命令定义里定义一个命令即可。
}
其使用了 generic-contact 这个联系模板,关于这个模板 templates.cfg 里的定义内容为:
define contact{
name generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states,
flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping
events, and scheduled downtime events
service_notification_commands notify-service-by-email,notify-service-by-msn ; send
service notifications via email
host_notification_commands notify-host-by-email,notify-host-by-msn ; send host
notifications via email
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A
REAL CONTACT, JUST A TEMPLATE!
}
上面我在该配置文件中增加了 notify-service-by-msn 和 notify-service-by-msn 的两种报警命
令
而关于报警的周期设置在 objects 下的 timeperiods.cfg 中,如我们上面在 service 里定义的
7x24 的 报 警 周 期 设 置 内 容 为 :
define timeperiod{
timeperiod_name 24x7