ค้นหาเว็บไซต์

วิธีเพิ่มโฮสต์ Windows ไปยัง Nagios Monitoring Server


บทความนี้อธิบายวิธีการตรวจสอบบริการเครื่อง Windowsส่วนตัว” เช่น โหลด CPU, การใช้งานดิสก์, การใช้หน่วยความจำ บริการ ฯลฯ สำหรับสิ่งนี้ เราจำเป็นต้องติดตั้งส่วนเสริม NSClient++ บนเครื่อง Windows ส่วนเสริมทำหน้าที่เป็นพร็อกซีระหว่างเครื่อง Windows และ Nagios และตรวจสอบบริการจริงโดยการสื่อสารกับปลั๊กอิน check_nt ปลั๊กอิน check_nt ติดตั้งไว้แล้วบน เซิร์ฟเวอร์การตรวจสอบ Nagios หากคุณปฏิบัติตามคู่มือการติดตั้ง Nagios ของเรา

เราถือว่าคุณได้ติดตั้งและกำหนดค่าเซิร์ฟเวอร์ Nagios ตามคำแนะนำต่อไปนี้แล้ว

  1. วิธีติดตั้ง Nagios 4.0.1 บน RHEL/CentOS 6.x/5.x และ Fedora 19/18/17
  2. เพิ่มโฮสต์ Linux ไปยังเซิร์ฟเวอร์การตรวจสอบ Nagios

หากต้องการตรวจสอบ เครื่อง Windows คุณจะต้องปฏิบัติตามหลายขั้นตอน ดังนี้:

  1. ติดตั้งโปรแกรมเสริม NSClient++ บนเครื่อง Windows
  2. กำหนดค่าเซิร์ฟเวอร์ Nagios สำหรับการตรวจสอบเครื่อง Windows
  3. เพิ่มข้อกำหนดโฮสต์และบริการใหม่สำหรับการตรวจสอบเครื่อง Windows
  4. เริ่มบริการ Nagios ใหม่

เพื่อให้คู่มือนี้ง่ายและสะดวกยิ่งขึ้น ได้มีการกำหนดค่าบางอย่างไว้ให้คุณแล้วในการติดตั้ง Nagios

  1. คำจำกัดความของคำสั่ง check_nt ได้เพิ่มไปยังไฟล์ command.cfg แล้ว คำสั่งคำจำกัดความนี้ใช้โดยปลั๊กอิน check_nt เพื่อตรวจสอบบริการ Windows
  2. เทมเพลต โฮสต์ windows-server สร้างขึ้นแล้วในไฟล์ templates.cfg เทมเพลตนี้อนุญาตให้คุณเพิ่มคำจำกัดความโฮสต์ Windows ใหม่ได้

ไฟล์สองไฟล์ “command.cfg” และ “templates.cfg” สามารถดูได้ที่ /usr/local/nagios/etc/objects/ คุณสามารถแก้ไขและเพิ่มคำจำกัดความของคุณเองให้เหมาะสมกับความต้องการของคุณได้ แต่ฉันขอแนะนำให้คุณทำตามคำแนะนำที่อธิบายไว้ในบทความนี้ และคุณจะสามารถตรวจสอบโฮสต์ windows ของคุณได้สำเร็จภายในเวลาไม่ถึง 20 นาที

ขั้นตอนที่ 1: การติดตั้ง NSClient++ Agent บนเครื่อง Windows

โปรดใช้คำแนะนำด้านล่างเพื่อติดตั้ง NSClient++ Agent บน Remote Windows Host ดาวน์โหลดไฟล์ต้นฉบับเสริม 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++ systray ด้วยคำสั่งต่อไปนี้

nsclient++ SysTray

เปิด Windows Services Manager และคลิกขวาที่ NSClient ไปที่ Properties จากนั้นคลิกแท็บ 'Log On' แล้วคลิก ช่องทำเครื่องหมายที่ระบุว่า “อนุญาตให้บริการโต้ตอบกับเดสก์ท็อป“ หากไม่ได้รับอนุญาต โปรดทำเครื่องหมายในช่องเพื่ออนุญาต

เปิดไฟล์ NSC.INI ซึ่งอยู่ที่ไดเร็กทอรี C:\NSClient++ และยกเลิกการใส่เครื่องหมายข้อคิดเห็นโมดูลทั้งหมดที่กำหนดไว้ในส่วน “โมดูล” ยกเว้น CheckWMI.dll และ RemoteConfiguration.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” ในส่วน “การตั้งค่า” และกำหนด ที่อยู่ IP ของ เซิร์ฟเวอร์การตรวจสอบ Nagios ของคุณ หรือ เว้นว่างไว้เพื่อให้โฮสต์เชื่อมต่อได้

[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' ตรวจสอบให้แน่ใจว่าได้เปิดพอร์ต '12489' บน ไฟร์วอลล์ Windows

[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 คุณสามารถเปลี่ยนคำจำกัดความของโฮสต์ เช่น ฟิลด์ ชื่อโฮสต์, นามแฝง และ ที่อยู่ ให้เหมาะสมได้ ค่าของเครื่อง 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
	}

สุดท้าย ยกเลิกหมายเหตุไฟล์ windows.cfg ใน /usr/local/nagios/etc/nagios.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 Monitoring ที่ “http://Your-server-IP-address/nagios ” หรือ “http://FQDN/nagios ” และระบุ ชื่อผู้ใช้ “nagiosadmin ” และรหัสผ่าน ตรวจสอบว่ามีการเพิ่ม โฮสต์ Windows ระยะไกล และกำลังได้รับการตรวจสอบ

แค่นั้นแหละ! สำหรับตอนนี้ ในบทความที่กำลังจะมีขึ้น ฉันจะแสดงให้คุณเห็นวิธีการเพิ่ม เครื่องพิมพ์ และ สวิตช์ ไปยัง Nagios Monitoring Server หากคุณประสบปัญหาใดๆ ในขณะที่เพิ่มโฮสต์ Windows ไปยัง Nagios โปรดแสดงความคิดเห็นเกี่ยวกับคำถามของคุณผ่านทางส่วนความคิดเห็น จนกว่าจะคอยติดตาม linux-console.net เพื่อดูบทความที่มีคุณค่าประเภทนี้เพิ่มเติม