Lab 1.2 Monitor Windows server bằng Nagios

root

Leader IT/Architect
Dec 31, 2012
1,153
72
48
Sau khi cài đặt thành công Nagios ở Lab 1.1 chúng ta sẽ tiến hành thực hiện Monitor thử máy Windows server 2008R2.

- Đây là mô hình hoạt động




1. Cài đặt NSclient trên máy cần giám sát (Windows 2k8)
- Để thực hiện giám sát Windows bằng Nagios thì trên máy Windows bạn cần phải cài 1 plugin NSClient để Nagios có thể giám sát được. Tùy vào Windows bạn sử dụng là 32 hay 64 bit thì bạn sẽ download plugin NSClient++ tương ứng 32bit hoặc 64 bit.
- Các bạn thực hiện download NSClient tại đây:
- Cài đặt NSClient++ trên máy Windows server 2oo8R2


- Các điền IP của nagios server vào đây nhé


- Đối với các Version NSClient cũ ta làm như dưới từ bước 2.2 tới bước 2.10 ngoại trừ bước 2.6, vì khi setup cài đặt Version mới này thì NSClient++ đã làm dùm ta các bước, bước 2.6 ta vẫn phải làm. Nó sẽ setup như 1 chương trình bình thường và mặc định nằm ở C:\Program Files\NSClient++>
- Các bước dưới dành cho version “xưa” cũ (trừ bước 2.6).
  • 2.2: Giải nén file NSClient tới C:\NSClient++
  • 2.3: Mở comanline (Start à Run gõ cmd) chuyển về thư mục C:\NSClinet++
  • 2.4: Đăng ký NSClient++ tới dịch vụ hệ thống bằng lệnh: nsclient++ /install
  • 2.5: Cài đặt NSClient++ systray bằng lệnh:
  • nsclient++ SysTray
- Với các bản mới hơn thì chúng ta chỉ cần làm bước sau:

  • 2.6: Mở dịch vụ quản lý (Starrt à Run gõ services.msc) và đảm bảo rằng dịch vụ NSClientpp đã được cho phép (Nhớ tích mục Allow service to interact with desktop)

- Chính sửa C:\Program Files\NSClient++\nsclient.ini

Code:
[/modules]


; CheckDisk - CheckDisk can check various file and disk related things. The current version has commands to check Size of hard drives and directories.
CheckDisk = 1


; Event log Checker. - Check for errors and warnings in the event log. This is only supported through NRPE so if you plan to use only NSClient this wont help you at all.
CheckEventLog = 1


; Check External Scripts - A simple wrapper to run external scripts and batch files.
CheckExternalScripts = 1


; Helper function - Various helper function to extend other checks. This is also only supported through NRPE.
CheckHelpers = 1


; Check NSCP - Checkes the state of the agent
CheckNSCP = 1


; CheckSystem - Various system related checks, such as CPU load, process state, service state memory usage and PDH counters.
CheckSystem = 1


; CheckWMI - CheckWMI can check various file and disk related things. The current version has commands to check Size of hard drives and directories.
CheckWMI = 1


; NRPE server - A simple server that listens for incoming NRPE connection and handles them.
NRPEServer = 1


; NSCAClient - Passive check support over NSCA.
NSCAClient = 1


; NSClient server - A simple server that listens for incoming NSClient (check_nt) connection and handles them. Although NRPE is the preferred method NSClient is fully supported and can be used for simplicity or for compatibility.
NSClientServer = 1




; Undocumented section
[/settings/default]


; ALLOWED HOSTS - A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges.
[COLOR=#FF0000]allowed hosts = 10.8.8.133[/COLOR]


; PASSWORD - Password used to authenticate againast server
[COLOR=#FF0000]password = svuit.com[/COLOR]


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


; A list of aliases available. An alias is an internal command that has been "wrapped" (to add arguments). Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)
[/settings/external scripts/alias]


; alias_cpu - Alias for alias_cpu. To configure this item add a section called: /settings/external scripts/alias/alias_cpu
alias_cpu = checkCPU warn=80 crit=90 time=5m time=1m time=30s


; alias_cpu_ex - Alias for alias_cpu_ex. To configure this item add a section called: /settings/external scripts/alias/alias_cpu_ex
alias_cpu_ex = checkCPU warn=$ARG1$ crit=$ARG2$ time=5m time=1m time=30s


; alias_disk - Alias for alias_disk. To configure this item add a section called: /settings/external scripts/alias/alias_disk
alias_disk = CheckDriveSize MinWarn=10% MinCrit=5% CheckAll FilterType=FIXED


; alias_disk_loose - Alias for alias_disk_loose. To configure this item add a section called: /settings/external scripts/alias/alias_disk_loose
alias_disk_loose = CheckDriveSize MinWarn=10% MinCrit=5% CheckAll FilterType=FIXED ignore-unreadable


; alias_event_log - Alias for alias_event_log. To configure this item add a section called: /settings/external scripts/alias/alias_event_log
alias_event_log = CheckEventLog file=application file=system MaxWarn=1 MaxCrit=1 "filter=generated gt -2d AND severity NOT IN ('success', 'informational') AND source != 'SideBySide'" truncate=800 unique descriptions "syntax=%severity%: %source%: %message% (%count%)"


; alias_file_age - Alias for alias_file_age. To configure this item add a section called: /settings/external scripts/alias/alias_file_age
alias_file_age = checkFile2 filter=out "file=$ARG1$" filter-written=>1d MaxWarn=1 MaxCrit=1 "syntax=%filename% %write%"


; alias_file_size - Alias for alias_file_size. To configure this item add a section called: /settings/external scripts/alias/alias_file_size
alias_file_size = CheckFiles "filter=size > $ARG2$" "path=$ARG1$" MaxWarn=1 MaxCrit=1 "syntax=%filename% %size%" max-dir-depth=10


; alias_mem - Alias for alias_mem. To configure this item add a section called: /settings/external scripts/alias/alias_mem
alias_mem = checkMem MaxWarn=80% MaxCrit=90% ShowAll=long type=physical type=virtual type=paged type=page


; alias_process - Alias for alias_process. To configure this item add a section called: /settings/external scripts/alias/alias_process
alias_process = checkProcState "$ARG1$=started"


; alias_process_count - Alias for alias_process_count. To configure this item add a section called: /settings/external scripts/alias/alias_process_count
alias_process_count = checkProcState MaxWarnCount=$ARG2$ MaxCritCount=$ARG3$ "$ARG1$=started"


; alias_process_hung - Alias for alias_process_hung. To configure this item add a section called: /settings/external scripts/alias/alias_process_hung
alias_process_hung = checkProcState MaxWarnCount=1 MaxCritCount=1 "$ARG1$=hung"


; alias_process_stopped - Alias for alias_process_stopped. To configure this item add a section called: /settings/external scripts/alias/alias_process_stopped
alias_process_stopped = checkProcState "$ARG1$=stopped"


; alias_sched_all - Alias for alias_sched_all. To configure this item add a section called: /settings/external scripts/alias/alias_sched_all
alias_sched_all = CheckTaskSched "filter=exit_code ne 0" "syntax=%title%: %exit_code%" warn=>0


; alias_sched_long - Alias for alias_sched_long. To configure this item add a section called: /settings/external scripts/alias/alias_sched_long
alias_sched_long = CheckTaskSched "filter=status = 'running' AND most_recent_run_time < -$ARG1$" "syntax=%title% (%most_recent_run_time%)" warn=>0


; alias_sched_task - Alias for alias_sched_task. To configure this item add a section called: /settings/external scripts/alias/alias_sched_task
alias_sched_task = CheckTaskSched "filter=title eq '$ARG1$' AND exit_code ne 0" "syntax=%title% (%most_recent_run_time%)" warn=>0


; alias_service - Alias for alias_service. To configure this item add a section called: /settings/external scripts/alias/alias_service
alias_service = checkServiceState CheckAll


; alias_service_ex - Alias for alias_service_ex. To configure this item add a section called: /settings/external scripts/alias/alias_service_ex
alias_service_ex = checkServiceState CheckAll "exclude=Net Driver HPZ12" "exclude=Pml Driver HPZ12" exclude=stisvc


; alias_up - Alias for alias_up. To configure this item add a section called: /settings/external scripts/alias/alias_up
alias_up = checkUpTime MinWarn=1d MinWarn=1h


; alias_updates - Alias for alias_updates. To configure this item add a section called: /settings/external scripts/alias/alias_updates
alias_updates = check_updates -warning 0 -critical 0


; alias_volumes - Alias for alias_volumes. To configure this item add a section called: /settings/external scripts/alias/alias_volumes
alias_volumes = CheckDriveSize MinWarn=10% MinCrit=5% CheckAll=volumes FilterType=FIXED


; alias_volumes_loose - Alias for alias_volumes_loose. To configure this item add a section called: /settings/external scripts/alias/alias_volumes_loose
alias_volumes_loose = CheckDriveSize MinWarn=10% MinCrit=5% CheckAll=volumes FilterType=FIXED ignore-unreadable 


; default - Alias for default. To configure this item add a section called: /settings/external scripts/alias/default
default =
- Khởi động lại dịch vụ NSClient++



2. Cấu hình server Nagios
- Tạo ra host mới và định nghĩa dịch vụ dành cho máy Windows cần theo dõi
- Ta đi định nghĩa các Object (đối tượng) cần theo dõi của máy Windows trong file windows.cfg
Mở file windows.cfg

Code:
[root@server Desktop]# vi /usr/local/nagios/etc/objects/windows.cfg

- Bổ xung máy Windows cần theo dõi. Chỉnh sửa lại các định nghĩa trong file windows.cfg (host_name, alias, address).
# Nếu có nhiều máy tính Windows cần theo dõi, ta phải định nghĩa thêm cho nó (copy hết, paste xuống dưới, thay các thông số cần thiết, các dịch vụ ở dưới cũng vậy).

Code:
define host{
        use             windows-server  ; Inherit default values from a template
        host_name       AD2k8.svuit.org ; [COLOR=#00FF00]Tên máy tính cần theo dõi[/COLOR]
        #host_name      winserver       ; The name we're giving to this host
        alias           My Windows Server       ; A longer name associated with the host
        address         10.8.8.134      ;  [COLOR=#00FF00]Địa chỉ IP của máy cần theo dõi.[/COLOR]
        }


##############################################################################
###############################################################################
#
# HOST GROUP DEFINITIONS
#
###############################################################################
###############################################################################


# Define a hostgroup for Windows machines
# All hosts that use the windows-server template will automatically be a member of this group

define hostgroup{
        hostgroup_name  windows-servers ; The name of the hostgroup
        alias           Windows Servers ; Long name of the group
        }

###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
###############################################################################

# Create a service for monitoring the version of NSCLient++ that is installed
# Change the host_name to match the name of the host you defined above


define service{
        use                     generic-service
        host_name               AD2k8.svuit.org
        #host_name              winserver
        service_description     NSClient++ Version
        check_command           check_nt!CLIENTVERSION
        }


# Create a service for monitoring the uptime of the server
# Change the host_name to match the name of the host you defined above
[I][COLOR=#00FF00]#Theo dõi uptime của Windows server[/COLOR][/I]
define service{
        use                     generic-service
        host_name               AD2k8.svuit.org
        #host_name              winserver
        service_description     Uptime
        check_command           check_nt!UPTIME
        }






# Create a service for monitoring CPU load
# Change the host_name to match the name of the host you defined above
[COLOR=#00FF00]# Theo dõi CPU của máy,  Cảnh báo CRITICAL nếu CPU có tải 5 phút là 90% trở lên hoặc WARNING nếu tải 5 phút là 80% hoặc cao hơn.[/COLOR]
define service{
        use                     generic-service
        host_name               AD2k8.svuit.org
        #host_name              winserver
        service_description     CPU Load
        check_command           check_nt!CPULOAD!-l 5,80,90
        }






# Create a service for monitoring memory usage
# Change the host_name to match the name of the host you defined above
[COLOR=#00FF00]# Theo dõi Memory của máy, Cảnh báo CRITICAL nếu bộ nhớ sử dụng 90% hoặc hơn, cảnh báo WARNING nếu bộ nhớ sử dụng 80% hoặc hơn.[/COLOR]
define service{
        use                     generic-service
        host_name               AD2k8.svuit.org
        #host_name              winserver
        service_description     Memory Usage
        check_command           check_nt!MEMUSE!-w 80 -c 90
        }


# Create a service for monitoring C:\ disk usage
# Change the host_name to match the name of the host you defined above
[COLOR=#00FF00]# Theo dõi dung lượng đĩa còn trống, Cảnh báo CRITICAL nếu dung lượng ổ cứng sử dụng 90% hoặc hơn, cảnh báo WARNING nếu dung lượng ổ cứng sử dụng 80% hoặc hơn.[/COLOR]
define service{
        use                     generic-service
        #host_name              winserver
        host_name               AD2k8.svuit.org
        service_description     C:\ Drive Space
        check_command           check_nt!USEDDISKSPACE!-l c -w 80 -c 90
        }


# Create a service for monitoring the W3SVC service
# Change the host_name to match the name of the host you defined above
[COLOR=#00FF00]# Theo dõi dịch vụ W3SVC, cảnh báo CRITICAL nếu dịch vụ bị ngừng[/COLOR]
define service{
        use                     generic-service
        host_name               AD2k8.svuit.org
        #host_name              winserver
        service_description     W3SVC
        check_command           check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
        }



# Create a service for monitoring the Explorer.exe process
# Change the host_name to match the name of the host you defined above
[COLOR=#00FF00]# Theo dõi dịch bụ explorer, cảnh báo CRITICAL nếu dịch vụ bị ngừng[/COLOR]
define service{
        use                     generic-service
        host_name               AD2k8.svuit.org
        #host_name              winserver
        service_description     Explorer
        check_command           check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
        }



Password Protection
- Nếu ta có đặc tả yêu cầu password trong khi cài đặt NSClient++ trên máy Windows ta cần phải chỉnh sửa lại lệnh check_nt bao gồm password.
- Mở file commands.cfg và chỉnh lại, thêm "-s " vào (Password này ta đã đặt khi cài NSClient++ trên Windows).
Code:
# vi /usr/local/nagios/etc/objects/commands.cfg

Sửa dòng sau:
Code:
# 'check_nt' command definition
define command{
        command_name    check_nt
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 [COLOR=#FF0000]-s svuit.com[/COLOR] -v $ARG1$ $ARG2$
        }

- Khởi động lại dịch vụ Nagios.

Code:
# systemctl start nagios.service

3. Kết quả
- Qua trình duyệt web login vào Nagios để xem lại thành quả
- Trên map đã hiện máy Windows server 2k8

2014-08-24_185958.jpg

- Bạn có thể rê chuột đến máy 2k8 và xem thông tin

2014-08-24_190020.jpg

- Các host mà Nagios đang thực hiện giám sát

2014-08-24_190031.jpg

- Trạng thái của máy 2k8

2014-08-24_190041.jpg

- Xem lịch sử của máy 2k8

2014-08-24_190056.jpg

- Thông tin HDD của 2k8

2014-08-24_190108.jpg
 

About us

  • Securityzone.vn là một trang web chuyên về an ninh mạng và công nghệ thông tin. Trang web này cung cấp các bài viết, tin tức, video, diễn đàn và các dịch vụ liên quan đến lĩnh vực này. Securityzone.vn là một trong những cộng đồng IT lớn và uy tín tại Việt Nam, thu hút nhiều người quan tâm và tham gia. Securityzone.vn cũng là nơi để các chuyên gia, nhà nghiên cứu, sinh viên và người yêu thích an ninh mạng có thể trao đổi, học hỏi và chia sẻ kiến thức, kinh nghiệm và giải pháp về các vấn đề bảo mật trong thời đại số.

Quick Navigation

User Menu