博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
97.4. 配置 Nagios
阅读量:6624 次
发布时间:2019-06-25

本文共 9304 字,大约阅读时间需要 31 分钟。

$ sudo vim /etc/nagios3/nagios.cfgcfg_dir=/etc/nagios3/hostscfg_dir=/etc/nagios3/serverscfg_dir=/etc/nagios3/switchescfg_dir=/etc/nagios3/routersadmin_email=nagios, neo.chen@example.com

97.4.1. authorized

add user neo for nagios

$ sudo htpasswd /etc/nagios3/htpasswd.users neoNew password:Re-type new password:Adding password for user neo

# grep default_user_name cgi.cfg#default_user_name=guest# grep authorized cgi.cfgauthorized_for_system_information=nagiosadminauthorized_for_configuration_information=nagiosadminauthorized_for_system_commands=nagiosadminauthorized_for_all_services=nagiosadminauthorized_for_all_hosts=nagiosadminauthorized_for_all_service_commands=nagiosadminauthorized_for_all_host_commands=nagiosadmin#authorized_for_read_only=user1,user2

$ sudo vim /etc/nagios3/cgi.cfgauthorized_for_all_services=nagiosadmin,neoauthorized_for_all_hosts=nagiosadmin,neo

97.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                  adminsneo@monitor:/etc/nagios3$ grep admins conf.d/generic-service_nagios2.cfg                contact_groups                  admins

97.4.3. hostgroups

$ sudo vim /etc/nagios3/conf.d/hostgroups_nagios2.cfgdefine hostgroup {        hostgroup_name  mysql-servers                alias           MySQL Servers                members         *        }

97.4.4. generic-service

$ cat /etc/nagios3/conf.d/generic-service_nagios2.cfg# generic service template definitiondefine 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次失败后报警

97.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.### 
=
## 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.wavhost_down_sound=hostdown.wavservice_critical_sound=critical.wavservice_warning_sound=warning.wavservice_unknown_sound=warning.wavnormal_sound=noproblem.wav

97.4.6. SMS 短信

vim /etc/nagios3/commands.cfg# 'notify-host-by-sms' command definitiondefine 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 definitiondefine 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.cfgdefine 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        }

97.4.7. nrpe plugins

neo@monitor:/etc/nagios3/hosts$ sudo cat www.example.com.cfgdefine 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 系列 手札

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

你可能感兴趣的文章
手游-放开那三国socket协议分析
查看>>
SQL Lazy Spool Eager Spool
查看>>
type的解释
查看>>
Windows Phone 8 开发环境搭建
查看>>
2017:IDC市场规模将持续增长 增速放缓
查看>>
从自动驾驶到学习机器学习:解读2017科技发展的15大趋势
查看>>
SinoBBD探索"一体化"大数据创新发展
查看>>
互联网金融带来新机遇 数据合规性不容忽视
查看>>
智能家庭本周锋闻:专注跨界100年
查看>>
在Linux中永久并安全删除文件和目录的方法
查看>>
全民直播时代 内容监管还得靠技术
查看>>
10款Web开发最佳的Python框架
查看>>
c++ 类的对象与指针
查看>>
【算法】数据结构
查看>>
Boolean operations between triangle meshes
查看>>
面积并
查看>>
java-JDBC
查看>>
通信术语解释
查看>>
javascript中数据属性与访问器属性
查看>>
对.NET跨平台的随想
查看>>