Nagios利用NSClient++监控Windows主机

简介:

一、简介

1、获取更多的NSClient原理,请参考NSClient++官方站点

NSClient++官网:http://www.nsclient.org/


2、NSClient++与NRPE

NSClient++的工作原理


wKiom1QnYaewuJNPAACIXWqRWWw312.jpg


NRPE的工作原理

wKiom1Qnc3zAjECMAAEUsOqv9kM145.jpg


Nagios对Windows主机的监控主要有三种方法

第一种是NSclient++

第二种是NRPE

第三种是SNMP(不是很常用)


NSclient++与nrpe最大的区别就是:

1、被监控机上安装有nrpe,并且还有插件,最终的监控是由这些插件来进行的.当监控主机将监控请求发给nrpe后,nrpe调用插件来完成监控.

2、NSclient++则不同,被监控机上只安装NSclient++,没有任何的插件.当监控主机将监控请求发给NSclient++后,NSclient++直接完成监控,所有的监控是由NSclient++完成的。

这也说明了NSclient++的一个很大的问题,不灵活,没有可扩展性.它只能完成自己本身包含的监控操作,不能由一些插件来扩展.好在NSclient++已经做的不错了,基本上可以完全满足我们的监控需要。


二、check_nt的方式监控windows主机

1、下载NSClient++

下载地址:http://sourceforge.net/projects/nscplus/files/nscplus/


2、安装NSClient++

wKiom1QmswLChu7BAAF5ugAoQLo820.jpg

wKioL1QmsyqyCXr-AAHsG6bmgZw306.jpg

wKiom1QmswOwzMYBAAGsdr9E0Pc403.jpg

wKioL1QmsyqTfejsAAGRfdnH-xU473.jpg

Allowed hosts:(this is the IP of the nagios (or other)server)

允许的主机地址:Nagios服务器端的IP地址


NSClient password(only userd via check_nt)

NSClient的密码:填写Nagios跟NSClient++进程通信的密码,可以不设置


Modules to load:

安装并加载相应的模块:NSClient++自带的有check_plugins插件,check_nt,check_nrpe,NSCA,WMI

在这里我们全部选择,以后会有用到的。

wKiom1QmswOTN7ZdAAF8CMhGqWs779.jpg

wKioL1Qmsyvjmrj1AADuL2UQatY830.jpg

点击【Finsh】,表示安装NSClient++完成

wKioL1QmsyujK89FAAGCBr_MNf0266.jpg


3、查看NSClient++服务是否已经启用

wKioL1QnXTmgMzAWAAQEAtOdHlA759.jpg

wKiom1QnYYexKlUCAACG8_0iqhA152.jpg


4、查看NSClient++的配置文件

默认是安装在C:\Program Files\NSClient++ 目录下,NSC.ini即为NSClient服务的配置文件,一般我们无需修改,但是当我们监控端的IP地址改变时,或者密码忘记,即可以在这里修改了。

安装时加载的模块

wKioL1QnXLeisp6DAAOmUPyr8zQ318.jpg

设置允许连接的地址:为Nagios的IP地址

wKiom1QnXJDxt5BDAAZlbauD00Y308.jpg

NRPE的默认端口号

wKioL1QnXLnCQe-sAATIjXBJX2M538.jpg


三、NSClient应用监控

NSClient++与Nagios服务器通信,主要使用Nagios服务器的check_nt插件。原理图如下

wKiom1QnXc7Rghy-AAC9NsiJ0jA271.jpg


1、check_nt插件的使用说明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
[root@Nagios ~] # cd /usr/local/nagios/libexec/
[root@Nagios libexec] # ./check_nt -h   #查看check_nt的语法
check_nt v2.0.3 (nagios-plugins 2.0.3)
Copyright (c) 2000 Yves Rubin (rubiyz@yahoo.com)
Copyright (c) 2000-2014 Nagios Plugin Development Team
     <devel@nagios-plugins.org>
 
This plugin collects data from the NSClient service running on a
Windows NT /2000/XP/2003  server.
 
 
Usage:
check_nt -H host - v  variable [-p port] [-w warning] [-c critical]
[-l params] [-d SHOWALL] [-u] [-t timeout]
 
Options:
  -h, --help
     Print detailed help  screen
  -V, --version
     Print version information
  --extra-opts=[section][@ file ]
     Read options from an ini  file . See
     https: //www .nagios-plugins.org /doc/extra-opts .html
     for  usage and examples.
Options:
  -H, -- hostname =HOST
    Name of the host to check
  -p, --port=INTEGER
    Optional port number (default: 1248)   #默认端口号
  -s, --secret=<password>                  #指定的密码
    Password needed  for  the request
  -w, --warning=INTEGER
    Threshold  which  will result  in  a warning status
  -c, --critical=INTEGER
    Threshold  which  will result  in  a critical status
  -t, --timeout=INTEGER
    Seconds before connection attempt  times  out (default:  -l, --params=<parameters>
    Parameters passed to specified check (see below) -d, --display={SHOWALL}
    Display options (currently only SHOWALL works) -u, --unknown-timeout
    Return UNKNOWN on timeouts10)
  -h, --help
    Print this help  screen
  -V, --version
    Print version information
  - v , --variable=STRING
    Variable to check
 
Valid variables are:
  CLIENTVERSION = Get the NSClient version
   If -l <version> is specified, will  return  warning  if  versions differ.
  CPULOAD =
   Average CPU load on last x minutes.
   Request a -l parameter with the following syntax:
   -l <minutes range>,<warning threshold>,<critical threshold>.
   <minute range> should be  less  than 24*60.
   Thresholds are percentage and up to 10 requests can be  done  in  one shot.
   ie: -l 60,90,95,120,90,95
  UPTIME =
   Get the uptime of the machine.
   -l <unit> 
   <unit> = seconds, minutes, hours, or days. (default: minutes)
   Thresholds will use the unit specified above.
  USEDDISKSPACE =
   Size and percentage of disk use.
   Request a -l parameter containing the drive letter only.
   Warning and critical thresholds can be specified with -w and -c.
  MEMUSE =
   Memory use.
   Warning and critical thresholds can be specified with -w and -c.
  SERVICESTATE =
   Check the state of one or several services.
   Request a -l parameters with the following syntax:
   -l <service1>,<service2>,<service3>,...
   You can specify -d SHOWALL  in  case  you want to see working services
   in  the returned string.
  PROCSTATE =
   Check  if  one or several process are running.
   Same syntax as SERVICESTATE.
  COUNTER =
   Check any performance counter of Windows NT /2000 .
     Request a -l parameters with the following syntax:
     -l  "\\<performance object>\\counter" ,"<description>
     The <description> parameter is optional and is given to a  printf 
   output  command  which  requires a float parameter.
   If <description> does not include  "%%" , it is used as a label.
   Some examples:
   "Paging file usage is %%.2f %%%%"
   "%%.f %%%% paging file used."
  INSTANCES =
   Check any performance counter object of Windows NT /2000 .
   Syntax: check_nt -H < hostname > -p <port> - v  INSTANCES -l <counter object>
   <counter object> is a Windows Perfmon Counter object (eg. Process),
   if  it is two words, it should be enclosed  in  quotes
   The returned results will be a comma-separated list of instances on 
    the selected computer  for  that object.
   The purpose of this is to be run from  command  line to determine what instances
    are available  for  monitoring without having to log onto the Windows server
     to run Perfmon directly.
   It can also be used  in  scripts that automatically create Nagios service
    configuration files.
   Some examples:
   check_nt -H 192.168.1.1 -p 1248 - v  INSTANCES -l Process    #check_nt的语法
  
Notes:
  - The NSClient service should be running on the server to get any information
    (http: //nsclient .ready2run. nl ).
  - Critical thresholds should be lower than warning thresholds
  - Default port 1248 is sometimes  in  use by other services. The error
    output when this happens contains  "Cannot map xxxxx to protocol number" .
    One fix  for  this is to change the port to something  else  on check_nt 
    and on the client service it's connecting to.
 
Send email to help@nagios-plugins.org  if  you have questions regarding use
of this software. To submit patches or suggest improvements, send email to
devel@nagios-plugins.org






2、check_nt命令的使用

check_nt参数解释

-w:警告比例

-c:紧急比例

-l:过去5分钟的平均值,80%的警告  90%紧急wKiom1QmuKqBRFWJAAJvlnFCVQ4764.jpg


四、定义命令、主机、服务

1、定义命令

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@Nagios ~] # vim /usr/local/nagios/etc/objects/commands.cfg
# 'check_win' command definition
define  command {
         command_name    check_win
         command_line    $USER1$ /check_nt  -H $HOSTADDRESS$ -p 12489 - v  $ARG1$ $ARG2$
         }
注释:
$..$    表示系统内置的宏,也就是所谓的变量
$USER1$ 表示插件所在的目录  
-H      指定主机地址
$HOSTADDRESS$  应用到哪个主机,就用哪个主机的地址
$ARG1$  传递的参数,形参
-s      指定密码 默认为空


2、定义主机和服务

1
2
3
[root@Nagios objects] # cp windows.cfg windows106.cfg 
[root@Nagios objects] # sed -i 's/winserver/Windows106/g' windows106.cfg 
[root@Nagios objects] # sed -i 's/192.168.1.2/192.168.0.106/' windows106.cfg

4、检测配置文件是否有语法错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[root@Nagios ~] # service nagios configtest
 
Nagios Core 4.0.7
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 06-03-2014
License: GPL
 
Website: http: //www .nagios.org
Reading configuration data...
    Read main config  file  okay...
    Read object config files okay...
 
Running pre-flight check on configuration data...
 
Checking objects...
     Checked 8 services.
     Checked 1 hosts.
     Checked 1 host  groups .
     Checked 0 service  groups .
     Checked 1 contacts.
     Checked 1 contact  groups .
     Checked 25 commands.
     Checked 5  time  periods.
     Checked 0 host escalations.
     Checked 0 service escalations.
Checking  for  circular paths...
     Checked 1 hosts
     Checked 0 service dependencies
     Checked 0 host dependencies
     Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
 
Total Warnings: 0
Total Errors:   0
 
Things  look  okay - No serious problems were detected during the pre-flight check
Object precache  file  created:
/usr/local/nagios/var/objects .precache


5、重启nagios服务

1
2
3
4
[root@Nagios objects] # service nagios restart
Running configuration check...
Stopping nagios: . done .
Starting nagios:  done .


四、浏览器查看监控信息

1、登陆后点击【Hosts】,查看新监控的Windows主机信息

wKioL1Qmw93SnhVOAAOI_HKVwgw436.jpg


2、点击【Services】,查看Windows服务的状态信息

wKiom1Qmw7awxW6cAAfMmerFYOc506.jpg


3、等待几分钟后状态就正常了,如下图所示

wKiom1Qmys7Sl-qRAAVcoYMMwSw515.jpg


三、NRPE的方式监控windows主机

1、修改NSClient++的配置文件

wKioL1QnawbRvD3RAAO2J91L10Q919.jpg

2、重新启动NSClient++服务

wKioL1Qna8GTPNRKAASz4_IEazg262.jpg

3、Nagios服务端测试NRPE命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
[root@Nagios ~] # cd /usr/local/nagios/libexec/
[root@Nagios libexec] # ./check_nrpe -h
 
NRPE Plugin  for  Nagios
Copyright (c) 1999-2008 Ethan Galstad (nagios@nagios.org)
Version: 2.15
Last Modified: 09-06-2013
License: GPL v2 with exemptions (-l  for  more  info)
SSL /TLS  Available: Anonymous DH Mode, OpenSSL 0.9.6 or higher required
 
Usage: check_nrpe -H <host> [ -b <bindaddr> ] [-4] [-6] [-n] [-u] [-p <port>] [-t <timeout>] [-c < command >] [-a <arglist...>]
 
Options:
  -n         = Do no use SSL
  -u         = Make socket timeouts  return  an UNKNOWN state instead of CRITICAL
  <host>     = The address of the host running the NRPE daemon
  <bindaddr> = bind to  local  address
  -4         = user ipv4 only
  -6         = user ipv6 only
  [port]     = The port on  which  the daemon is running (default=5666)
  [timeout]  = Number of seconds before connection  times  out (default=10)
  [ command ]  = The name of the  command  that the remote daemon should run
  [arglist]  = Optional arguments that should be passed to the  command .  Multiple
               arguments should be separated by a space.  If provided, this must be
               the last option supplied on the  command  line.
 
Note:
This plugin requires that you have the NRPE daemon running on the remote host.
You must also have configured the daemon to associate a specific plugin  command
with the [ command ] option you are specifying here.  Upon receipt of the
[ command ] argument, the NRPE daemon will run the appropriate plugin  command  and
send the plugin output and  return  code back to *this* plugin.  This allows you
to execute plugins on remote hosts and  'fake'  the results to  make  Nagios think
the plugin is being run locally.
 
 
check_nrpe语法:
check_nrpe ... -c < command > [-a <argument> <argument> <argument>]
 
 
check_nrpe的内置命令:
· CheckAlwaysCRITICAL (check)
· CheckAlwaysOK (check)
· CheckAlwaysWARNING (check)
· CheckCPU (check)
· CheckCRITICAL (check)
· CheckCounter (check)
· CheckEventLog /CheckEventLog  (check)
· CheckFile (check)
· CheckFileSize (check)
· CheckMem (check)
· CheckMultiple (check)
· CheckOK (check)
· CheckProcState (check)
· CheckServiceState (check)
· CheckTaskSched /CheckTaskSched  (check)
· CheckUpTime (check)
· CheckVersion (check)
· CheckWARNING (check)
· CheckWMI /CheckWMI  (check)
· CheckWMIValue (check)
1
2
[root@Nagios libexec] # ./check_nrpe -H 192.168.1.142 -p 5666 -c CheckCPU -a warn=80 crit=90 time=20m time=10s time=4
OK CPU Load ok.| '20m' =0%;80;90  '10s' =0%;80;90  '4' =0%;80;90







     本文转自zys467754239 51CTO博客,原文链接:http://blog.51cto.com/467754239/1558861,如需转载请自行联系原作者





相关文章
|
3月前
|
Arthas 监控 Java
Arthas 可以用于监控和诊断在 Windows 系统下部署的 Tomcat 服务
Arthas 可以用于监控和诊断在 Windows 系统下部署的 Tomcat 服务
175 2
|
2月前
|
弹性计算 Ubuntu Linux
2024年Windows/Linux搭建幻兽帕鲁主机教程(超详细图文)
幻兽帕鲁作为一款热门多人在线游戏,为了给玩家提供稳定、流畅的联机体验,阿里云提供了高效便捷的快速部署解决方案,本文将为大家介绍阿里云一键部署幻兽帕鲁联机服务器详细教程。
|
4月前
|
监控 安全 API
7.2 Windows驱动开发:内核注册并监控对象回调
在笔者上一篇文章`《内核枚举进程与线程ObCall回调》`简单介绍了如何枚举系统中已经存在的`进程与线程`回调,本章`LyShark`将通过对象回调实现对进程线程的`句柄`监控,在内核中提供了`ObRegisterCallbacks`回调,使用这个内核`回调`函数,可注册一个`对象`回调,不过目前该函数`只能`监控进程与线程句柄操作,通过监控进程或线程句柄,可实现保护指定进程线程不被终止的目的。
29 0
7.2 Windows驱动开发:内核注册并监控对象回调
|
4月前
|
监控 安全 API
7.6 Windows驱动开发:内核监控FileObject文件回调
本篇文章与上一篇文章`《内核注册并监控对象回调》`所使用的方式是一样的都是使用`ObRegisterCallbacks`注册回调事件,只不过上一篇博文中`LyShark`将回调结构体`OB_OPERATION_REGISTRATION`中的`ObjectType`填充为了`PsProcessType`和`PsThreadType`格式从而实现监控进程与线程,本章我们需要将该结构填充为`IoFileObjectType`以此来实现对文件的监控,文件过滤驱动不仅仅可以用来监控文件的打开,还可以用它实现对文件的保护,一旦驱动加载则文件是不可被删除和改动的。
29 1
7.6 Windows驱动开发:内核监控FileObject文件回调
|
4月前
|
监控 安全 API
7.5 Windows驱动开发:监控Register注册表回调
在笔者前一篇文章`《内核枚举Registry注册表回调》`中实现了对注册表的枚举,本章将实现对注册表的监控,不同于32位系统在64位系统中,微软为我们提供了两个针对注册表的专用内核监控函数,通过这两个函数可以在不劫持内核API的前提下实现对注册表增加,删除,创建等事件的有效监控,注册表监视通常会通过`CmRegisterCallback`创建监控事件并传入自己的回调函数,与该创建对应的是`CmUnRegisterCallback`当注册表监控结束后可用于注销回调。
45 0
7.5 Windows驱动开发:监控Register注册表回调
|
4月前
|
监控 安全 API
7.1 Windows驱动开发:内核监控进程与线程回调
在前面的文章中`LyShark`一直在重复的实现对系统底层模块的枚举,今天我们将展开一个新的话题,内核监控,我们以`监控进程线程`创建为例,在`Win10`系统中监控进程与线程可以使用微软提供给我们的两个新函数来实现,此类函数的原理是创建一个回调事件,当有进程或线程被创建或者注销时,系统会通过回调机制将该进程相关信息优先返回给我们自己的函数待处理结束后再转向系统层。
59 0
7.1 Windows驱动开发:内核监控进程与线程回调
|
4月前
|
监控 Windows
4.4 Windows驱动开发:内核监控进程与线程创建
当你需要在Windows操作系统中监控进程的启动和退出时,可以使用`PsSetCreateProcessNotifyRoutineEx`函数来创建一个`MyCreateProcessNotifyEx`回调函数,该回调函数将在每个进程的创建和退出时被调用。PsSetCreateProcessNotifyRoutineEx 用于在系统启动后向内核注册一个回调函数,以监视新进程的创建和退出,
39 0
4.4 Windows驱动开发:内核监控进程与线程创建
|
4月前
|
监控 安全 Windows
4.3 Windows驱动开发:监控进程与线程对象操作
在内核中,可以使用`ObRegisterCallbacks`这个内核回调函数来实现监控进程和线程对象操作。通过注册一个`OB_CALLBACK_REGISTRATION`回调结构体,可以指定所需的回调函数和回调的监控类型。这个回调结构体包含了回调函数和监控的对象类型,还有一个`Altitude`字段,用于指定回调函数的优先级。优先级越高的回调函数会先被调用,如果某个回调函数返回了一个非NULL值,后续的回调函数就不会被调用。当有进程或线程对象创建、删除、复制或重命名时,内核会调用注册的回调函数。回调函数可以访问被监控对象的信息,如句柄、进程ID等,并可以采取相应的操作,如打印日志、记录信息等。
28 0
4.3 Windows驱动开发:监控进程与线程对象操作
|
5月前
|
监控 C# Windows
内网桌面监控软件中的远程控制功能实现(基于C#和Windows Forms)
近年来,随着远程办公的兴起,对内网桌面监控软件的需求逐渐增加。本文将探讨如何通过C#和Windows Forms实现内网桌面监控软件中的远程控制功能,并在结尾部分介绍监控到的数据如何自动提交到网站。
279 0
|
6月前
|
运维 安全 Linux
企业实战(18)超简单实现轻量级开源堡垒机Teleport管理Linux/Windows主机(2)
企业实战(18)超简单实现轻量级开源堡垒机Teleport管理Linux/Windows主机(2)