20.4. 配置 Nagios

$ sudo vim /etc/nagios3/nagios.cfg

cfg_dir=/etc/nagios3/hosts
cfg_dir=/etc/nagios3/servers
cfg_dir=/etc/nagios3/switches
cfg_dir=/etc/nagios3/routers

admin_email=nagios, neo.chen@example.com
		

20.4.1. authorized

add user neo for nagios

$ sudo htpasswd /etc/nagios3/htpasswd.users neo
New password:
Re-type new password:
Adding password for user neo
			
# grep default_user_name cgi.cfg
#default_user_name=guest

# grep authorized cgi.cfg
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
#authorized_for_read_only=user1,user2
			
$ sudo vim /etc/nagios3/cgi.cfg

authorized_for_all_services=nagiosadmin,neo
authorized_for_all_hosts=nagiosadmin,neo

20.4.2. contacts

$ sudo vim /etc/nagios3/conf.d/contacts_nagios2.cfg

###############################################################################
# contacts.cfg
###############################################################################

define contact{
        contact_name                    neo
        alias                           Neo
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email                           neo.chen@example.com
        }

###############################################################################
###############################################################################
#
# CONTACT GROUPS
#
###############################################################################
###############################################################################

# We only have one contact in this simple configuration file, so there is
# no need to create more than one contact group.

define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 root, neo
        }

当服务出现w—报警(warning),u—未知(unkown),c—严重(critical),r—从异常恢复到正常,在这四种情况下通知联系人

当主机出现d-当机(down),u—返回不可达(unreachable),r—从异常情况恢复正常,在这3种情况下通知联系人

确认 contact_groups 已经设置

neo@monitor:/etc/nagios3$ grep admins conf.d/generic-host_nagios2.cfg
                contact_groups                  admins
neo@monitor:/etc/nagios3$ grep admins conf.d/generic-service_nagios2.cfg
                contact_groups                  admins
			

20.4.3. hostgroups

$ sudo vim /etc/nagios3/conf.d/hostgroups_nagios2.cfg

define hostgroup {
        hostgroup_name  mysql-servers
                alias           MySQL Servers
                members         *
        }

20.4.4. generic-service

$ cat /etc/nagios3/conf.d/generic-service_nagios2.cfg
# generic service template definition
define service{
        name                            generic-service ; The 'name' of this service template
        active_checks_enabled           1       ; Active service checks are enabled
        passive_checks_enabled          1       ; Passive service checks are enabled/accepted
        parallelize_check               1       ; Active service checks should be parallelized (disabling this can lead to major performance problems)
        obsess_over_service             1       ; We should obsess over this service (if necessary)
        check_freshness                 0       ; Default is to NOT check service 'freshness'
        notifications_enabled           1       ; Service notifications are enabled
        event_handler_enabled           1       ; Service event handler is enabled
        flap_detection_enabled          1       ; Flap detection is enabled
        failure_prediction_enabled      1       ; Failure prediction is enabled
        process_perf_data               1       ; Process performance data
        retain_status_information       1       ; Retain status information across program restarts
        retain_nonstatus_information    1       ; Retain non-status information across program restarts
                notification_interval           0               ; Only send notifications on status change by default.
                is_volatile                     0
                check_period                    24x7
                normal_check_interval           5
                retry_check_interval            1
                max_check_attempts              4
                notification_period             24x7
                notification_options            w,u,c,r
                contact_groups                  admins
        register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
        }
			
  • notification_interval 报警发送间隔,单位分钟
  • normal_check_interval 间隔时间
  • retry_check_interval 重试间隔时间
  • max_check_attempts 检查次数,4次失败后报警

20.4.5. SOUND OPTIONS

发出警报声

$ sudo vim /etc/nagios3/cgi.cfg

# SOUND OPTIONS
# These options allow you to specify an optional audio file
# that should be played in your browser window when there are
# problems on the network.  The audio files are used only in
# the status CGI.  Only the sound for the most critical problem
# will be played.  Order of importance (higher to lower) is as
# follows: unreachable hosts, down hosts, critical services,
# warning services, and unknown services. If there are no
# visible problems, the sound file optionally specified by
# 'normal_sound' variable will be played.
#
#
# <varname>=<sound_file>
#
# Note: All audio files must be placed in the /media subdirectory
# under the HTML path (i.e. /usr/local/nagios/share/media/).

host_unreachable_sound=hostdown.wav
host_down_sound=hostdown.wav
service_critical_sound=critical.wav
service_warning_sound=warning.wav
service_unknown_sound=warning.wav
normal_sound=noproblem.wav

20.4.6. SMS 短信

vim /etc/nagios3/commands.cfg

# 'notify-host-by-sms' command definition
define command{
        command_name    notify-host-by-sms
        command_line    /srv/sms/sms $CONTACTPAGER$ "Host: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n"
        }

# 'notify-service-by-sms' command definition
define command{
        command_name    notify-service-by-sms
        command_line    /srv/sms/sms $CONTACTPAGER$ "Service: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$"
        }
			
sudo vim /etc/nagios3/conf.d/contacts_nagios2.cfg
define contact{
        contact_name                    neo
        alias                           Neo
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-by-email, notify-service-by-sms
        host_notification_commands      notify-host-by-email, notify-host-by-sms
        email                           neo.chen@example.com
        pager 							13113668899
        }

20.4.7. nrpe plugins

neo@monitor:/etc/nagios3/hosts$ sudo cat www.example.com.cfg

define host{
        use             generic-host            ; Inherit default values from a template
        host_name       www.example.com             ; The name we're giving to this host
        alias           Some Remote Host        ; A longer name associated with the host
        address         172.16.1.10              ; IP address of the host
        hostgroups      http-servers                    ; Host groups this host is associated with
        }

# NRPE disk check.
define service {
        use                             generic-service
        host_name                       www.example.com
        service_description             nrpe-disk
        check_command                   check_nrpe_1arg!check_all_disks!172.16.1.10
}
define service {
        use                             generic-service
        host_name                       www.example.com
        service_description             nrpe-users
        check_command                   check_nrpe_1arg!check_users!172.16.1.10
}
define service {
        use                             generic-service
        host_name                       www.example.com
        service_description             nrpe-swap
        check_command                   check_nrpe_1arg!check_swap!172.16.1.10
}
define service {
        use                             generic-service
        host_name                       www.example.com
        service_description             nrpe-procs
        check_command                   check_nrpe_1arg!check_total_procs!172.16.1.10
}
define service {
        use                             generic-service
        host_name                       www.example.com
        service_description             nrpe-load
        check_command                   check_nrpe_1arg!check_load!172.16.1.10
}
define service {
        use                             generic-service
        host_name                       www.example.com
        service_description             nrpe-zombie_procs
        check_command                   check_nrpe_1arg!check_zombie_procs!172.16.1.10
}

原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

时间: 2024-10-23 13:33:07

20.4. 配置 Nagios的相关文章

Struts.2.3.20.1配置struts.xml位置的问题

问题描述 Struts.2.3.20.1配置struts.xml位置的问题 我在使用SSH框架时,一开始将struts.xml放在了src文件夹下,整个系统是可以用的,然后我又新建了一个source package:config,把struts.xml放在这包下面也可以使用,然后我又在config包下面新建了一个package:struts2,把struts.xml拖进了struts2包下,并在web.xml中配置了位置信息,如图,发现系统就找不到定义的action了,是什么原因呢? 解决方案

Centos 5系统下安装和配置nagios监控系统

我们的网络和服务器要被细心的照看,要不然你会有很多麻烦的 还是找个工具来帮助我们管理这些让人牵挂的机器吧----nagios 在这里简单的配置了一下监控主机,深入的配置需要多多学习,网上的资料很多 下面简单的写出来我自己的配置,也许有不对的地方,请指出,谢谢,您的参阅 1.创建nagios用户 adduser nagios mkdir /usr/local/nagios chown nagios.nagios /usr/local/nagios 3.解压下载的安装包 tar xzvf nagio

Apache2+php4.3.6+MySQL4.0.20+SSL配置过程

Apache2+php4.3.6+MySQL4.0.20+SSL详细配置过程: 首先安装将需要的文件都放到root目录下: 1.MySQL-client-4.0.20-0.i386.rpm 2. MySQL-server-4.0.20-0.i386.rpm 3. httpd-2.0.49.tar.gz 4. php-4.3.6.tar.gz 我们先来安装MySQL,步骤如下: # >rpm –Uvh MySQL-server-4.0.20-0.i386.rpm # >rpm -Uvh MySQ

教你在Ubuntu 11.10中搭建和配置Nagios

我们都知道Nagios是一个监视系统运行状态和网络信息的监视系统.Nagios能监视所指定的本地或远程主机以及服务,同时提供异常通知功能等.Nagios可运行在Linux/Unix平台之上,同时提供一个可选的基于浏览器的WEB界面以方便系统管理人员查看网络状态,各种系统问题,以及日志等等. Nagios的主要功能特点: - 监视网络服务 (SMTP, POP3, HTTP, NNTP, PING等) - 监视主机资源 (进程, 磁盘等) - 简单的插件设计可以轻松扩展Nagios的监视功能 -

CentOS系统快速配置Nagios监控服务器

Nagios 监控实现原理 Nagios 软件需安装在一台独立的服务器上运行,这台服务器称为监控中心,监控中心服务器可以采用 Linux 或 Unix 操作系统:每一台被监视的硬件主机或服务都运行一个与监控中心服务器进行通信的 Nagios 软件后台程序,也可以理解为 Agent 或插件均可.监控中心服务器读取配置文件中的指令与远程的守护程序进行通信,并且指示远程的守护程序进行必要的检查.虽然 Nagios 软件必须在 Linux 或 Unix 操作系统上运行,但是远程被监控的机器可以是任何能够

20.5. 配置监控设备

20.5.1. routers vim /etc/nagios3/routers/firewall.cfg define host{ use generic-host; Inherit default values from a template host_name firewall ; The name we're giving to this switch alias Cisco PIX 515E Firewall ; A longer name associated with the sw

Tomcat6.0.20 ActiveMQ 配置出错

问题描述 conf/context.xml的配置如下<Resourcename="jms/FailoverConnectionFactory"auth="Container"type="org.apache.activemq.ActiveMQConnectionFactory"description="JMSConnectionFactory"factory="org.apache.activemq.jndi.

Ubuntu 12.04中安装配置Nagios 4.0.5步骤详解

以下是2014-4-17安装记录: == 服务端 == 安装依赖包:(其实不装也能安装成功,就是部分功能会disabled) sudo apt-get install build-essential libssl-dev \ libgd2-xpm-dev libpng12-dev php5-gd libgd2-xpm 用户组: sudo adduser --system --no-create-home --disabled-login --group nagios sudo groupadd

97.4. 配置 Nagios

$ sudo vim /etc/nagios3/nagios.cfg cfg_dir=/etc/nagios3/hosts cfg_dir=/etc/nagios3/servers cfg_dir=/etc/nagios3/switches cfg_dir=/etc/nagios3/routers admin_email=nagios, neo.chen@example.com 97.4.1. authorized add user neo for nagios $ sudo htpasswd