Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม Bash

เพิ่ม Windows Host เข้า Nagios: คู่มือขั้นตอน

บทความนี้อธิบายวิธี Monitor Windows Machines สำหรับ “Private” Services เช่น CPU Load, Disk Usage, Memory Usage, Services ฯลฯ สำหรับสิ่งนี้ เราต้องติดตั้ง Addon NSClient++ บนเครื่อง Windows Addon นี้ทำหน้าที่เป็น Proxy ระหว่าง Windows Machine และ Nagios และ Monitor Services จริงโดยสื่อสารกับ Plugin check_nt Plugin check_nt ถูกติดตั้งบน Nagios Monitoring Server แล้ว หากคุณปฏิบัติตามคู่มือติดตั้ง Nagios ของเรา

เราสมมติว่าคุณติดตั้งและกำหนดค่า Nagios Server ตามคู่มือของเราแล้ว

  1. How to Install Nagios 4.0.1 on RHEL/CentOS 6.x/5.x and Fedora 19/18/17
  2. Add Linux Host to Nagios Monitoring Server

เพื่อ Monitor Windows Machines คุณจะต้องปฏิบัติตามหลายขั้นตอน และคือ:

  1. ติดตั้ง NSClient++ Addon บน Windows Machine
  2. กำหนดค่า Nagios Server สำหรับ Monitor Windows Machine
  3. เพิ่ม Host และ Service Definitions ใหม่สำหรับ Monitor Windows Machine
  4. Restart Nagios Service

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

  1. check_nt Command Definition ถูกเพิ่มเข้าไปในไฟล์ command.cfg แล้ว Definition นี้ใช้โดย Plugin check_nt เพื่อ Monitor Windows Services
  2. Windows-Server Host Template ถูกสร้างในไฟล์ templates.cfg แล้ว Template นี้อนุญาตให้คุณเพิ่ม Windows Host Definitions ใหม่ได้

ไฟล์ทั้งสอง “command.cfg” และ “templates.cfg” สามารถหาได้ที่ไดเรกทอรี /usr/local/nagios/etc/objects/ คุณสามารถแก้ไขและเพิ่ม Definitions ของตัวเองที่เหมาะกับความต้องการ แต่ ผมแนะนำให้ปฏิบัติตามคำแนะนำในบทความนี้ และคุณจะ Monitor Windows Host ได้สำเร็จภายใน 20 นาที

ขั้นตอนที่ 1: ติดตั้ง NSClient++ Agent บน Windows Machine

โปรดใช้คำแนะนำด้านล่างเพื่อติดตั้ง NSClient++ Agent บน Remote Windows Host ก่อนอื่น ดาวน์โหลดรุ่น Stable ล่าสุด NSClient++ 0.3.1 Addon Source Files ซึ่งหาได้ที่ลิงก์ด้านล่าง

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

เมื่อดาวน์โหลดรุ่น Stable ล่าสุดแล้ว Unzip ไฟล์ NSClient++ ไปยังไดเรกทอรี C:\NSClient++ ใหม่

ตอนนี้เปิด MS-DOS Command Prompt จาก Start Screen –> Run –> พิมพ์ ‘cmd‘ กด Enter และเปลี่ยนไปไดเรกทอรี C:\NSClient++

C:\NSClient++

ต่อไป ลงทะเบียน NSClient++ Service บนระบบด้วยคำสั่งต่อไปนี้:

nsclient++ /install

สุดท้าย ติดตั้ง NSClient++ SysTray ด้วยคำสั่งต่อไปนี้:

nsclient++ SysTray

เปิด Windows Services Manager คลิกขวาที่ NSClient ไป Properties แล้วแท็บ ‘Log On‘ และติ๊กถูกกล่องที่เขียนว่า “Allow service to interact with the desktop“ หากยังไม่ได้อนุญาต โปรดติ๊กถูกเพื่ออนุญาต

เพิ่ม Windows Host เข้า Nagios: คู่มือขั้นตอนInstall NSClient++

เปิดไฟล์ NSC.INI ที่ตั้งอยู่ที่ไดเรกทอรี C:\NSClient++ และ Uncomment Modules ทั้งหมดที่กำหนดในส่วน “modules” ยกเว้น 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

Uncomment “allowed_hosts” ในส่วน “Settings” และกำหนด IP Address ของ Nagios Monitoring Server ของคุณ หรือเว้นว่างไว้เพื่ออนุญาตให้ Host ใดๆ เชื่อมต่อได้

[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

Uncomment “port” ในส่วน “NSClient” และตั้งค่าเป็น Default Port ‘12489‘ ตรวจสอบให้แน่ใจว่าเปิด Port ‘12489‘ บน Windows Firewall

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

สุดท้าย เริ่ม NSClient++ Service ด้วยคำสั่งต่อไปนี้:

nsclient++ /start

หากติดตั้งและกำหนดค่าถูกต้อง คุณควรเห็นไอคอนใหม่ใน System Tray เป็นวงกลมสีเหลืองพร้อม ‘M‘ สีดำด้านใน

ขั้นตอนที่ 2: กำหนดค่า Nagios Server และเพิ่ม Windows Hosts

ตอนนี้ Login เข้า Nagios Server และเพิ่ม Object Definitions บางส่วนในไฟล์ Config ของ Nagios เพื่อ Monitor Windows Machine ใหม่ เปิดไฟล์ windows.cfg เพื่อแก้ไขด้วย Vi Editor

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

Sample Windows Host Definition ถูกกำหนดไว้สำหรับ Windows Machine แล้ว คุณสามารถเปลี่ยน Host Definition เช่น host_name, alias, และ address Fields ให้เป็นค่าที่เหมาะสมของ Windows Machine ของคุณ

###############################################################################
###############################################################################
#
# 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
}

Services ต่อไปนี้ถูกเพิ่มและเปิดใช้งานในไฟล์ windows.cfg แล้ว หากคุณต้องการเพิ่ม Service Definitions อื่นๆ ที่ต้องการ Monitor คุณเพียงแค่เพิ่ม Definitions นั้นๆ เข้าไปใน Config File เดียวกัน ตรวจสอบให้แน่ใจว่าเปลี่ยน host_name สำหรับ Services ทั้งหมดนี้ ให้ตรงกับ 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
}

สุดท้าย Uncomment ไฟล์ 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

สุดท้าย ตรวจสอบไฟล์ Config ของ 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

หากกระบวนการตรวจสอบโยนข้อความ Error ออกมา ให้แก้ไข Errors เหล่านั้นจนกระทั่งกระบวนการตรวจสอบเสร็จสมบูรณ์โดยไม่มี Error Messages หนึ่งตัว เมื่อคุณแก้ไข Errors นั้นแล้ว ให้ Restart Nagios Service

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

แค่นี้ก็จบแล้ว ตอนนี้ไปที่ Nagios Monitoring Web Interface ที่ “https://Your-server-IP-address/nagios” หรือ “https://FQDN/nagios” และใส่ Username “nagiosadmin” และ Password ตรวจสอบว่า Remote Windows Host ถูกเพิ่มและกำลังถูก Monitor อยู่

เพิ่ม Windows Host เข้า Nagios: คู่มือขั้นตอนNagios Monitor Windows Host

แค่นี้ก็จบ! ตอนนี้ ในบทความหน้า ผมจะแสดงวิธีเพิ่ม Printer และ Switches เข้า Nagios Monitoring Server หากคุณมีปัญหาใดๆ ขณะเพิ่ม Windows Host เข้า Nagios โปรด Comment คำถามผ่าน Comment Section จนกว่าจะพบกันใหม่ ติดตาม Tecmint.com สำหรับบทความมีค่าอื่นๆ