网站搜索

如何将Windows主机添加到Nagios监控服务器


本文介绍如何监控Windows机器的“私有”服务,例如CPU负载磁盘使用情况 >内存使用情况, 服务等。为此,我们需要在Windows计算机上安装NSClient++插件。该插件充当 Windows 计算机和 Nagios 之间的代理,并通过与 check_nt 插件通信来监视实际服务。如果您遵循我们的 Nagios 安装指南,则 check_nt 插件已安装在 Nagios 监控服务器上。

我们假设您已经根据我们的以下指南安装并配置了 Nagios 服务器。

  1. 如何在 RHEL/CentOS 6.x/5.x 和 Fedora 19/18/17 上安装 Nagios 4.0.1
  2. 将Linux主机添加到Nagios监控服务器

要监控Windows计算机,您需要执行以下几个步骤:

  1. 在 Windows 机器上安装 NSClient++ 插件。
  2. 配置 Nagios 服务器以监视 Windows 计算机。
  3. 为 Windows 计算机监控添加新的主机和服务定义。
  4. 重新启动 Nagios 服务。

为了使本指南更简单、更容易,在 Nagios 安装中已经为您完成了一些配置。

  1. check_nt 命令定义已添加到 command.cfg 文件中。 check_nt插件使用此定义命令来监控Windows服务。
  2. 已在 templates.cfg 文件中创建 Windows 服务器主机模板。此模板允许您添加新的 Windows 主机定义。

上述两个文件“command.cfg”和“templates.cfg”文件可以在/usr/local/nagios/etc/objects/目录。您可以修改和添加适合您要求的自己的定义。但是,我建议您按照本文中描述的说明进行操作,您将在 20 分钟内成功监控您的 Windows 主机。

第 1 步:在 Windows 计算机上安装 NSClient++ 代理

请按照以下说明在远程 Windows 主机上安装NSClient++ Agent。首先下载最新稳定版本NSClient++ 0.3.1插件源文件,可以在下面的链接找到。

  1. http://sourceforge.net/projects/nscplus/

下载最新的稳定版本后,将 NSClient++ 文件解压缩到新的 C:\NSClient++ 目录中。

现在从开始屏幕打开MS-DOS命令提示符 -> 运行 -> 输入“cmd”并按 Enter 并切换到 C:\NSClient++ 目录。

C:\NSClient++

接下来,使用以下命令在系统上注册 NSClient++ 服务。

nsclient++ /install

最后,使用以下命令安装 NSClient++ 系统托盘

nsclient++ SysTray

打开Windows 服务管理器,右键单击NSClient,转到属性,然后选择“登录”选项卡,然后单击“允许服务与桌面交互”复选框。如果尚未允许,请选中该框以允许。

打开位于 C:\NSClient++ 目录的 NSC.INI 文件,并取消注释“模块”部分中定义的所有模块,除了 >CheckWMI.dllRemoteConfiguration.dll

[modules]
;# NSCLIENT++ MODULES
;# A list with DLLs to load at startup.
;  You will need to enable some of these for NSClient++ to work.
; ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
; *                                                               *
; * N O T I C E ! ! ! - Y O U   H A V E   T O   E D I T   T H I S *
; *                                                               *
; ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
FileLogger.dll
CheckSystem.dll
CheckDisk.dll
NSClientListener.dll
NRPEListener.dll
SysTray.dll
CheckEventLog.dll
CheckHelpers.dll
;CheckWMI.dll
;
; RemoteConfiguration IS AN EXTREM EARLY IDEA SO DONT USE FOR PRODUCTION ENVIROMNEMTS!
;RemoteConfiguration.dll
; NSCA Agent is a new beta module use with care!
;NSCAAgent.dll
; LUA script module used to write your own "check deamon" (sort of) early beta.
;LUAScript.dll
; Script to check external scripts and/or internal aliases, early beta.
;CheckExternalScripts.dll
; Check other hosts through NRPE extreme beta and probably a bit dangerous! :)
;NRPEClient.dll

取消注释“设置”部分中的“allowed_hosts”,并定义 Nagios 监控服务器IP 地址或将其留空以允许任何主机连接。

[Settings]
;# ALLOWED HOST ADDRESSES
;  This is a comma-delimited list of IP address of hosts that are allowed to talk to the all daemons.
;  If leave this blank anyone can access the deamon remotly (NSClient still requires a valid password).
;  The syntax is host or ip/mask so 192.168.0.0/24 will allow anyone on that subnet access
allowed_hosts=172.16.27.41

取消注释“NSClient”部分中的“端口”,并将其设置为默认端口“12489”。确保在Windows 防火墙上打开“12489”端口。

[NSClient]
;# NSCLIENT PORT NUMBER
;  This is the port the NSClientListener.dll will listen to.
port=12489

最后使用以下命令启动 NSClient++ 服务。

nsclient++ /start

如果您正确安装和配置,您应该在系统托盘中看到一个黄色圆圈的新图标,里面有一个黑色的“M”。

步骤2:配置Nagios服务器并添加Windows主机

现在登录Nagios服务器并在Nagios配置文件中添加一些对象定义来监控新的Windows机器。打开windows.cfg文件,使用Vi编辑器进行编辑。

[root@tecmint]# vi /usr/local/nagios/etc/objects/windows.cfg

已为 Windows 计算机定义了示例 Windows 主机定义,您只需将主机定义(例如 host_name别名地址 字段)更改为适当的即可您的Windows计算机的值。

###############################################################################
###############################################################################
#
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       winserver       ; The name we're giving to this host
        alias           My Windows Server       ; A longer name associated with the host
        address         172.31.41.53    ; IP address of the host
        }

以下服务已在 windows.cfg 文件中添加并启用。如果您希望添加更多需要监控的其他服务定义,您可以简单地将这些定义添加到同一配置文件中。确保更改上述步骤中定义的 host_name 的所有服务的 host_name

define service{
	use			generic-service
	host_name		winserver
	service_description	NSClient++ Version
	check_command		check_nt!CLIENTVERSION
	}

Add the following service definition to monitor the uptime of the Windows server.

define service{
	use			generic-service
	host_name		winserver
	service_description	Uptime
	check_command		check_nt!UPTIME
	}

Add the following service definition to monitor the CPU utilization on the Windows server and generate a CRITICAL alert if the 5-minute CPU load is 90% or more or a WARNING alert if the 5-minute load is 80% or greater.

define service{
	use			generic-service
	host_name		winserver
	service_description	CPU Load
	check_command		check_nt!CPULOAD!-l 5,80,90
	}

Add the following service definition to monitor memory usage on the Windows server and generate a CRITICAL alert if memory usage is 90% or more or a WARNING alert if memory usage is 80% or greater.

define service{
	use			generic-service
	host_name		winserver
	service_description	Memory Usage
	check_command		check_nt!MEMUSE!-w 80 -c 90
	}

Add the following service definition to monitor usage of the C:\ drive on the Windows server and generate a CRITICAL alert if disk usage is 90% or more or a WARNING alert if disk usage is 80% or greater.

define service{
	use			generic-service
	host_name		winserver
	service_description	C:\ Drive Space
	check_command		check_nt!USEDDISKSPACE!-l c -w 80 -c 90
	}

Add the following service definition to monitor the W3SVC service state on the Windows machine and generate a CRITICAL alert if the service is stopped.

define service{
	use			generic-service
	host_name		winserver
	service_description	W3SVC
	check_command		check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
	}

Add the following service definition to monitor the Explorer.exe process on the Windows machine and generate a CRITICAL alert if the process is not running.

define service{
	use			generic-service
	host_name		winserver
	service_description	Explorer
	check_command		check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
	}

最后,取消注释/usr/local/nagios/etc/nagios.cfg中的windows.cfg文件。

[root@tecmint]# vi /usr/local/nagios/etc/nagios.cfg
Definitions for monitoring a Windows machine
cfg_file=/usr/local/nagios/etc/objects/windows.cfg

最后,验证 Nagios 配置文件是否存在任何错误。

[root@tecmint]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

如果验证过程抛出任何错误消息,请修复这些错误,直到验证过程完成且没有任何错误消息。修复这些错误后,重新启动 Nagios 服务。

[root@tecmint]# service nagios restart

Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.

就是这样。现在转到 Nagios 监控 Web 界面“http://Your-server-IP-address/nagios”或“http://FQDN/nagios”并提供用户名“nagiosadmin”和密码。检查远程 Windows 主机是否已添加且正在受监控。

就是这样!现在,在我即将发表的文章中,我将向您展示如何将打印机交换机添加到Nagios监控服务器。如果您在将 Windows 主机添加到 Nagios 时遇到任何困难。请通过评论部分评论您的疑问,在此之前请继续关注linux-console.net以获取更多此类有价值的文章。