0
点赞
收藏
分享

微信扫一扫

Nagios使用手册

兮城 2022-07-12 阅读 72


目 录

​​1. 概述 1​​

​​1.1 编写目的 1​​

​​1.2 环境准备 1​​

​​1.3 参考资料 1​​

​​2. 安装配置 2​​

​​2.1 Nagios安装 2​​

​​2.1.1. 功能介绍 2​​

​​2.1.2. 基础包安装 2​​

​​2.1.3. 安装Nagios 3​​

​​2.1.4. 安装Apache 3​​

​​2.1.5. 安装PHP 4​​

​​2.1.6. 整合Apache 4​​

​​2.1.7. 汉化步骤 7​​

​​2.1.8. 安装插件 8​​

​​2.2 Nagios配置 8​​

​​2.2.1. 配置文件 8​​

​​2.2.2. 配置文件关系 9​​

​​2.2.3. 配置Nagios 10​​

​​2.2.4. 验证配置文件 19​​

​​2.3 Pnpnagios安装 19​​

​​2.3.1. 安装Rrdtools 19​​

​​2.3.2. 安装Pnpnagios 20​​

​​2.3.3. 整合Nagios 20​​

​​3. 监控配置 23​​

​​3.1 Centos监控 23​​

​​3.1.1. 安装NRPE 23​​

​​3.1.2. 监控配置 25​​

​​3.2 Oracle监控 29​​

​​3.2.1. 安装Check_oracle_health 29​​

​​3.2.2. 远程监控配置 30​​

​​3.3 Weblogic监控 34​​

​​3.3.1. 安装wlsagent 34​​

​​3.3.2. 远程监控配置 37​​

​​3.4 短信网关配置 39​​

​​3.4.1. 编写脚本 39​​

​​3.4.2. 配置 40​​



  1. 概述
  1. 编写目的本文档是针对nagios基础部署整理编写的,为运维人员提供centos5.8环境下nagios的安装和配置指导,帮助运维人员以及相关人员能够快速安装配置nagios。
  2. 环境准备适用于centos5.8 X64操作系统下,环境如下:

主机名

IP地址

安装软件

监控内容

nagios-server

192.168.3.202

apache php nagios nagios-plugins

rrdtools pnpnagios

liunx服务

nagios1

192.168.3.200

nagios-plugins nrpe perl check_oracle_health

Oraclecentos服务

nagios2

192.168.3.201

nagios-pluginsnrpe wlsagentperl

weblogic服务yum

  1. 参考资料​​http://www.nagios.com/solutions​​
    ​​​http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html​​
    ​​​http://code.google.com/p/wlsagent/w/list​​
    ​​​http://labs.consol.de/nagios/check_oracle_health/​​
  2. Nagios安装
  1. 功能介绍
  1. 监控网络服务(SMTPPOP3HTTPNNTPPING等);
  2. 监控主机资源(处理器负荷、磁盘利用率等);
  3. 简单地插件设计使得用户可以方便地扩展自己服务的检测方法;
  4. 并行服务检查机制;
  5. 具备定义​​网络分层​​结构的能力,用"parent"主机定义来表达网络主机间的关系,这种关系可被用来发现和明晰主机宕机或不可达状态;
  6. 当服务或​​主机​​问题产生与解决时将告警发送给联系人(通过EMail、短信、用户定义方式);
  7. 可以定义一些处理程序,使之能够在服务或者​​主机​​发生故障时起到预防作用;
  8. 自动的日志滚动功能;
  9. 可以支持并实现对​​主机​​​​冗余​​监控;
  10. 可选的WEB界面用于查看当前的网络状态、通知和故障历史、日志文件等。
  1. 基础包安装
  1. 安装依赖包[root@nagios-server opt]# yum -y install gcc glibc glibc-common gd gd-devel gd-devel openssl-devel libxml2-devel xinetd.d
  2. 创建用户

[root@nagios-server opt]# useradd nagios

[root@nagios-server opt]# mkdir -p /usr/local/nagios

[root@nagios-server opt]# chown -R nagios.nagios /usr/local/nagios/

  1. 安装Nagios
  1. 源码安装[root@nagios-server opt]# tar zxvf nagios-3.4.3.tar.gz
    [root@nagios-server opt]# cd nagios
    [root@nagios-server nagios]# ./configure --prefix=/usr/local/nagios/
    [root@nagios-server nagios]# make all
    [root@nagios-server nagios]# make install
    [root@nagios-server nagios]# make install-init 设置系统服务
    [root@nagios-server nagios]# make install-commandmode #设置权限
    [root@nagios-server nagios]# make install-config #安装示例程序
    # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //检查配置文件的正确性
  2. 启动服务[root@~]#/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
    [root@~]#/etc/init.d/nagios start
  3. 添加自启动

[root@nagios-server nagios]# chkconfig --add nagios

[root@nagios-server nagios]# chkconfig --level 35 nagios on

[root@nagios-server nagios]# chkconfig --list nagios

nagios 0:off 1:off 2:off 3:on 4:on 5:on 6:off

  1. 安装Apache
  1. 卸载自带apache[root@nagios-server nagios]# rpm -qa|grep httpd
    httpd-2.2.3-63.el5.centos
    httpd-manual-2.2.3-63.el5.centos
    system-config-httpd-1.3.3.3-1.el5
    [root@nagios-server nagios]# rpm -e httpd-2.2.3-63.el5.centos --nodeps
  2. 源码安装[root@nagios-server opt]#tar zxvf httpd-2.2.23.tar.gz
    [root@nagios-server opt]# cd httpd-2.2.23
    [root@nagios-server httpd-2.2.23]# ./configure --prefix=/usr/local/apache2
    [root@nagios-server httpd-2.2.23]# make && make install
  3. 启动apache:vi /usr/local/apache2/conf/httpd.cnf
    #ServerName ​​www.example.com:80​​下面添加这一行:
    ServerName localhost:80
    [root@nagios-server bin]# /usr/local/apache2/bin/apachectl start
  4. ​​将Apache添加为Linux的系统服务 实现自启动 ​​

[root@nagios-server ~]#cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
[root@nagios-server ~]#ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S61httpd

[root@nagios-server ~]#ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S61httpd

编辑vi /etc/rc.d/init.d/httpd,在第2行添加如下信息:

# chkconfig: 35 61 61
# description: Apache

[root@nagios-server ~]#chkconfig --add httpd

  1. 安装PHP
  1. 源码安装

报错:

# yum -y install perl-devel

# yum -y install sqlite-devel

[root@nagios-server opt]# tar zxvf php-5.4.10.tar.gz

[root@nagios-server opt]# cd php-5.4.10

#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs

[root@nagios-server php-5.4.10]# make &&make install

  1. 整合Apache
  1. 修改运行httpd服务用户的组vi /usr/local/apache2/conf/httpd.conf
    User daemon
    Group daemon
    修改为
    User nagios
    Group nagios
  2. 配置apache解析php后缀名使用 PHP 解析编辑/usr/local/apache2/conf/httpd.conf文件
    166|
    <IfModule dir_module>
    DirectoryIndex index.html
    </IfModule>
    修改为
    <IfModule dir_module>
    DirectoryIndex index.html index.php
    </IfModule>
    添加:
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php.php .phtml
  3. 测试/usr/local/apache2/htdocs目录下,新建test.php文件,添加一下内容
    <?php
    phpinfo();
    ?>
    浏览器访问该地址:​​http://ip/test.php​​
  4. Nagios使用手册_oracle


  5. 添加nagios的web监控页面的验证配置vi /usr/local/apache2/conf/httpd.conf 添加如下代码
    #setting for nagios
    ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" //55行
    <Directory "/usr/local/nagios/sbin">
    AuthType Basic
    Options ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "Nagios Access"
    AuthUserFile /usr/local/nagios/etc/htpasswd
    Require valid-user
    </Directory>
    Alias /nagios "/usr/local/nagios/share"
    <Directory "/usr/local/nagios/share">
    AuthType Basic
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "nagios Access"
    AuthUserFile /usr/local/nagios/etc/htpasswd // 用于此目录访问身份验证的文件
    Require valid-user
    </Directory>
  6. 创建apache目录验证文件

[root@nagios-server conf]# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd zrsf 用户名

New password:

Re-type new password:

Adding password for user zrsf

  1. 汉化步骤
  1. 安装汉化包(可选择)

[root@nagios-server opt]# tar -jxvf nagios-cn-3.2.3.tar.bz2

[root@nagios-server opt]# cd nagios-cn-3.2.3

[root@nagios-server nagios-cn-3.2.3]# ./configure --prefix=/usr/local/nagios/ --with-command-group=nagios

[root@nagios-server nagios-cn-3.2.3]# make all

[root@nagios-server nagios-cn-3.2.3]# make install

[root@nagios-server nagios-cn-3.2.3]# make install-init

[root@nagios-server nagios-cn-3.2.3]# make install-commandmode

[root@nagios-server nagios-cn-3.2.3]# make install-config

[root@nagios-server nagios-cn-3.2.3]# make install-webconf

可直接安装汉化包,或者安装汉化插件。(若已安装nagios,再安装汉化包原配置文件会被覆盖)

  1. 安装插件
  1. 安装nagios-plugin,可监控本身# tar zxvf nagios-plugins-1.4.16.tar.gz
    # cd nagios-plugins-1.4.16
    # ./configure --prefix=/usr/local/nagios
    # make && make install
  2. 安装check-nrpe

# tar zxvf nrpe-2.13.tar.gz

# cd nrpe-2.13

# ./configure --prefix=/usr/local/nagios

# make all

# make install-plugin

  1. 配置文件Nagios 安装完毕后,默认的配置文件在/usr/local/nagios/etc目录下:
    # ls /usr/local/nagios/etc/
    cgi.cfg nagios.cfg objects resource.cfg statuswrl.cgi
    hosts.cfg nagiosgraph.cfg
    # ls /usr/local/nagios/etc/objects
    commands.cfg localhost.cfg switch.cfg timeperiods.cfg
    contacts.cfg printer.cfg templates.cfg windows.cfg
    每个文件或目录含义如下表所示:

文件名或目录名

用途

cgi.cfg

控制CGI访问的配置文件(*cgi为是HTTP服务器与你的或其它机器 上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上。)

nagios.cfg

Nagios 主配置文件

resource.cfg

变量定义文件,又称为资源文件,在些文件中定义变量,以便由其他配置文件引用,如$USER1$

objects

objects 是一个目录,在此目录下有很多配置文件模板,用于定义Nagios 对象

objects/commands.cfg

命令定义配置文件,其中定义的命令可以被其他配置文件引用

objects/contacts.cfg

定义联系人和联系人组的配置文件

objects/localhost.cfg

定义监控本地主机的配置文件

objects/printer.cfg

定义监控打印机的一个配置文件模板,默认没有启用此文件

objects/switch.cfg

定义监控路由器的一个配置文件模板,默认没有启用此文件

objects/templates.cfg

定义主机和服务的一个模板配置文件,可以在其他配置文件中引用

objects/timeperiods.cfg

定义Nagios 监控时间段的配置文件

objects/windows.cfg

监控Windows 主机的一个配置文件模板,默认没有启用此文件

  1. 配置文件关系在nagios的配置过程中涉及到的几个定义有:主机、主机组,服务、服务组,联系人、联系人组,监控时间,监控命令等,从这些定义可以看出,nagios各个配置文件之间是互为关联,彼此引用的。
    成功配置出一台nagios监控系统,必须要弄清楚每个配置文件之间依赖与被依赖的关系,最重要的有四点:
    第一:定义监控哪些主机、主机组、服务和服务组;
    第二:定义这个监控要用什么命令实现;
    第三:定义监控的时间段;
    第四:定义主机或服务出现问题时要通知的联系人和联系人组。
  2. 配置Nagios为维护方便,建议将nagios各个定义对象创建独立的配置文件:
  • 创建/usr/local/nagios/etc/hosts.cfg文件来定义主机和主机组
  • 创建/usr/local/nagios/etc/service/centos.cfg weblogic.cfg oracle.cfg文件来定义服务
  • 用默认的contacts.cfg文件来定义联系人和联系人组
  • 用默认的commands.cfg文件来定义命令
  • 用默认的timeperiods.cfg来定义监控时间段
  • 用默认的templates.cfg文件作为资源引用文件
  1. templates.cfg文件nagios主要用于监控主机资源以及服务,在nagios配置中称为对象,为了不必重复定义一些监控对象,Nagios引入了一个模板配置文件,将一些共性的属性定义成模板,以便于多次引用。这就是templates.cfg的作用.详细介绍下templates.cfg文件中每个参数的含义:
    define contact{
    name generic-contact ; 联系人名称
    service_notification_period 24x7 ; 当服务出现异常时,发送通知的时间段,这个时间段"24x7"在timeperiods.cfg文件中定义
    host_notification_period 24x7 ; 当主机出现异常时,发送通知的时间段,这个时间段"24x7"在timeperiods.cfg文件中定义
    service_notification_options w,u,c,r ; 这个定义的是“通知可以被发出的情况”。w即warn,表示警告状态,u即unknown,表示不明状态;
    ; c即criticle,表示紧急状态,r即recover,表示恢复状态;
    ; 也就是在服务出现警告状态、未知状态、紧急状态和重新恢复状态时都发送通知给使用者。
    host_notification_options d,u,r ; 定义主机在什么状态下需要发送通知给使用者,d即down,表示宕机状态;
    ; u即unreachable,表示不可到达状态,r即recovery,表示重新恢复状态。
    service_notification_commands notify-service-by-email ; 服务故障时,发送通知的方式,可以是邮件和短信,这里发送的方式是邮件;
    ; 其中“notify-service-by-email”在commands.cfg文件中定义。
    host_notification_commands notify-host-by-email ; 主机故障时,发送通知的方式,可以是邮件和短信,这里发送的方式是邮件;
    ; 其中“notify-host-by-email”在commands.cfg文件中定义。
    register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
    }
    define host{
    name generic-host ; 主机名称,这里的主机名,并不是直接对应到真正机器的主机名;
    ; 乃是对应到在主机配置文件里所设定的主机名。
    notifications_enabled 1 ; Host notifications are enabled
    event_handler_enabled 1 ; Host event handler is enabled
    flap_detection_enabled 1 ; Flap detection is enabled
    failure_prediction_enabled 1 ; Failure prediction is enabled
    process_perf_data 1 ; 其值可以为0或1,其作用为是否启用Nagios的数据输出功能;
    ; 如果将此项赋值为1,那么Nagios就会将收集的数据写入某个文件中,以备提取。
    retain_status_information 1 ; Retain status information across program restarts
    retain_nonstatus_information 1 ; Retain non-status information across program restarts
    notification_period 24x7 ; 指定“发送通知”的时间段,也就是可以在什么时候发送通知给使用者。
    register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
    }
    define host{
    name linux-server ; 主机名称
    use generic-host ; use表示引用,也就是将主机generic-host的所有属性引用到linux-server中来;
    ; 在nagios配置中,很多情况下会用到引用。
    check_period 24x7 ; 这里的check_period告诉nagios检查主机的时间段
    check_interval 5 ; nagios对主机的检查时间间隔,这里是5分钟。
    retry_interval 1 ; 重试检查时间间隔,单位是分钟。
    max_check_attempts 10 ; nagios对主机的最大检查次数,也就是nagios在检查发现某主机异常时,并不马上判断为异常状况;
    ; 而是多试几次,因为有可能只是一时网络太拥挤,或是一些其他原因,让主机受到了一点影响;
    ; 这里的10就是最多试10次的意思。
    check_command check-host-alive ; 指定检查主机状态的命令,其中“check-host-alive”在commands.cfg文件中定义。
    notification_period 24x7 ; 主机故障时,发送通知的时间范围,其中“workhours”在timeperiods.cfg中进行了定义;
    ; 下面会陆续讲到。
    notification_interval 10 ; 在主机出现异常后,故障一直没有解决,nagios再次对使用者发出通知的时间。单位是分钟;
    ; 如果你觉得,所有的事件只需要一次通知就够了,可以把这里的选项设为0
    notification_options d,u,r ; 定义主机在什么状态下可以发送通知给使用者,d即down,表示宕机状态;
    ; u即unreachable,表示不可到达状态;
    ; r即recovery,表示重新恢复状态。
    contact_groups ts ; 指定联系人组,这个“admins”在contacts.cfg文件中定义。
    register 0 ; DONT REGISTER THIS DEFINITION - ITS 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 10 ; Resend notifications every 30 minutes
    notification_options d,r ; Only send notifications for specific host states
    contact_groups ts ; 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
    }
    define service{
    name generic-service ; 定义一个服务名称
    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
    is_volatile 0 ; The service is not volatile
    check_period 24x7 ; 这里的check_period告诉nagios检查服务的时间段。
    max_check_attempts 3 ; nagios对服务的最大检查次数。
    normal_check_interval 5 ; 此选项是用来设置服务检查时间间隔,也就是说,nagios这一次检查和下一次检查之间所隔的时间;
    ; 这里是5分钟。
    retry_check_interval 2 ; 重试检查时间间隔,单位是分钟。
    contact_groups ts ; 指定联系人组
    notification_options w,u,c,r ; 这个定义的是“通知可以被发出的情况”。w即warn,表示警告状态;
    ; u即unknown,表示不明状态;
    ; c即criticle,表示紧急状态,r即recover,表示恢复状态;
    ; 也就是在服务出现警告状态、未知状态、紧急状态和重新恢复后都发送通知给使用者。
    notification_interval 10 ; Re-notify about service problems every hour
    notification_period 24x7 ; 指定“发送通知”的时间段,也就是可以在什么时候发送通知给使用者。
    register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
    }
    define service{
    name local-service ; The name of this service template
    use generic-service ; Inherit default values from the generic-service definition
    max_check_attempts 4 ; Re-check the service up to 4 times in order to determine its final (hard) state
    normal_check_interval 5 ; Check the service every 5 minutes under normal conditions
    retry_check_interval 1 ; Re-check the service every minute until a hard state can be determined
    register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
    }
  2. hosts.cfg文件此文件默认不存在,需要手动创建,hosts.cfg主要用来指定被监控的主机地址以及相关属性信息,根据目标配置如下:vim etc/hosts.cfg
    define host{ //定义主机
    use linux-server
    host_name 192.168.3.200
    alias Oracle
    statusmap_image linux40.jpg
    address 192.168.3.200
    }
    define host{
    use linux-server
    host_name 192.168.3.201
    alias Weblogic
    statusmap_image linux40.jpg
    address 192.168.3.201
    }
    define hostgroup{
    hostgroup_name nagios-servers
    alias nagios servers
    members 192.168.3.200,192.168.3.201
    }
  3. resource.cfg文件$USER1$=/usr/local/nagios/libexec
  4. 文件此文件默认是存在的,无需修改即可使用,当然如果有新的命令需要加入时,在此文件进行添加即可。
    #notify-host-by-email命令的定义
    define command{
    命令名称,即定义了一个主机异常时发送邮件的命令。
    command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ #命令具体的执行方式。
    }
    #notify-service-by-email命令的定义
    define command{
    命令名称,即定义了一个服务异常时发送邮件的命令
    command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
    }
    #check-host-alive命令的定义
    define command{
    命令名称,用来检测主机状态。
    command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
    这里的变量$USER1$在resource.cfg文件中进行定义,即$USER1$=/usr/local/nagios/libexec;
    那么check_ping的完整路径为/usr/local/nagios/libexec/check_ping;
    “-w 3000.0,80%”中“-w”说明后面的一对值对应的是“WARNING”状态,“80%”是其临界值。
    “-c 5000.0,100%”中“-c”说明后面的一对值对应的是“CRITICAL”,“100%”是其临界值。
    “-p 1”说明每次探测发送一个包。
    }
    define command{
    command_name check_local_disk
    是指在调用这个命令的时候,命令后面的第一个参数。
    }
    define command{
    command_name check_local_load
    command_line $USER1$/check_load -w $ARG1$ -c $ARG2$
    }
    define command{
    command_name check_local_procs
    command_line $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
    }
    define command{
    command_name check_local_users
    command_line $USER1$/check_users -w $ARG1$ -c $ARG2$
    }
    define command{
    command_name check_local_swap
    command_line $USER1$/check_swap -w $ARG1$ -c $ARG2$
    }
    define command{
    command_name check_ftp
    command_line $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$
    }
    define command{
    command_name check_http
    command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
    }
    define command{
    command_name check_ssh
    command_line $USER1$/check_ssh $ARG1$ $HOSTADDRESS$
    }
    define command{
    command_name check_ping
    command_line $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
    }
    define command{
    command_name check_nt
    command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
    }
  5. contacts.cfg文件contacts.cfg是一个定义联系人和联系人组的配置文件,当监控的主机或者服务出现故障,nagios会通过指定的通知方式(邮件或者短信)将信息发给这里指定的联系人或者使用者。
    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 nagios@localhost
    }
    define contact{
    contact_name zrsfadmin ; Short name of user
    use generic-contact ; Inherit default values from generic-contact template (defined above)
    alias Zrsf Admin
    email zcm_mail@126.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
    }
    define contactgroup{
    contactgroup_name admins
    alias Nagios Administrators
    members nagiosadmin
    }
    #####add by zhaocm20140509#####
    define contactgroup{
    contactgroup_name ts
    alias Test
    members zrsfadmin
    }
  6. timeperiods.cfg文件此文件只要用于定义监控的时间段,使用默认模板文件。
  7. nagios.cfg文件nagios.cfg默认的路径为/usr/local/nagios/etc/nagios.cfg,是nagios的核心配置文件,所有的对象配置文件都必须在这个文件中进行定义才能发挥其作用,这里只需将对象配置文件在Nagios.cfg文件中进行引用即可。
    log_file=/usr/local/nagios/var/nagios.log # 定义nagios日志文件的路径
    cfg_file=/usr/local/nagios/etc/objects/commands.cfg # “cfg_file”变量用来引用对象配置文件,如果有更多的对象配置文件,在这里依次添加即可。
    cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
    cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
    cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
    cfg_file=/usr/local/nagios/etc/objects/templates.cfg
    cfg_file=/usr/local/nagios/etc/objects/localhost.cfg # 本机配置文件
    cfg_file=/usr/local/nagios/etc/objects/windows.cfg # windows 主机配置文件
    object_cache_file=/usr/local/nagios/var/objects.cache # 该变量用于指定一个“所有对象配置文件”的副本文件,或者叫对象缓冲文件
    precached_object_file=/usr/local/nagios/var/objects.precache
    resource_file=/usr/local/nagios/etc/resource.cfg # 该变量用于指定nagios资源文件的路径,可以在nagios.cfg中定义多个资源文件。
    status_file=/usr/local/nagios/var/status.dat # 该变量用于定义一个状态文件,此文件用于保存nagios的当前状态、注释和宕机信息等。
    status_update_interval=10 # 该变量用于定义状态文件(即status.dat)的更新时间间隔,单位是秒,最小更新间隔是1秒。
    nagios_user=nagios # 该变量指定了Nagios进程使用哪个用户运行。
    nagios_group=nagios # 该变量用于指定Nagios使用哪个用户组运行。
    check_external_commands=1 # 该变量用于设置是否允许nagios在web监控界面运行cgi命令;
    # 也就是是否允许nagios在web界面下执行重启nagios、停止主机/服务检查等操作;
    # “1”为运行,“0”为不允许。
    command_check_interval=10s # 该变量用于设置nagios对外部命令检测的时间间隔,如果指定了一个数字加一个"s"(如10s);
    # 那么外部检测命令的间隔是这个数值以秒为单位的时间间隔;
    # 如果没有用"s",那么外部检测命令的间隔是以这个数值的“时间单位”的时间间隔。
    interval_length=60 # 该变量指定了nagios的时间单位,默认值是60秒,也就是1分钟;
    # 即在nagios配置中所有的时间单位都是分钟。
  8. centos.cfg weblogic.cfg oracle.cfg文件配置分别不同模块的配置
  1. 验证配置文件Nagios 在验证配置文件方面做的非常到位,只需通过一个命令即可完成:
    # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  2. 安装Rrdtools# yum -y instll install cairo-devel libxml2-devel pango-devel pango libpng-devel freetype freetype-devel libart_lgpl-devel
    #tar zxvf rrdtool-1.4.8.tar.gz
    #cd rrdtool
    #./configure --prefix=/usr/local/rrdtool
    #make
    #make install
  3. 安装Pnpnagios
  1. 源码安装# tar xvf pnp4nagios-0.6.21
    # cd pnp4nagios-0.6.21
    #./configure --prefix=/usr/local/pnp4nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool
    # make all
    # make install
    # make install-webconf
    # make install-config
    # make install-init
  2. 安装验证浏览器访问:​​http://192.168.3.202/pnp4nagios/index.php​​
  3. Nagios使用手册_oracle_02


  4. 删除或者重命名/usr/local/pnp4nagios/share/install.pnp

[root@nagios-server share]# mv install.php install.php.bak

  1. 整合Nagios
  1. 配置apache将/etc/httpd/conf.d/pnp4nagios.conf中的所有内容全部添加到apache的httpd.conf文件最后。
    # cat /etc/httpd/conf.d/pnp4nagios.conf >>/usr/local/apache2/conf/httpd.conf
  2. 创建配置文件# cd /usr/local/pnp4nagios/etc
    # misccommands.cfg
    # nagios.cfg
    # mv mv rra.cfg-sample rra.cfg
    # process_perfdata.cfg
    #cd pages
    # mv web_traffic.cfg-sample web_traffic.cfg
    # cd ../check_commands
    # check_all_local_disks.cfg
    # check_nrpe.cfg
    # check_nwstat.cfg
  3. 重启服务# /etc/init.d/npcd restart
  4. 修改 nagios 的配置文件修改/usr/local/nagios/etc/nagios.cfg文件,内容如下:
    process_performance_data=1
    host_perfdata_command=process-host-perfdata
    service_perfdata_command=process-service-perfdata
    enable_environment_macros=1
  5. 修改command.cfg配置文件编辑/usr/local/nagios/etc/objects文件,将原有的process-host-perfdataprocess-service-perfdata注释点,添加如下内容:
    definecommand{
    command_name process-host-perfdata
    command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
    }
    define command{
    command_name process-service-perfdata
    command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl
    }
  6. 添加图标模块编辑/user/local/nagios/etc/object/template.cfg文件,linux-servergeneric-service中分别,添加action_url
    action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
    action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
  7. 重启nagios服务

#/etc/init.d/nagios restart

  1. 安装NRPENRPE是监控软件nagios的一个扩展,它被用于被监控的服务器上,向nagios监控平台提供该服务器的一些本地的情况。例如,cpu负载、内存使用、硬盘使用等等。NRPE可以称为nagiosfor linux 客户端。
  1. Nrpe监控原理
  2. Nagios使用手册_oracle_03

  3. NRPE总共由两部分组成:
  • check_nrpe 插件,位于监控主机上
  • NRPE daemon,运行在远程的Linux主机上(通常就是被监控机)
  • 按照上图,整个的监控过程如下:
  • 当Nagios 需要监控某个远程Linux 主机的服务或者资源情况时:
  • Nagios 会运行check_nrpe 这个插件,告诉它要检查什么;
  • check_nrpe 插件会连接到远程的NRPE daemon,所用的方式是SSL;
  • NRPE daemon 会运行相应的Nagios 插件来执行检查;
  • NRPE daemon 将检查的结果返回给check_nrpe 插件,插件将其递交给nagios做处理。
  • 注意:NRPE daemon 需要Nagios 插件安装在远程的Linux主机上,否则,daemon不能做任何的监控。

2. 在被监控机(Nagios-Linux)上,源码安装nagios插件

# useradd nagios

# passwd nagios

# tar zxvf nagios-plugins-1.4.16.tar.gz

# cd nagios-plugins-1.4.16

# ./configure --prefix=/usr/local/nagios

# make && make install

# chown nagios.nagios /usr/local/nagios

# chown -R nagios.nagios /usr/local/nagios/libexec

# tar zxvf nrpe-2.13.tar.gz

# cd nrpe-2.13

# ./configure

# make all

# make install-plugin

# make install-daemon

# make install-daemon-config

# make install-xinetd

  1. 在被监控机上添加监控主机IP地址编辑/etc/xinetd.d/nrpe文件在only_from 后增加监控主机的IP地址。
    # default: on
    # description: NRPE (Nagios Remote Plugin Executor)
    service nrpe
    {
    flags = REUSE
    socket_type = stream
    port = 5666
    wait = no
    user = nagios
    group = nagios
    server = /usr/local/nrpe/bin/nrpe
    server_args = -c /usr/local/nrpe/etc/nrpe.cfg --inetd
    log_on_failure += USERID
    disable = no
    only_from = 127.0.0.1 192.168.3.202
    allowed_hosts = 192.168.3.202
    }
  2. 在被监控机上增加NRPE服务编辑/etc/services 文件,增加NRPE服务
    # Local services
    nrpe 5666/tcp # nrpe
  3. 在被监控机上重启xinetd服务:#service xinetd restart
  4. 在被监控机上测试NRPE是否则正常工作在被监控机上安装的check_nrpe 这个插件测试NRPE 是否工作正常
    # /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
    NRPE v2.13
  5. 添加命令定义

在监控机上编辑/usr/local/nagios/etc/objects/commands.cfg文件,添加如下内容:

# 'check_nrpe' command definition by zhaocm 20140529

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

  1. 监控配置
  1. 安装sys-Statistics-Linux# tar zxvf Sys-Statistics-Linux-0.66.tar.gz
    # cd Sys-Statistics-Linux-0.66
    # perl Makefile.PL
    # make
    # make test
    # make install
  2. check_linux_stats.pl拷贝到/usr/local/nagios/libexec目录
  3. 编辑/usr/local/nagios/etc/nrpe.cfg文件,添加以下内容。# Check disk usage on /, /home, /var
    command[check_disk]=/usr/local/nagios/libexec/check_linux_stats.pl -D -w 10 -c 5 -p /,/home,/var -u %
    # Check load average
    command[check_load]=/usr/local/nagios/libexec/check_linux_stats.pl -L -w 10,8,5 -c 20,18,15
    # Check memory & swap usage
    command[check_mem]=/usr/local/nagios/libexec/check_linux_stats.pl -M -w 100,25 -c 100,50
    # Check cpu usage
    command[check_cpu]=/usr/local/nagios/libexec/check_linux_stats.pl -C -w 99 -c 100 -s 5
    # Check open files
    command[check_open_file]=/usr/local/nagios/libexec/check_linux_stats.pl -F -w 10000,250000 -c 15000,350000
    # Check io disk on device sda1, sda3 and sda4
    command[check_io]=/usr/local/nagios/libexec/check_linux_stats.pl -I -w 2000,600 -c 3000,800 -p sda1,sda2,sda3 -s 5
    # Check processes
    command[check_procs]=/usr/local/nagios/libexec/check_linux_stats.pl -P -w 1000 -c 2000
    # Check network usage on eth0
    command[check_net]=/usr/local/nagios/libexec/check_linux_stats.pl -N -w 1000000 -c 1500000 -p eth0 -s 5
    # Check socket usage
    command[check_socket]=/usr/local/nagios/libexec/check_linux_stats.pl -S -w 500 -c 1000
    # Check uptime
    command[check_uptime]=/usr/local/nagios/libexec/check_linux_stats.pl -U -w 5
    # Check paging statistisc
    command[check_paging]=/usr/local/nagios/libexec/check_linux_stats.pl -W -w 50000,1000 -c 60000,2000 -s 3
  4. 插件的命令用法# /usr/local/nagios/libexec/check_linux_stats.pl -h
  5. 本地测试# /usr/local/nagios/libexec/check_linux_stats.pl -C -w 99 -c 100 -s 5
    CPU OK : idle 99.62% |idle=99.62%;99;100 user=0.03% system=0.03% iowait=0.33% steal=0.00%
  6. 监控机定义服务编辑/usr/local/nagios/etc/service/centos.cfg,添加如下内容:
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_ping
    check_command check-host-alive
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_disk
    check_command check_nrpe!check_disk
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_load
    check_command check_nrpe!check_load
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_mem
    check_command check_nrpe!check_mem
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_cpu
    check_command check_nrpe!check_cpu
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_open_file
    check_command check_nrpe!check_open_file
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_io
    check_command check_nrpe!check_io
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_procs
    check_command check_nrpe!check_procs
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_net
    check_command check_nrpe!check_net
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_socket
    check_command check_nrpe!check_socket
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_uptime
    check_command check_nrpe!check_uptime
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description check_paging
    check_command check_nrpe!check_paging
    }
  7. 监控机远程监控测试[root@nagios-server libexec]# /usr/local/nagios/libexec/check_nrpe -H 192.168.3.200 -c check_cpu
    CPU OK : idle 99.62% |idle=99.62%;99;100 user=0.03% system=0.03% iowait=0.33% steal=0.00%
  8. 将centos.cfg加载编辑/usr/local/nagios/etc/nagios.cfg文件,添加如下:
    cfg_file=/usr/local/nagios/etc/service/centos.cfg
  9. 重启监控端nagios和被监控端nrpe服务,web访问如下:
  1. 安装Check_oracle_health
  1. 安装perl环境(同上)
  2. 设置运行环境编辑 .bash_profile文件,添加oracle变量环境
    export ORACLE_BASE=/oracleapp/oinstall/oracle
    export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
    export ORACLE_SID=fsrz
    export PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin
    export PATH=$PATH:$ORACLE_HOME/bin
    export TNS_ADMIN=$ORACLE_HOME/network/admin
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:ORACLE_HOME/lib
    export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
    export ORA_NLS10=$ORACLE_HOME/nls/data
    unset USERNAME
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin/:/lib
    export LC_ALL=C
    立即生效
    #source /root/ .bash_profile
  3. ORACLE数据库创建用户并赋予权限CREATE USER nagios IDENTIFIED BY oradbmon;
    GRANT CREATE SESSION TO nagios;
    GRANT SELECT any dictionary TO nagios;
    GRANT SELECT ON V_$SYSSTAT TO nagios;
    GRANT SELECT ON V_$INSTANCE TO nagios;
    GRANT SELECT ON V_$LOG TO nagios;
    GRANT SELECT ON SYS.DBA_DATA_FILES TO nagios;
    GRANT SELECT ON SYS.DBA_FREE_SPACE TO nagios;
    GRANT SELECT ON sys.dba_tablespaces TO nagios;
    GRANT SELECT ON dba_temp_files TO nagios;
    GRANT SELECT ON sys.v_$Temp_extent_pool TO nagios;
    GRANT SELECT ON sys.v_$TEMP_SPACE_HEADER TO nagios;
    GRANT SELECT ON sys.v_$session TO nagios;
  4. 安装DBIDBD-Oracle# tar -zxvf DBI-1.631.tar.gz
    # cd DBI-1.631
    # perl Makefile.PL
    # perl Makefile.PL
    # make install
    # tar -zxvf DBD-Oracle-1.74.tar.gz
    # cd DBD-Oracle-1.74
    # perl Makefile.PL
    # make
    # make install
  5. 安装check_oracle_health# tar -zxvf check_oracle_health-1.7.7.3.tar.gz
    # cd check_oracle_health-1.7.7.3
    # ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-mymodules-dir=/usr/local/nagios/libexec --with-mymodules-dyndir=/usr/local/nagios/libexec
    # make all
    # make install
  6. 验证安装成功后会生产check_oracle_health文件。
    # ls -al /usr/local/nagios/libexec/check_oracle_health
    -rwxr-xr-x 1 root root 231744 May 14 03:32 /usr/local/nagios/libexec/check_oracle_health
  7. 本地测试

# /usr/local/nagios/libexec/check_oracle_health --cnotallow=fsrz --user=system --password=fsrz --mode=tnsping --environment ORACLE_HOME=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1

OK - connection established to fsrz.

  1. 远程监控配置
  1. 安装npre插件(同上)
  2. 被监控端添加监控内容编辑/usr/local/nagios/etc文件,添加oracle监控内容(部分):
    # Check oracle tnsping
    command[check_tnsping]=/usr/local/nagios/libexec/check_oracle_health --cnotallow=fsrz --user=system --password=fsrz --mode=tnsping --environment ORACLE_HOME=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1
    # Check oracle connection-time
    command[check_connection-time]=/usr/local/nagios/libexec/check_oracle_health --cnotallow=fsrz --user=system --password=fsrz --mode=connection-time --environment ORACLE_HOME=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1
    # Check oracle sga-data-buffer-hit-ratio
    command[check_sga-data-buffer-hit-ratio]=/usr/local/nagios/libexec/check_oracle_health --cnotallow=fsrz --user=system --password=fsrz --mode=sga-data-buffer-hit-ratio --environment ORACLE_HOME=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1
    # Check oracle sga-library-cache-hit-ratio
    command[check_sga-library-cache-hit-ratio]=/usr/local/nagios/libexec/check_oracle_health --cnotallow=fsrz --user=system --password=fsrz --mode=sga-library-cache-hit-ratio --environment ORACLE_HOME=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1
    # Check oracle sga-latches-hit-ratio
    command[check_sga-latches-hit-ratio]=/usr/local/nagios/libexec/check_oracle_health --cnotallow=fsrz --user=system --password=fsrz --mode=sga-latches-hit-ratio --environment ORACLE_HOME=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1
    # Check oracle sga-shared-pool-reloads
    command[check_sga-shared-pool-reloads]=/usr/local/nagios/libexec/check_oracle_health --cnotallow=fsrz --user=system --password=fsrz --mode=sga-shared-pool-reloads --environment ORACLE_HOME=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1
    # Check oracle sga-shared-pool-free
    command[check_sga-shared-pool-free]=/usr/local/nagios/libexec/check_oracle_health --cnotallow=fsrz --user=system --password=fsrz --mode=sga-shared-pool-free --environment ORACLE_HOME=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1
    # Check oracle pga-in-memory-sort-ratio
    command[check_pga-in-memory-sort-ratio]=/usr/local/nagios/libexec/check_oracle_health --cnotallow=fsrz --user=system --password=fsrz --mode=pga-in-memory-sort-ratio --environment ORACLE_HOME=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1
    # Check oracle invalid-objects
    command[check_invalid-objects]=/usr/local/nagios/libexec/check_oracle_health --cnotallow=fsrz --user=system --password=fsrz --mode=invalid-objects --environment ORACLE_HOME=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1
  3. 监控端远程测试[root@nagios-server libexec]# /usr/local/nagios/libexec/check_nrpe -H 192.168.3.201 -c check_tnsping
    OK - connection established to fsrz.
  4. 监控端添加服务编辑/usr/local/nagios/etc/service/oracle.cfg文件,添加如下内容(部分):
    define service{
    use local-service
    host_name 192.168.3.200
    service_description oracle_tnsping
    check_command check_nrpe!check_tnsping
    }
    define service{
    use local-service
    define service{
    use local-service
    host_name 192.168.3.200
    service_description oracle_tnsping
    check_command check_nrpe!check_tnsping
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description oracle_connection-time
    check_command check_nrpe!check_connection-time
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description oracle_sga-data-buffer-hit-ratio
    check_command check_nrpe!check_sga-data-buffer-hit-ratio
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description oracle_sga-latches-hit-ratio
    check_command check_nrpe!check_sga-latches-hit-ratio
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description oracle_sga-shared-pool-reloads
    check_command check_nrpe!check_sga-shared-pool-reloads
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description oracle_sga-shared-pool-free
    check_command check_nrpe!check_sga-shared-pool-free
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description oracle_pga-in-memory-sort-ratio
    check_command check_nrpe!check_pga-in-memory-sort-ratio
    }
    define service{
    use local-service
    host_name 192.168.3.200
    service_description oracle_invalid-objects
    check_command check_nrpe!check_invalid-objects
    }
  5. 将oracle.cfg加载编辑/usr/local/nagios/etc/nagios文件,添加如下:
    cfg_file=/usr/local/nagios/etc/service/oracle.cfg
  6. 重启监控端nagios和和被监控端nrpe服务,web访问如下:
  1. 安装wlsagent下载地址:​​http://code.google.com/p/wlsagent/downloads/list​​Wlsagent运行需要jdk环境,安装jdk1.6以上版本。
  1. 解压安装tar zxvf wlsagent-r185
    [root@tomcat wlsagent-r185]# ls
    lib run.sh wlsagent-r185.jar wlsagent.sh
  2. 下载java监控工程:svn checkout http://wlsagent.googlecode.com/svn/trunk/src
    将java工程net,导入eclipse编译,将编译后工程拷贝到/opt/wlsagent-r185目录下。
  3. /opt/wlsagent-r185(工作目录)创建build.xml文件,内容如下:<?xml versinotallow="1.0" encoding="UTF-8" ?>
    <project name="wlsagent" basedir="." default="build">
    <property name="src.dir" value="src"/>
    <property name="lib.dir" value="lib"/>
    <property name="build.dir" value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="jar.dir" value="${build.dir}/jar"/>
    <property name="javadoc.dir" value="${build.dir}/javadoc" />
    <property name="main-class" value="net.wait4it.nagios.wlsagent.core.WLSAgent"/>

    <path id="classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>
    <target name="clean">
    <delete dir="${build.dir}"/>
    </target>
    <target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" includeantruntime="false"/>
    </target>
    <target name="jar" depends="compile">
    <mkdir dir="${jar.dir}"/>
    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
    <manifest>
    <attribute name="Main-Class" value="${main-class}"/>
    </manifest>
    </jar>
    </target>
    <target name="javadoc">
    <javadoc packagenames="src" sourcepath="${src.dir}" destdir="${javadoc.dir}" classpathref="classpath">
    <fileset dir="${src.dir}">
    <include name="**" />
    </fileset>
    </javadoc>
    </target>
    <target name="build" depends="clean,jar"/>
    </project>
  4. 修改启动脚本(如下):编辑/opt/wlsagent-r185/run.sh,修改后文件如下:
    #!/bin/bash
    cd $(dirname "$0")
    JAVA_HOME="/opt/jdk1.6.0_30"
    HOST="0.0.0.0"
    PORT="9090"
    CLASSPATH=".:wlsagent-r185.jar"
    # Add Jetty dependencies to the plugin classpath.
    CLASSPATH="${CLASSPATH}:lib/servlet-api-2.5.jar:lib/jetty-servlet-7.6.2.v20120308.jar"
    # Add WebLogic dependencies to the plugin classpath.
    # The 'wljmxclient.jar' must be loaded before the 'wlfullclient.jar'.
    CLASSPATH="${CLASSPATH}:lib/wlclient.jar:lib/wljmxclient.jar:lib/wlfullclient.jar"
    ${JAVA_HOME}/bin/java -Xmx32m -cp ${CLASSPATH} net.wait4it.nagios.wlsagent.core.WLSAgent ${HOST} ${PORT} > /dev/null 2>&1 &
    注意JAVA_HOME和java工程包的路径。
  5. 添加需要jar包进入$weblogic/wlserver_10.3/server/lib下,生成wlfullclent.jar,将wlclient.jar wljmxclient.jar包一起复制到/opt/wlsagent-r185/lib/
    #cd /wlserver_10.3/server/lib
    # java -jar wljarbuilder.jar
    # cp wlclient.jar wljmxclient.jar wlfullclient.jar /opt/wlsagent-r185/lib/
    添加后的jar
    # ls /wlserver_10.3/server/lib
    jetty-servlet-7.6.2.v20120308.jar servlet-api-2.5.jar wlclient.jar wlfullclient.jar wljmxclient.jar
  6. 本地测试

#/opt/wlsagent-r185/wlsagent.sh 'hostname=nagios2&port=7001&username=weblogic&password=weblogic2014'

或者

#wget -q -O - 'http://localhost:9090/wlsagent/WlsAgent' --post-data='hostname=nagios2&port=7001&username=weblogic&password=weblogic2014'

若有返回信息如下:

wlfpAdmin is in RUNNING state, status OK|

表明安装成功。

  1. 远程监控配置
  1. 安装npre插件(同上)
  2. 安装 nagios-plugins插件(同上)
  3. 被监控端添加监控内容编辑/usr/local/nagios/etc文件,添加如下内容:
    command[check_status]=/opt/wlsagent-r185/wlsagent.sh 'hostname=nagios2&port=7001&username=weblogic&password=weblogic2014'
    command[check_jvm]=/opt/wlsagent-r185/wlsagent.sh 'hostname=nagios2&port=7001&username=weblogic&password=weblogic2014&jvm=UsedMemory,80,90'
    command[check_jvm2]=wget -q -O - 'http://localhost:9090/wlsagent/WlsAgent' --post-data='hostname=nagios2&port=7001&username=weblogic&password=weblogic2014&jvm=UsedMemory,80,90'
    command[check_thread-pool]=/opt/wlsagent-r185/wlsagent.sh 'hostname=nagios2&port=7001&username=weblogic&password=weblogic2014&thread-pool=ThreadStuckCount,5,10'
    command[check_jta]=/opt/wlsagent-r185/wlsagent.sh 'hostname=nagios2&port=7001&username=weblogic&password=weblogic2014&jta=ActiveTransactions,15,30'
    command[check_jmsRuntime]=/opt/wlsagent-r185/wlsagent.sh 'hostname=nagios2&port=7001&username=weblogic&password=weblogic2014&jms-runtime=CurrentConnections,500,750'
    command[check_jme-queue]=/opt/wlsagent-r185/wlsagent.sh 'hostname=nagios2&port=7001&username=weblogic&password=weblogic2014&jms-queue=*,150,200'
    command[check_component]=/opt/wlsagent-r185/wlsagent.sh 'hostname=nagios2&port=7001&username=weblogic&password=weblogic2014&compnotallow=*,100,150'
  4. 监控端远程测试[root@nagios-server libexec]# /usr/local/nagios/libexec/check_nrpe -H 192.168.3.201 -c check_status
    wlfpAdmin is in RUNNING state, status OK|
  5. 监控端添加服务编辑/usr/local/nagios/etc/service/weblogic.cfg文件,添加如下内容:
    define service{
    use local-service
    host_name 192.168.3.201
    service_description weblogic_jvm
    process_perf_data 1
    check_command check_nrpe!check_jvm
    }
    define service{
    use local-service
    host_name 192.168.3.201
    service_description weblogic_jvm2
    check_command check_nrpe!check_jvm2
    }
    define service{
    use local-service
    host_name 192.168.3.201
    service_description weblogic_thread-pool
    check_command check_nrpe!check_thread-pool
    }
    define service{
    use local-service
    host_name 192.168.3.201
    service_description weblogic_jta
    check_command check_nrpe!check_jta
    }

    define service{
    use local-service
    host_name 192.168.3.201
    service_description weblogic_jmsRuntime
    check_command check_nrpe!check_jmsRuntime
    }
    define service{
    use local-service
    host_name 192.168.3.201
    service_description weblogic_jme-queue
    check_command check_nrpe!check_jme-queue
    }
    define service{
    use local-service
    host_name 192.168.3.201
    service_description weblogic_component
    check_command check_nrpe!check_component
    }
  6. 将weblogic.cfg加载编辑/usr/local/nagios/etc/nagios文件,添加如下:
    cfg_file=/usr/local/nagios/etc/service/weblogic.cfg
  7. 重启监控端nagios和和被监控端nrpe服务,web访问如下:
  1. 编写脚本
  1. 安装perl环境及相应的perl模块,依次安装LWP::Simple URI::Escape Digest::MD5模块,可使用yum或者CPAN命令安装。
  2. /usr/local/nagios/libexec目录下,新建sms_send.pl脚本,内容如下:#!/usr/bin/perl -w
    use strict;
    use LWP::Simple;
    use URI::Escape;
    use Digest::MD5;
    my ($mobile, $content) = @ARGV; # get params from command line
    my $log_control = 1; # a switch of log
    my $username = '******'; # your sms service username
    my $password = '******'; # your sms service password
    my $key = ''; # your sms service key
    my $souce_content = substr($mobile, 0, 8) . substr($mobile, -10, 10) . $key;
    my $md5 = Digest::MD5->new;
    $md5->add($souce_content);
    my $keyword = uc($md5->hexdigest);
    my $result = get "http://211.147.224.154:18013/cgi-bin/sendsms?username=$username&password=$password&to=$mobile&text=$content&Keyword=$keyword";
    if($log_control) {
    my $fh;
    open($fh, '>> /var/log/sms.log') or die "can't open log: $!"; # make sure have permission
    print $fh join(' ', time, $result, "/n");
    close $fh;
    }
    示例说明:
  1. my $key = '’ 短信服务商给的验证关键字,如没有可以设为空值。
  2. my $url=

以短信服务商广州玄武科技公司提供的网关通道为例说明: ​​http://211.147.224.154:18013/cgi-bin/sendsms?username=$username&password=$password&to=$mobile&text=$content&Keyword=$keyword&subid=&msgtype=4”url​​中包含用户名、密码、关键字、电话号码、发送内容、长短信协议等等。
chomod u+x /usr/local/nagios/libexec/sms_send.pl 给与它执行权限。

  1. 测试

执行命令行/usr/local/nagios/libexec/sms_send.pl 13800138000 "It is a test"

  1. 配置
  1. Nagios配置
  2. Pnpnagios安装Pnpnagios实现nagios服务图表,它利用RRDTool工具将Nagios的数据生成图形,以便更直观的查看,而且可以查看历史记录。
  3. Centos监控
  4. Oracle监控check_oracle_health 是一个 Nagios 用来监控Oracle 数据库运行状态的插件。可监控的内容包括:连接时间、SGA 数据缓冲区的使用率、命中率以及可用空间、PGA 内存排序的命中率、表空间的使用率、表空间碎片、表空间IO瓶颈、无效对象以及其他很多方面的数据监控内容。
    ​​​http://labs.consol.de/nagios/check_oracle_health/​​
  5. Weblogic监控Wlsagent是一个nagios的插件程序,可监控WebLogic服务器(9x,10x & 11g版本),而且最小可能占用服务器内存的程序.目前可提供JVMTHREAD POOLJTAJDBCJMS HTTP SESSION等监控。
  6. 短信网关配置
  1. 安装配置
  2. 监控配置
  3. 修改command.cfg文件,增加短信报警部分# 'notify-host-by-sms' command definition
    define command{
    command_name host-notify-by-sms
    command_line /usr/local/nagios/libexec/sms_send.pl $CONTACTPAGER$ "*** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ IP: $HOSTADDRESS$ is $HOSTSTATE$ ***"
    }
    # 'notify-service-by-sms' command definition
    define command{
    command_name service-notify-by-sms
    command_line /usr/local/nagios/libexec/sms_send.pl $CONTACTPAGER$ "*** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$ IP: $HOSTADDRESS$ / $SERVICEDESC$ is $SERVICESTATE$ ***"
    }
  4. 修改templata.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,service-notify-by-sms ; send service notifications via email
    host_notification_commands notify-host-by-email,host-notify-by-sms ; send host notifications via email
    register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
    }
  5. 修改contacts.cfg文件,定义联系人define contact{
    contact_name zrsfadmin ; Short name of user
    use generic-contact ; Inherit default values from generic-contact template (defined above)
    alias Zrsf Admin
    email zcm_mail@126.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS
    pager 18576652571
    }
  6. 4.重启nagios服务
举报

相关推荐

IDEA使用手册

Typora使用手册

Consul使用手册

npm使用手册

pgpy使用手册

Portainer使用手册

0 条评论