nagios

一、簡介

Nagios是一款開源的免費網絡監視工具,能有效監控Windows、Linux和Unix的主機狀態,交換機路由器等網絡設置,打印機等。在系統或服務狀態異常時發出郵件或短信報警第一時間通知網站運維人員,在狀態恢復後發出正常的郵件或短信通知。


二、組成(插件模式)

1、主程序nagios,core,提供平臺,不做任何監測工作,具體監測工作由插件完成。

2、主插件nagios-plugins

3、四個可選的插件NRPE、NSCA、NSCLIENT++、NDOUTILS,snmp

NSCLIENT++(snmp):用來監控windows主機,需要安裝在windows主機上。

NDOUtils++:用來將nagios的配置信息和event產生的數據存入數據庫,並實現數據檢索。

NRPE:監控linux/unix主機,客戶端同樣需要安裝nagios-plugins插件,而服務器端則需要安裝nrpe。

NSCA:用來讓被監控的主機(linux)主動的發送監控信息到nagios上。(複雜沒講解)

285666.tmp

661492.tmp

狀態信號:ok、warning、critical、unknown

依據不同的數值區間定義報警信號,並簡便的顯示監測結果。


三、監控對象

1、主機、主機組

2、服務、資源、服務組

3、聯繫人

4、時段

5、命令(模板-》應用到某個被監控對象上,實現具體的監控)


模板:將多個需要使用相同監控定義的對象,製成一個可以自由使用的框架。


四、nagios監控依賴關係


監控依賴關係是什麼?

其實就是被監控設備之間存在着某種聯繫,比如交換機和下聯的主機、文件服務器和終端等等。在對存在依賴關係的設置進行同時監控的時候,可能會由於其中一個設備故障造成另一個設備無法訪問、無法提供服務的情況。就是依賴關係。


如何處理依賴關係的設備呢?

    對於存在依賴關係的設備,建議在主設備(被依賴設備)出現問題時,關閉受其有影響的依賴設備監控。


監控通知:

    通常情況下,監控對象在一種狀態變化到另一種狀態需要經過一個時間週期,或者頻次週期纔到達發送閾值,同樣對於flapping狀態(狀態間的反覆)也是有觸發閾值的。


五、nagios安裝

通常安裝服務器端很簡單,主要安裝nagios主程序及nagios plugins即可。

如果要監控使用namp協議的設備(路由交換設備、打印)不需要再額外安裝插件。

如果是監控linux設備,服務器端、客戶端需要安裝NRPE、nagios plugins插件。

如果監控windows設備,客戶端安裝nsclient++插件即可。

如果是linux設備使用send-nsca功能,需要服務器端開啓nsca功能。


1、安裝依賴的軟件包(安裝過程中的很多參數不可以修改,比如組,賬戶)

yum install httpd php php-devel php-mysql mysql mysql-devel mysql-server

2、創建工作組和用戶(用戶要在/bin/bash環境)

[root@localhost ~]# groupadd nagcmd

[root@localhost ~]# useradd -G nagcmd nagios

useradd: user 'nagios' already exists

[root@localhost ~]# usermod -G nagcmd nagios

[root@localhost ~]# id nagios

uid=501(nagios) gid=501(nagios) 組=501(nagios),502(nagcmd)


將apache的用戶也加入到nagcmd組,以便於在通過web interface操作nagios時有足夠的權限。

[[email protected] /var/www/html/cacti]# usermod -a -G nagcmd apache


3、下載編譯nagios和nagios plugins

官網下載地址:https://www.nagios.org,此次使用的版本是nagios-xi-5.4.6(此版本收費)和nagios-plugins-2.2.1

安裝xi.5.4.6,解壓縮源碼並進入安裝目錄。

[[email protected] /nagiossxi-5.4.6]# ./fullinstall

以下是教程安裝老版本:

編譯nagios-core-4.3.2:

./configure  --sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker

make all

make install

make install-init

make install-commandmode

make install-config


解釋:--enable-event-broker是爲NDOUtiles++做準備。

4、爲email指定接收告警信息的郵件地址


5、在http的配置文件目錄(conf.d)中創建nagios的web程序配置文件

[root@localhost nagios]# make install-webconf

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf


*** Nagios/Apache conf file installed ***




6、創建用戶登錄web程序的賬戶信息。

[root@localhost nagios]# htpasswd -c /etc/htpasswd.users nagiosadmin

New password: 

Re-type new password: 

Adding password for user nagiosadmin


7、設置開機啓動服務

[root@localhost nagios]# chkconfig --add nagios

[root@localhost nagios]# chkconfig --level 35 nagios on

[root@localhost nagios]# chkconfig --list nagios

nagios          0:關閉 1:關閉 2:關閉 3:啓用 4:啓用 5:啓用 6:關閉


8、安裝nagios-plugins-2.2.1插件,如果要監控mysql,需要加載—with-mysql選項。

[root@localhost nagios-plugins-2.1.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

[root@localhost nagios-plugins-2.1.1]# make && make install


9、默認情況下selinux是拒絕nags web cgi程序的。需要關閉或者關閉拒絕。

方法一、編輯/etc/sysconfig/selinux,將force改爲disable即可。

方法二、放行nagios服務

[root@localhost nagios-plugins-2.1.1]# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin          

[root@localhost nagios-plugins-2.1.1]# chcon -R -t httpd_sys_content_t /usr/local/nagios/share


問題分析:

通過htpasswd創建完登錄認證文件,但是登錄時總是提示錯誤,信息如下:

590912.tmp

問題原因:檢查httpd服務關於nagios.cfg的配置文件信息。位置通常在/etc/httpd/conf.d/nagios.cfg。修改授權認證文件位置。

<Directory "/usr/local/nagios/sbin">

#  SSLRequireSSL

   Options ExecCGI

   AllowOverride None

   <IfVersion >= 2.3>

      <RequireAll>

         Require all granted

#        Require host 127.0.0.1


         AuthName "Nagios Access"

         AuthType Basic

         AuthUserFile /etc/htpasswd.users //檢查此路徑和htpasswd設置的路徑是否一致。

         Require valid-user

      </RequireAll>

   </IfVersion>

   <IfVersion < 2.3>

      Order allow,deny

      Allow from all

#     Order deny,allow

#     Deny from all

#     Allow from 127.0.0.1


      AuthName "Nagios Access"

      AuthType Basic

      AuthUserFile /etc/htpasswd.users

      Require valid-user

   </IfVersion>

</Directory>



六、定義監控對象


監控對象配置文件在安裝目錄下的object文件夾中:

[root@localhost ~]# cd /etc/nagios/

[root@localhost nagios]# ls

cgi.cfg  htpasswd.users  nagios.cfg  objects  resource.cfg

[root@localhost nagios]# cd objects/

[root@localhost objects]# ll

總用量 48

-rw-rw-r--. 1 nagios nagios  7716 6月   7 10:24 commands.cfg

-rw-rw-r--. 1 nagios nagios  2166 6月   7 10:24 contacts.cfg

-rw-rw-r--. 1 nagios nagios  5403 6月   7 10:24 localhost.cfg

-rw-rw-r--. 1 nagios nagios  3124 6月   7 10:24 printer.cfg

-rw-rw-r--. 1 nagios nagios  3293 6月   7 10:24 switch.cfg

-rw-rw-r--. 1 nagios nagios 10812 6月   7 10:24 templates.cfg

-rw-rw-r--. 1 nagios nagios  3208 6月   7 10:24 timeperiods.cfg

-rw-rw-r--. 1 nagios nagios  4019 6月   7 10:24 windows.cfg


主配置文件:nagios.cfg

監控對象通過主配置文件來調用objects文件夾下的內容,或者可以自定義調用位置。

# You can specify individual object config files as shown below:

cfg_file=/etc/nagios/objects/commands.cfg


沒有註釋掉的內容表示可以被調用到並進行監控。也可以通過cfg_dir=的方式指定監控對象配置文件的位置。

#cfg_dir=/etc/nagios/servers

#cfg_dir=/etc/nagios/printers

#cfg_dir=/etc/nagios/switches

#cfg_dir=/etc/nagios/routers


resource_file指定的是nagios插件的位置,resource定義的是一個宏USER,實際上就是一個變量

resource_file=/etc/nagios/resource.cfg

resource.cfg定義的變量,這個user1不要隨意更改,可以創建其他變量最大32個。

# Sets $USER1$ to be the path to the plugins

$USER1$=/usr/local/nagios/libexec



監控對象配置文件:objects文件夾下

1、command.cfg

define command{

command_name process-host-perfdata       ##自定義命令名稱

command_line /usr/bin/printf "%b”         ##定義實際命令操作 "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /usr/local/nagios/var/host-perfdata.out

}


2、contacts.cfg

define contactgroup{

        contactgroup_name       admins

        alias                   Nagios Administrators

        members                 nagiosadmin

        }

3、.localhost.cfg

define service{

        use                             local-service         ; Name of service template to use

        host_name                       localhost //唯一

        service_description             HTTP //全機唯一

check_command check_http

notifications_enabled 0

        }



4、templates.cfg

define service{

name local-service  ; The name of this service template

use generic-service ; Inherit default values from the generic-service definition

        max_check_attempts              4 ; Re-check the service up to 4 times in order to determine its final (hard) state

        normal_check_interval           5 ; Check the service every 5 minutes under normal conditions

        retry_check_interval            1 ; Re-check the service every minute until a hard state can be determined

        register                        0        ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!

}


5、timeperiod .cfg

define timeperiod{

name us-holidays //名稱唯一

        timeperiod_name         us-holidays

        alias                   U.S. Holidays


        january 1               00:00-00:00     ; New Years

        monday -1 may           00:00-00:00     ; Memorial Day (last Monday in May)

        july 4                  00:00-00:00     ; Independence Day

        monday 1 september      00:00-00:00     ; Labor Day (first Monday in September)

        thursday 4 november     00:00-00:00     ; Thanksgiving (4th Thursday in November)

        december 25             00:00-00:00     ; Christmas

        }



# This defines a modified "24x7" timeperiod that covers every day of the

# year, except for U.S. holidays (defined in the timeperiod above).

define timeperiod{

        timeperiod_name 24x7_sans_holidays

        alias           24x7 Sans Holidays


use us-holidays ; Get holiday exceptions from other timeperiod


        sunday          00:00-24:00

        monday          00:00-24:00

        tuesday         00:00-24:00

        wednesday       00:00-24:00

        thursday        00:00-24:00

        friday          00:00-24:00

        saturday        00:00-24:00

        }


這裏簡單說一下各個配置文件直接的關係,不同的配置文件依據文件名而有各自的功能,在配置文件內創建各個變量,類似一個個積木塊,並且各個配置文件之間也會調用其他配置文件中的變量塊來實現監控功能。


馬哥培訓nagios:http://edu.51cto.com/lesson/id-11467.html

七、配置

  實現nagios監控windows主機


監測方式可以基於nsclient++、nrpe、nsca、等方式進行監控,不同的協議服務器端使用的命令或插件也不同。

服務器端                     客戶端

check_nt   ---------------nsclient++

check_nrpe--------------nsclient++ nrpe(nagios-plugins)

nsca deamon------------nsca

210186.tmp

1、check_nt通信模式:

1、安裝nsclient++

503440.png

2、通過檢查端口查看服務是否開啓

12489對應客戶端的nsclient++服務和服務器端的check_nt進行通信

5666是nsclient++同服務器端nrpe協議通信對應的端口


3、服務器端通過check_nt命令可以進行監控了(命令在/usr/local/nagios/libexec/目錄下)!!!!!

[root@localhost libexec]# ./check_nt -H 10.40.0.208 -p 12489 -v UPTIME -s 123123

System Uptime - 0 day(s) 7 hour(s) 38 minute(s) |uptime=458


[[email protected] /usr/local/nagios/libexec]# ./check_nt -H 10.40.0.226 -p 12489 -v USERDDISKSPACE -w 80 -c 90 -l C


4、實現通過web訪問界面查看監控對象信息的方法。

a、配置command.cfg文件,將監控中使用的命令寫進去

define command {

        command_name check_nt

        command_line    $USER1$/check_nt -H $HOSTNAME$ -p 12489 -s 123123 -v $ARG1$ $ARG2$ 

}

b、配置windows.cfg文件,將監控對象的信息錄入到host_name位置,同時錄入相關的“服務”信息

define host{

use windows-server ; Inherit default values from a template

host_name dtedu ; The name we're giving to this host

alias My Windows Server ; A longer name associated with the host

address 10.40.0.225 ; IP address of the host

}

define hostgroup{

hostgroup_name windows-servers ; The name of the hostgroup

alias Windows Servers ; Long name of the group

}


c、編輯主配置文件nagios.cfg,並啓用windows.cfg文件

# Definitions for monitoring a Windows machine

cfg_file=/etc/nagios/objects/windows.cfg



5、檢查配置文件語法錯誤

[root@localhost libexec]# /usr/local/nagios/bin/nagios -v /etc/nagios//nagios.cfg 


Nagios Core 3.4.3

Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors

Copyright (c) 1999-2009 Ethan Galstad

Last Modified: 11-30-2012

License: GPL


Website: http://www.nagios.org

Reading configuration data...

   Read main config file okay...

Processing object config file '/etc/nagios/objects/commands.cfg'...

Processing object config file '/etc/nagios/objects/contacts.cfg'...

Processing object config file '/etc/nagios/objects/timeperiods.cfg'...

Processing object config file '/etc/nagios/objects/templates.cfg'...

Processing object config file '/etc/nagios/objects/localhost.cfg'...

   Read object config files okay...


Running pre-flight check on configuration data...


Checking services...

Checked 8 services.

Checking hosts...

Checked 1 hosts.

Checking host groups...

Checked 1 host groups.

Checking service groups...

Checked 0 service groups.

Checking contacts...

Checked 1 contacts.

Checking contact groups...

Checked 1 contact groups.

Checking service escalations...

Checked 0 service escalations.

Checking service dependencies...

Checked 0 service dependencies.

Checking host escalations...

Checked 0 host escalations.

Checking host dependencies...

Checked 0 host dependencies.

Checking commands...

Checked 24 commands.

Checking time periods...

Checked 5 time periods.

Checking for circular paths between hosts...

Checking for circular host and service dependencies...

Checking global event handlers...

Checking obsessive compulsive processor commands...

Checking misc settings...


Total Warnings: 0

Total Errors:   0


2、check_nrpe通信模式(linux系統)

要求:服務器端安裝nrpe插件、客戶端安裝nagios-plugins、nsclient++、nrpe插件。


NRPE是用於在遠端服務器上運行檢測命令的守護進程,他用於讓nagios監控端基於安裝的方式觸發遠端主機上的檢測命令。並將結果輸出到監控端,而其執行的開銷遠低於ssh的檢測方式,而且檢測過程並不需要遠程主機上的賬戶信息。



1、安裝並配置被監控端

a、確保開發包組已經安裝,“development tools” “development libraries”

b、創建nagios用戶。

BingGongtekiMacBook-Pro:~ binggong$ useradd -s /sbin/nologin nagios


c、安裝nagios-plugins。

BingGongtekiMacBook-Pro:~ binggong$ ./configure --with-nagios-user=nagios --with-nagios-group=nagios

BingGongtekiMacBook-Pro:~ binggong$ make  all && make install


d、安裝nrpe插件 https://sourceforge.net/projects/nagios/files/

BingGongtekiMacBook-Pro:~ binggong$ ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl && make all && make install-plugin && make install-daemon && make install-daemon-config —sysconfdir=/etc


e、編輯配置文件,位置通常在/usr/local/nagios/etc/nrpe.cfg,我測試的版本nrpe-2.15需要將server_address=127.0.0.1註釋掉並重啓。

f、nagios-3.4.3.tar.gznagios-plugins-2.1.1.tar.gznagios-4.1.1.tar.gznrpe-2.15.tar.gz


g、設置開機啓動和service啓動方式配置啓動方案,可以通過創建/etc/init.d/目錄下的配置文件完成一個獨立的守護進程的方式,也可以通過基於xinetd的非獨立守護進程方式。

手動方式(以守護進程方式啓動):

[root@localhost bin]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg  -d



非獨立(在xinetd目錄下創建nrpe文件,使其成爲一個基於非獨立守護進程的服務,此情況啓動服務需要重啓xinetd服務):


[root@localhost bin]# vi /etc/xinetd.d/nrpe 


service nrpe

{

        flags = reuse

        socket_type = stream

        vait = no

        user = nagios

        group = nagios

        server = /opt/nagios/nrpe.cfg -l

        log_on_failure += USERID

        disable = no

}


獨立方式(在init.d目錄下創建啓動腳本實現獨立啓動一個單獨的服務進程):

[root@localhost bin]# chkconfig --add nrpe

[root@localhost bin]# chkconfig --level 35 nrpe on

[root@localhost bin]# chkconfig --list nrpe

nrpe            0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉


#!/bin/bash

#chkconfig: 2345 88 12

#description:nrpe daemon


NRPE=/usr/local/nagios/bin/nrpe

NRPECONF=/usr/local/nagios/etc/nrpe.cfg


case "$1" in

        start)

                echo -n "Starting NREP daemon"

                $NRPE -c $NRPECONF -d

                echo "done"

                ;;

        stop)

                echo -n "stopping NRPE DAEMON"

                pkill -u nagios nrpe

                echo "done"

                ;;

        restart)

                $0 stop

                sleep 2

                $0 start

                ;;

exit 0



3、check_nrpe通信模式(windows系統)

同樣需要安裝nsclients++插件,並且需要配置c:/program file/nsclients++/nsclient-full.ini。

講解:http://edu.51cto.com/lesson/id-11472.html


2、服務器端設置

a、安裝nrpe,配置同客戶端。

BingGongtekiMacBook-Pro:~ binggong$ ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl && make all && make install-plugin 


b、

c、安裝完畢後默認在/usr/local/nagios/libexec/目錄下生成check_nrpe命令。

d、檢測客戶端連通性

[root@5 libexec]# ./check_nrpe -H 10.40.0.57

NRPE v2.15


e、配置文件視頻http://edu.51cto.com/lesson/id-11471.html

在comand.cfg中添加一條check_nrpe命令

define command{

        command_name check_nrpe

        command_line $USER1$/check_nrpe -H $HOSTNAME$ -c $ARG1$

        }


創建一個新的主機配置文件10.40.0.226.cfg

define service{

        use                     generic-service

        host_name               linux001

        service_description     CHECK_users

        check_command           check_nrpe!check_users

        }

define service{

        use                     generic-service

        host_name               linux001

        service_description     load

        check_command           check_nrpe!check_load

        }

define service{

        use                     generic-service

        host_name               linux001

        service_description     CHECK_hda

        check_command           check_nrpe!check_hda1

        }

define service{

        use                     generic-service

        host_name               linux001

        service_description     CHECK_zombie——procs

        check_command           check_nrpe!check_zombie_procs

        }

define service{

        use                     generic-service

        host_name               linux001

        service_description     CHECK_total-procs

        check_command           check_nrpe!check_total_procs

        }

其中的check_users要同客戶端的配置對於。

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10

command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z

command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 


將主機配置文件添加到nagios.cfg文件中(服務器端)

# You can specify individual object config files as shown below:

cfg_file=/etc/nagios/objects/commands.cfg

cfg_file=/etc/nagios/objects/contacts.cfg

cfg_file=/etc/nagios/objects/timeperiods.cfg

cfg_file=/etc/nagios/objects/templates.cfg

cfg_file=/etc/nagios/objects/10.40.0.226.cfg


# Definitions for monitoring the local (Linux) host

cfg_file=/etc/nagios/objects/localhost.cfg


監控http服務啓動狀態。check_http

監控mysql服務啓動狀態,check_mysql -u $arg1$ -p $arg2$

錯誤總結:

[[email protected] ~]#  /usr/local/nagios/libexec/check_mysql -H 10.40.0.227 -u root -p root

/usr/local/nagios/libexec/check_mysql: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory


安裝libmysqlclient.so.18文件。(未成功)

下載位置:https://altlinux.pkgs.org/sisyphus/classic-i586/libmysqlclient18-10.1.23-alt1.S1.i586.rpm.html

4、NSCA方式被動監測:

1、需要在服務器端的“服務”腳本中添加以下選項:

define host{

active_check_enabled 0

passive_checks_enabled 1

}

define service{

active_check_enabled 0

passive_checks_enabled 1

}

2、服務器端的需要啓動nsca的服務

3、需要設置“模板”腳本

相關網頁:http://os.51cto.com/art/201409/452605.htm

nagios插件下載地址:http://exchange.nagios.org/

nagios在線中文幫助文檔:http://nagios-cn.sourceforge.net/nagios-cn/


八、告警通知機制

nagios告警通知的配置涉及到模板、服務、contact腳本,總的來說,他們之間是由關聯的而關聯的最終結果是在contact.cfg文件上。contact.cfg文件中定義的admins,最終會在服務、模板腳本中使用,所以,只要在contact中定義通知郵箱或飛信即可完成通知功能。


define contact{

        contact_name                    nagiosadmin             ; Short name of user

        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)

        alias                           Nagios Admin            ; Full name of user


        email                           nagios@localhost        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

        }

define contactgroup{

        contactgroup_name       admins

        alias                   Nagios Administrators

        members                 nagiosadmin

        }

~                  


define contact{

        name                            generic-contact         ; The name of this contact template

        service_notification_period     24x7                    ; service notifications can be sent anytime

        host_notification_period        24x7                    ; host notifications can be sent anytime

        service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events

        host_notification_options       d,u,r,f,s               ; send notifications for all host states, flapping events, and scheduled downtime events

        service_notification_commands   notify-service-by-email ; send service notifications via email

        host_notification_commands      notify-host-by-email    ; send host notifications via email

        register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!

        }

define host{

        name                            linux-server    ; The name of this host template

        use                             generic-host    ; This template inherits other values from the generic-host template

        check_period                    24x7            ; By default, Linux hosts are checked round the clock

        check_interval                  5               ; Actively check the host every 5 minutes

        retry_interval                  1               ; Schedule host check retries at 1 minute intervals

        max_check_attempts              10              ; Check each Linux host 10 times (max)

        check_command                   check-host-alive ; Default command to check Linux hosts

        notification_period             workhours       ; Linux admins hate to be woken up, so we only notify during the day

                                                        ; Note that the notification_period variable is being overridden from

                                                        ; the value that is inherited from the generic-host template!

        notification_interval           120             ; Resend notifications every 2 hours

        notification_options            d,u,r           ; Only send notifications for specific host states

        contact_groups                  admins          ; Notifications get sent to the admins by default

        register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!


        }


define command{

        command_name    notify-host-by-email

        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$

        }


# 'notify-service-by-email' command definition

define command{

        command_name    notify-service-by-email

        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

        }

飛信通知方式可以下載飛信機器人,這裏就不再講解了。


九、常見問題:


1、服務器連接不上被監控端,比如telnet 10.40.0.37 5666 被拒絕。

處理辦法:查看netstat -tunlp 發現5666端口的ip地址對應的是本機127.0.0.1。

tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      2946/nrpe           

所以只允許本地監控、訪問。解決方法

    就是把nrpe.cfg裏面的

server_address=127.0.0.1
註釋掉,重啓就可以


2、nagios基本流程是什麼

創建主機的配置文件,一個主機一個配置文件,然後將主機配置文件路徑添加到nagios.cfg文件中。

通過命令配置文件修改對應主機配置文件中的service模塊。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章