设为首页 收藏本站
查看: 949|回复: 0

nagios整合cacti2011版(五)

[复制链接]

尚未签到

发表于 2019-1-16 12:02:57 | 显示全部楼层 |阅读模式
Nagios使用NSClient++监控远程Windows主机
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/ksohtml/wps_clip_image-30177.png

下载NSClient++-Win32-0.3.8.msi并安装。
http://files.nsclient.org/x-0.3.x/NSClient++-0.3.8-Win32.msi
到安装目录打开NSC.ini文件进行修改:
在[modules]模块,将除CheckWMI.dll和RemoteConfiguration.dll外的所有dll文件明前的注释(;)去掉。
在[Settings]模块可以设置一个连接密码password=PWD,为了简单,在此不设密码。设置allowed_hosts=127.0.0.1/32,192.168.0.19,可以连接的监控服务器的地址,如果写成192.168.0.0/24则表示该子网内的所有机器都可以访问;如果这个地方是空白则表示所有的主机都可以连接上来(注意在[NSClient]有allowed_hosts的同样设置,不要设置错了),最后不要忘记去掉前面的注释符(;)。
运行nsclient++
NSClient++ /install
NSClient++ SysTray install
NSClient++ /start
如果有防火墙,请开放相应端口。
创建监控配置文件,使用check_nt命令监控windows系统信息(此命令默认已定义)。
Windows监控示例配置文件:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@tech etc]# cat /usr/local/nagios/etc/servers/print-w-80.cfg
###############################################################################
# WINDOWS.CFG - SAMPLE CONFIG FILE FOR MONITORING A WINDOWS MACHINE
#
# Last Modified: 06-13-2007
#
# NOTES: This config file assumes that you are using the sample configuration
#     files that get installed with the Nagios quickstart guide.
#
###############################################################################

###############################################################################
###############################################################################
#
# HOST DEFINITIONS
#
###############################################################################
###############################################################################
# Define a host for the Windows machine we'll be monitoring
# Change the host_name, alias, and address to fit your situation
define host{
    use        windows-server    ; Inherit default values from a template
    host_name    print80        ; The name we're giving to this host
    alias        Print80        ; A longer name associated with the host
    address        192.168.0.80    ; IP address of the host
    }
###############################################################################
###############################################################################
#
# HOST GROUP DEFINITIONS
# 主机组在/usr/local/nagios/etc/servers/hostgroup.cfg中单独配置
###############################################################################
###############################################################################
# Define a hostgroup for Windows machines
# All hosts that use the windows-server template will automatically be a member of this group
#define hostgroup{
#    hostgroup_name    windows-servers    ; The name of the hostgroup
#    alias        Windows Servers    ; Long name of the group
#    }
###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
###############################################################################
# Create a service for monitoring the version of NSCLient++ that is installed
# Change the host_name to match the name of the host you defined above
define service{
    use            generic-service
    host_name        print80
    service_description    NSClient++ Version
    check_command        check_nt!CLIENTVERSION
    }
# Create a service for monitoring the uptime of the server
# Change the host_name to match the name of the host you defined above
define service{
    use            generic-service
    host_name        print80
    service_description    Uptime
    check_command        check_nt!UPTIME
    }
# Create a service for monitoring CPU load
# Change the host_name to match the name of the host you defined above
define service{
    use            generic-service
    host_name        print80
    service_description    CPU Load
    check_command        check_nt!CPULOAD!-l 5,80,90
    }
# Create a service for monitoring
# Change the host_name to match the name of the host you defined above
define service{
    use            generic-service
    host_name        print80
    service_description    Memory Usage
    check_command        check_nt!MEMUSE!-w 80 -c 90
    }
# Create a service for monitoring C:\ disk usage
# Change the host_name to match the name of the host you defined above
define service{
    use            generic-service
    host_name        print80
    service_description    C_Drive_Space
    check_command        check_nt!USEDDISKSPACE!-l c -w 80 -c 90
    }
# Create a service for monitoring the W3SVC service
# Change the host_name to match the name of the host you defined above
define service{
    use            generic-service
    host_name        print80
    service_description    W3SVC
    check_command        check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
    }
# Create a service for monitoring the Explorer.exe process
# Change the host_name to match the name of the host you defined above
define service{
    use            generic-service
    host_name        print80
    service_description    Explorer
    check_command        check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
    }
#主机组配置文件
[root@tech etc]# cat /usr/local/nagios/etc/servers/hostgroup.cfg
define hostgroup{
        hostgroup_name  linux-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         localhost,wiki     ; Comma separated list of hosts that belong to this group
        }
define hostgroup{
        hostgroup_name  windows-servers ; The name of the hostgroup
        alias           Windows Servers ; Long name of the group
        members         print80     ; Comma separated list of hosts that belong to this group
        }
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 完成监控主机配置文件的配置后使用下面命令检查配置文件的正确性:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# 确定无误后重启Nagios:
service nagios restart
===============================================================================
使用nagios监控网页
在server文件夹里加入webpages.cfg并设置好用户权限
Vim webpages.cfg
define host{
       use             linux-server
       host_name       webpages
       alias           webpages
       address         127.0.0.1
}
define service{
        use             generic-service         ; Name of service template to use
        host_name                       webpages
        service_description             web_zgzb
        check_command             check_webpage!-H test.cn -u /index.jsp
        notifications_enabled           0
        }
然后在hostgroup里linux组里加入webpages主机
define hostgroup{
        hostgroup_name  linux-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         localhost,webpages ; Comma separated list of hosts that belong to this group
        }
确认下配置文件没有问题
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
OK重启一下nagios服务,就OK了.
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/ksohtml/wps_clip_image-32056.png
===============================================================================
使用139邮箱进行邮件短信报警
    nagios发警告邮件是采用本机的smtp服务,可以查看commands.cfg中关于发邮件的命令的定义,使用本机的mail命令,这就需要开启本机的smtp服务,为了安全可以在防火墙上设置拒绝其他的机器连本机的25号端口
    另外由于移动增加了飞信api接口,在Linux命令行下使用飞信客户端需要图片验证码,飞信就不能用了,那么用139邮箱可以解决这个问题
    申请139邮箱,成功申请后配置邮件到达短信通知,使用长格式。139邮件短信通知这个功能好用,而且免费:)缺点:短信报警有延时,不如linux命令行飞信报警快,但实际使用中速度还是不错的, 基本上和邮箱同步.可以不开启本机的smtp服务,这就需要重新定义命令使用第三方软件sendEmail.
139邮箱申请:http://mail.10086.cn/
http://caspian.dotconf.net/menu/Software/SendEmail/
这里邮件服务器的地址为mail.jetsum.net
用来发邮件的帐号 test@jetsum.net
SMTP验证的用户名 test密码 ******
  以下就来介绍一下sendEmail这个软件的使用.
sendEmail的主页http://caspian.dotconf.net/menu/Software/SendEmail/
下载地址
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
软件十分小,是一个通过命令来发smtp邮件的程序.安装也十分简单(查看其README文件即可).
解压缩tar –zxvf sendEmail-v sendEmail-v1.56.tar.gz
cd sendEmail-v1.56
将可执行程序复制cp sendEmail /usr/local/bin
然后给确认确实它具有执行权限
ll /usr/local/bin/sendEmail
-rwxr-xr-x 1 root root 77882 11-03 14:23 /usr/local/bin/sendEmail
这样程序就装好了,使用也很简单.直接运行sendEmail就会显示详细的用法
先看一个典型的例子
/usr/local/binsendEmail -f test@jetsum.net -t 15107170098@139.com,17610376@qq.com -s mail.jetsum.net -u "send by nagios" -xu test -xp 密码 -m "just test too"
解释:
-f表示发送者的邮箱
-t表示接收者的邮箱,发多邮箱中间用逗号隔开
-s表示SMTP服务器的域名或者ip
-u表示邮件的主题
-xu表示SMTP验证的用户名
-xp表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
-m表示邮件的内容
  如果你不带-m参数的话,就会提示你自行输入
Reading message body from STDIN because the ‘-m’ option was not used.
If you are manually typing in a message:
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line
输入完成后使用CTRL-D来结束
  当然我们也可以将一个文件的内容作为邮件的正文发出去的那么就可以使用:
cat文件名| /usr/local/bin/sendEmail –f nagios@test.com –t yahoon@test.com –s mail.test.com –u “from nagios” –xu nagios –xp p#3isoda
有关sendEmail的用法就讲到这里
  既然nagios要使用sendEmail来发警告邮件,那么就要修改commands.cfg中关于发邮件的命令的定义,我们现在来修改notify-by-email这个命令,如下(注意其中粗体的部分)
# 'notify-by-email' command definition
define command{
       command_name   notify-by-email
       command_line   /usr/bin/printf "%b" "***** Nagios 2.9 *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/local/bin/sendEmail -f test@jetsum.net -t 15107170098@139.com,17610376@qq.com -s mail.jetsum.net -u "send by nagios" -xu test -xp 密码
       }
  :其实sendEmail是一个十分有用的程序,我们在这个地方用了它,其实别的地方也可以用,典型的好处就是你不需要每台机器都装sendmail,开启smtp服务.直接用现成的一台邮件服务器就行了,这无疑很大的加强了系统的安全性,也节约了资源.
4.编写nagios报警脚本(略),这个简单,适当修改一下即可
参考:
http://www.gaojinbo.com/nagios%E9%A3%9E%E4%BF%A1linux%E7%9F%AD%E4%BF%A1%E6%8A%A5%E8%AD%A6%E8%84%9A%E6%9C%AC%E9%85%8D%E7%BD%AE.html




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-663983-1-1.html 上篇帖子: nagios整合cacti2011版(四) 下篇帖子: nagios整合cacti2011版(六)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表