Nagios使用NSClient++监控远程Windows主机

下载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了.
===============================================================================
使用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

转载于:https://blog.51cto.com/17610376/543614

nagios整合cacti2011版(五)相关推荐

  1. 冀教版五年级计算机教学计划,冀教版五年级科学教学计划

    冀教版五年级科学教学计划 生物与生物之间.生物与环境之间存在的相互作用和平衡关系.同时,着重培养同学搜集资料.分析资料,以控制实验.模拟实验.分析实验结果.提出假设等探究能力,鼓励同学从正反两个方面分 ...

  2. 把一个人的特点写具体作文_部编版五年级下册语文习作把一个人的特点写具体教案课件+范文...

    第一单元 部编版五年级下册语文第1课<古诗词三首>知识点+图文讲解 部编版小学语文五年级下册第2课<祖父的园子>课文讲解 部编版小学语文五年级下册第3课<月是故乡明> ...

  3. 分数怎么化成带分数_人教版五年级下册第4单元带分数及把假分数化成整数或带分数教学视频+知识点...

    |点击题目下方蓝字一键关注 小学生知识库| [教学视频]分数的分类与互化[知识点] 带分数的意义和特征: 像-这样由整数和真分数合成的数叫做带分数. 假分数化成整数或带分数的方法是什么? ①当假分数的 ...

  4. 不规则图形数格子的方法_【微课堂】人教版五年级数学(上)6.5不规则图形的面积图文精讲+教学视频+同步练习...

    小学生精选资料库,家有小学生都在关注 更多资料.微课堂,请至文末 人教教材同步微课堂(包括视频微课.教材同步.图文讲解.同步练习等),可以在课堂之外帮助同学们学习.欢迎转发给更多的同学哦~~ 电子课本 ...

  5. 3d数学基础:图形和游戏开发(第2版)_人教版五年级数学上册教学计划进度表

    文末有打印资料的方法 往期回顾: 统编版五年级语文上册第1课<白鹭>视频+课件+练习 统编版五年级语文上册第2课<落花生>视频+课件+练习 统编版五年级语文上册第3课<桂 ...

  6. css 平行四边形 梯形 组合_微课|人教版五年级数学上册6.4组合图形的面积(P99)...

    |点击题目下方蓝字一键关注 小学生知识库| 视频微课 在公众号菜单"爱学小学",打开小程序 "爱学中小学",免费观看人教版数学教学视频. 您也可以在这里搜一搜, ...

  7. my batis plus 小数没有0_北师大版五年级第一单元小数除法知识点总结及易错题解析(1)...

    北师大版五年级上册第一单元<小数除法>包括小数除法,积商近似值,循环小数.小数四则混合运算等内容.看似简单,但出错率很高,家长.老师都说:孩子一问好像都知道,但是一做题就这问题那问题,笔者 ...

  8. 不规则图形数格子的方法_北师大版五年级数学上册数学6.1组合图形的面积微课堂、同步练习、图文解读...

    点击上方蓝字关注我们! 电子教材 点击图片,查看大图 ▼▼▼ 微课堂 知识点 知识点:了解组合图形:有几个简单的图形拼出来的图形,我们把它们叫做组合图形. 计算组合图形的面积的方法是多种多样的.一般运 ...

  9. cacti+nagios整合(未成)

    cacti+nagios整合: http://pkgs.fedoraproject.org/repo/pkgs/php-json/php-json-ext-1.2.1.tar.bz2/e06e7014 ...

最新文章

  1. 你熟知的那个杀毒软件公司McAfee,用这种方法骗过护照人脸识别系统
  2. 推荐系统-03-简单基于用户的推荐
  3. 【 FPGA 】状态机的模型之Mealy型状态机
  4. 用Spark实现简单的单词统计
  5. Android ContentResolver
  6. source insight c++ namespace 无法跳转解决方法
  7. 专题一:预处理数据(使用sklearn-preprocessing)
  8. iOS之Socket的使用-AsyncSocket
  9. Linux系统正则表达式用法笔记
  10. 基于OpenCV实现------图像的转置
  11. python将json数据集转成voc xml文件
  12. 《小团团团队》【Alpha】Scrum Meeting 3
  13. HashMap和HashSet的区别?
  14. html个人中心源代码,HTML用户注册页面设置源码
  15. WebRTC SDP 详解和剖析
  16. iphone 投android电视,手机投屏到电视上的2种方法,看完才知道原来这么简单
  17. 如何删除word页眉的横线
  18. 几个黑科技、实用网站(转自公众号:趣说软件)
  19. 字节面试官推荐的一份 Java 基础面试题!太顶了
  20. 可解释性机器学习( Explainable Artificial Intelligence (XAI) )文献阅读记录(1.1)

热门文章

  1. es6去除重复项_Excel的去除重复项你真的明白原理吗?浅尝去除重复项的函数奥秘...
  2. 转转钓鱼php,最新转转钓鱼源码程序网站微信:mm88wk 最新转转源码 - 下载 - 搜珍网...
  3. 计算机自然语言的中国科学家,中科院教授王斌加入小米 任自然语言处理首席科学家...
  4. 怎么在计算机里找到CF里保存的视频,电脑怎么查看穿越火线录制保存视频?操作方法...
  5. ios 系统提示框_ios13终于能屏蔽系统更新了!附详细教程
  6. Linux Ubuntu 16.04系统下可用的Windows应用
  7. hdu Caocao's Bridges(无向图边双连通分量,找出权值最小的桥)
  8. Floyd算法的理解
  9. checkA.php,php window平台模拟checkdnsrr函数检测_php
  10. distinct返回null报错_C#之集合常用扩展方法与Linq