Nagios利用NSClient++監(jiān)控Windows主機(jī)-創(chuàng)新互聯(lián)

一、簡介

創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、成都外貿(mào)網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的比如網(wǎng)站設(shè)計(jì)、移動媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

1、獲取更多的NSClient原理,請參考NSClient++官方站點(diǎn)

NSClient++官網(wǎng):http://www.nsclient.org/

2、NSClient++與NRPE

NSClient++的工作原理

Nagios利用NSClient++監(jiān)控Windows主機(jī)

NRPE的工作原理

Nagios利用NSClient++監(jiān)控Windows主機(jī)

Nagios對Windows主機(jī)的監(jiān)控主要有三種方法

第一種是NSclient++

第二種是NRPE

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

NSclient++與nrpe大的區(qū)別就是:

1、被監(jiān)控機(jī)上安裝有nrpe,并且還有插件,最終的監(jiān)控是由這些插件來進(jìn)行的.當(dāng)監(jiān)控主機(jī)將監(jiān)控請求發(fā)給nrpe后,nrpe調(diào)用插件來完成監(jiān)控.

2、NSclient++則不同,被監(jiān)控機(jī)上只安裝NSclient++,沒有任何的插件.當(dāng)監(jiān)控主機(jī)將監(jiān)控請求發(fā)給NSclient++后,NSclient++直接完成監(jiān)控,所有的監(jiān)控是由NSclient++完成的。

這也說明了NSclient++的一個(gè)很大的問題,不靈活,沒有可擴(kuò)展性.它只能完成自己本身包含的監(jiān)控操作,不能由一些插件來擴(kuò)展.好在NSclient++已經(jīng)做的不錯(cuò)了,基本上可以完全滿足我們的監(jiān)控需要。

二、check_nt的方式監(jiān)控windows主機(jī)

1、下載NSClient++

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

2、安裝NSClient++

Nagios利用NSClient++監(jiān)控Windows主機(jī)

Nagios利用NSClient++監(jiān)控Windows主機(jī)

Nagios利用NSClient++監(jiān)控Windows主機(jī)

Nagios利用NSClient++監(jiān)控Windows主機(jī)

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

允許的主機(jī)地址:Nagios服務(wù)器端的IP地址

NSClient password(only userd via check_nt)

NSClient的密碼:填寫Nagios跟NSClient++進(jìn)程通信的密碼,可以不設(shè)置

Modules to load:

安裝并加載相應(yīng)的模塊:NSClient++自帶的有check_plugins插件,check_nt,check_nrpe,NSCA,WMI

在這里我們?nèi)窟x擇,以后會有用到的。

Nagios利用NSClient++監(jiān)控Windows主機(jī)

Nagios利用NSClient++監(jiān)控Windows主機(jī)

點(diǎn)擊【Finsh】,表示安裝NSClient++完成

Nagios利用NSClient++監(jiān)控Windows主機(jī)

3、查看NSClient++服務(wù)是否已經(jīng)啟用

Nagios利用NSClient++監(jiān)控Windows主機(jī)

Nagios利用NSClient++監(jiān)控Windows主機(jī)

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

默認(rèn)是安裝在C:\Program Files\NSClient++ 目錄下,NSC.ini即為NSClient服務(wù)的配置文件,一般我們無需修改,但是當(dāng)我們監(jiān)控端的IP地址改變時(shí),或者密碼忘記,即可以在這里修改了。

安裝時(shí)加載的模塊

Nagios利用NSClient++監(jiān)控Windows主機(jī)

設(shè)置允許連接的地址:為Nagios的IP地址

Nagios利用NSClient++監(jiān)控Windows主機(jī)

NRPE的默認(rèn)端口號

Nagios利用NSClient++監(jiān)控Windows主機(jī)

三、NSClient應(yīng)用監(jiān)控

NSClient++與Nagios服務(wù)器通信,主要使用Nagios服務(wù)器的check_nt插件。原理圖如下

Nagios利用NSClient++監(jiān)控Windows主機(jī)

1、check_nt插件的使用說明

[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)  #默認(rèn)端口號
 -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參數(shù)解釋

-w:警告比例

-c:緊急比例

-l:過去5分鐘的平均值,80%的警告  90%緊急Nagios利用NSClient++監(jiān)控Windows主機(jī)

四、定義命令、主機(jī)、服務(wù)

1、定義命令

[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$
        }
注釋:
$..$    表示系統(tǒng)內(nèi)置的宏,也就是所謂的變量
$USER1$ 表示插件所在的目錄  
-H      指定主機(jī)地址
$HOSTADDRESS$  應(yīng)用到哪個(gè)主機(jī),就用哪個(gè)主機(jī)的地址
$ARG1$  傳遞的參數(shù),形參
-s      指定密碼 默認(rèn)為空

2、定義主機(jī)和服務(wù)

[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、檢測配置文件是否有語法錯(cuò)誤

[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服務(wù)

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

四、瀏覽器查看監(jiān)控信息

1、登陸后點(diǎn)擊【Hosts】,查看新監(jiān)控的Windows主機(jī)信息

Nagios利用NSClient++監(jiān)控Windows主機(jī)

2、點(diǎn)擊【Services】,查看Windows服務(wù)的狀態(tài)信息

Nagios利用NSClient++監(jiān)控Windows主機(jī)

3、等待幾分鐘后狀態(tài)就正常了,如下圖所示

Nagios利用NSClient++監(jiān)控Windows主機(jī)

三、NRPE的方式監(jiān)控windows主機(jī)

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

Nagios利用NSClient++監(jiān)控Windows主機(jī)

2、重新啟動NSClient++服務(wù)

Nagios利用NSClient++監(jiān)控Windows主機(jī)

3、Nagios服務(wù)端測試NRPE命令

[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的內(nèi)置命令:
· 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)
[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

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

名稱欄目:Nagios利用NSClient++監(jiān)控Windows主機(jī)-創(chuàng)新互聯(lián)
當(dāng)前網(wǎng)址:http://muchs.cn/article24/csgjje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、微信公眾號、定制開發(fā)、網(wǎng)站策劃、網(wǎng)頁設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)