centreon安裝配置文檔

LAMP+Nagios+Ndoutils+Centreon 64位操做系統安裝php

LAMP安裝html


安裝yum 源python

1.rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpmmysql

2.rpm -ivh epel-release-5-4.noarch.rpmlinux

3.rpm -ivh remi-release-5-8.el5.remi.noarch.rpmios


yum安裝: c++

#yum install httpd web

#yum install mysql mysql-server mysql-devel openssl-devel perl-DBD-MySQL sql

#yum install php php-mysql php-gd 數據庫


yum install sysstat (安裝iostat)

部分軟件包安裝

安裝 PHP附屬包:

#yum install php-pear php-snmp php-common php-ldap php-xml php-gd php-mbstring


安裝PERl包:

#yum install perl-DBI perl-Config-IniFiles perl-Crypt-DES perl-Digest-HMAC perl-Digest-SHA1 perl-GD perl-IO-Socket-INET6 perl-Net-SNMP perl-rrdtool perl-Socket6 perl-Config-IniFiles


安裝GD Modules:

#yum install gd gd-devel


安裝其他軟件包:

#yum install libpng-devel dmidecode lm_sensors libpng zlib freetype cairo pango libxml2 fontconfig fping graphviz gcc-c++ glib2-devel

Yum install glib

Yum install fping

Yum install graphviz.x86_64


以上軟件包若是本機中未能自帶,請登陸http://rpm.pbone.net/ 上自行下載。

(當須要安裝librrd.so.2()(64bit時,下載zenoss-2.3.3.el5.x86_64.rpm

安裝RRDTOOL:

rpm -e rrdtool-1.4.7-1.el5.rf.x86_64 perl-rrdtool-1.4.7-1.el5.rf.x86_64


#rpm –ivh rrdtool-1.2.19-1.el5.kb.x86_64.rpm

#rpm –ivh rrdtool-devel-1.2.19-1.el5.kb.x86_64.rpm

#rpm –ivh rrdtool-doc-1.2.19-1.el5.kb.x86_64.rpm

#rpm –ivh rrdtool-perl-1.2.19-1.el5.kb.x86_64.rpm

#rpm –ivh rrdtool-php-1.2.19-1.el5.kb.x86_64.rpm

#rpm –ivh rrdtool-python-1.2.19-1.el5.kb.x86_64.rpm

#rpm –ivh rrdtool-tcl-1.2.19-1.el5.kb.x86_64.rpm


安裝PEAR模塊:

由於以前已經安裝過php-pear包,pear的主目錄已經產生,可是Centreon還須要加載一些pear模塊才能工做。


pear upgrade --force http://pear.php.net/get/PEAR-1.9.0


#pear install Archive_Tar Auth_SASL Console_Getopt Date DB DB_DataObject DB_DataObject_FormBuilder HTML_Common HTML_QuickForm_advmultiselect HTML_QuickForm_ElementGrid HTML_Table HTML_QuickForm HTTP HTTP_Request Image_Canvas Image_Color Image_Graph Image_GraphViz Log Mail Mail_Mime Math_BigInteger MDB2 Net_DIME Net_IDNA Net_Ping Net_SMTP Net_Socket Net_Traceroute Net_URL Numbers_Roman Numbers_Words SOAP Structures_Graph Validate XML_RPC


#pear list ------ 查看安裝了哪些模塊

pear install channel://pear.php.net/Image_Canvas-0.3.5

pear install channel://pear.php.net/Image_Graph-0.8.0

pear install channel://pear.php.net/Numbers_Words-0.16.4

pear install channel://pear.php.net/SOAP-0.13.0

pear install channel://pear.php.net/Validate-0.8.5

pear install channel://pear.php.net/HTML_QuickForm_ElementGrid-0.1.2

pear install channel://pear.php.net/NET_IDNA-0.8.1

pear install channel://pear.php.net/Net_Traceroute-0.21.3


安裝SNMP:

#yum install net-snmp net-snmp-utils net-snmp-devel net-snmp-perl


配置SNMP:

#vim /etc/snmp/snmpd.conf 將x.x.x.x換成運行nagios服務器的IP地址:

com2sec notConfigUser x.x.x.x public

access notConfigGroup」」 any noauth exact all none none

view all included .1 80




安裝nagios Ndoutils安裝


=====================yum 安裝===================

yum install nagios nagios-plugins nagios-plugins-nrpe nagios-devel nagios-nrpe


安裝完的插件都在/usr/lib64/nagios/plugins下,之後centreon插件也會在這個目錄下。

輸入http://IP/nagios便可看到nagios監控界面

{

/usr/bin/htpasswd -c /etc/nagios/htpasswd.users nagios (如沒法登錄需設置用戶名密碼、用戶名或爲nagiosadmin)

設置密碼

sed -i 's/nagiosadmin/nagios/g' /etc/nagios/cgi.cfg 打開查看權限

service nagios restart

service httpd restart

service mysqld restart


#執行service nagios start操做能夠看到nagios監控的本機的狀態

(nagios目錄:/etc/nagios/

插件目錄:/usr/lib64/nagios/plugins

給nagios用戶開權限,讓他可以查看信息!

# vim /usr/local/nagios/etc/cgi.cfg

在全部的nagiosadmin後面添加nagios

/etc/init.d/nrpe start)

} //{}中內容能夠不配置

Ndoutils安裝

#tar -zxf ndoutils-1.4b9.tar.gz

#cd ndoutils-1.4b9

#./configure --prefix=/usr/local/nagios/ \

--enable-mysql \

--disable-pgsql \

--with-ndo2db-user=nagios \

--with-ndo2db-group=nagios

#make

#make install

Cd config

Copy ndo2db.cfg-sample to /etc/nagios/ndo2db.cfg


Centreon安裝

#每一步都要看好要安裝的東西以及目錄,安裝目錄默認的就選默認就行了,有的須要本身指定目錄:RRDs,PEAR.php,ndomod.o

#find / -name RRDs.pm

/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/RRDs.pm

#find / -name PEAR.php

/usr/share/pear/PEAR.php

/usr/lib64/nagios

/etc/nagios

/var/nagios

#find / -name ndomod.o

/usr/local/nagios/bin/ndomod.o


#tar -zxf centreon-2.1.9.tar.gz

#cd centreon-2.1.9

#./install.sh -i

###############################################################################

#          #

#    Centreon (www.centreon.com)    #

#    Thanks for using Centreon    #

#          #

#     v2.2     #

#          #

#    infos@centreon.com    #

#          #

#   Make sure you have installed and configured  #

#   sudo - sed - php - apache - rrdtool - mysql  #

#          #

###############################################################################

------------------------------------------------------------------------

Checking all needed binaries

------------------------------------------------------------------------

rm        OK

cp        OK

mv        OK

/bin/chmod       OK

/bin/chown       OK

echo       OK

more       OK

mkdir       OK

find       OK

/bin/grep       OK

/bin/cat       OK

/bin/sed       OK


You will now read Centreon Licence.

Press enter to continue.

GNU GENERAL PUBLIC LICENSE

Version 2, June 1991

........................................................................................



Do you accept GPL license ?

[y/n], default to [n]:

> y

------------------------------------------------------------------------

Please choose what you want to install

------------------------------------------------------------------------


Do you want to install : Centreon Web Front

[y/n], default to [n]:

> y


Do you want to install : Centreon CentCore

[y/n], default to [n]:

> y


Do you want to install : Centreon Nagios Plugins

[y/n], default to [n]:

> y


Do you want to install : Centreon Snmp Traps process

[y/n], default to [n]:

> y


------------------------------------------------------------------------

Start CentWeb Installation

------------------------------------------------------------------------


Where is your Centreon directory?

default to [/usr/local/centreon]

>


Do you want me to create this directory ? [/usr/local/centreon]

[y/n], default to [n]:

> y

Path /usr/local/centreon     OK


Where is your Centreon log directory

default to [/usr/local/centreon/log]

>


Do you want me to create this directory ? [/usr/local/centreon/log]

[y/n], default to [n]:

> y

Path /usr/local/centreon/log    OK


Where is your Centreon etc directory

default to [/etc/centreon]

>

Path /etc/centreon      OK


Where is your Centreon generation_files directory?

default to [/usr/local/centreon]

>

Path /usr/local/centreon     OK


Where is your Centreon variable library directory?

default to [/var/lib/centreon]

>

Path /var/lib/centreon     OK


Where is your CentPlugins Traps binary

default to [/usr/local/centreon/bin]

>


Do you want me to create this directory ? [/usr/local/centreon/bin]

[y/n], default to [n]:

> y

Path /usr/local/centreon/bin    OK


Where is the RRD perl module installed [RRDs.pm]

default to [/usr/lib/perl5/RRDs.pm]

> /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/RRDs.pm

Path /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-threadOKulti

/usr/bin/rrdtool      OK

/bin/mail       OK


Where is PEAR [PEAR.php]

default to [/usr/share/php/PEAR.php]

> /usr/share/pear/PEAR.php

Path /usr/share/pear     OK


Where is installed Nagios ?

default to [/usr/local/nagios]

> /usr/lib64/nagios

Path /usr/lib64/nagios     OK


Where is your nagios config directory

default to [/usr/local/nagios/etc]

> /etc/nagios

Path /etc/nagios      OK


Where is your Nagios var directory ?

default to [/usr/local/nagios/var]

> /var/nagios

Path /var/nagios      OK


Where is your Nagios plugins (libexec) directory ?

default to [/usr/local/nagios/libexec]

> /usr/lib64/nagios/plugins

Path /usr/lib64/nagios/plugins    OK

/usr/bin/nagios      OK


Where is your Nagios p_w_picpath directory ?

default to [/usr/local/nagios/share/p_w_picpaths/logos]

> /usr/share/nagios/p_w_picpaths/logos

Path /usr/share/nagios/p_w_picpaths/logos   OK

/usr/bin/nagiostats     OK

p1_file : /usr/bin/p1.pl     OK

/usr/bin/php      OK

/usr/bin/perl      OK

Finding Apache group :     apache

Finding Apache user :     apache

Finding Nagios user :     nagios

Finding Nagios group :     nagios


Where is your NDO ndomod binary ?

default to [/usr/sbin/ndomod.o]

> /usr/local/nagios/bin/ndomod.o

/usr/local/nagios/bin/ndomod.o    OK


------------------------------------------------------------------------

Configure Sudo

------------------------------------------------------------------------


Where is sudo configuration file

default to [/etc/sudoers]

>

/etc/sudoers      OK

Nagios init script      OK

Your sudo has been configured previously


Do you want me to reconfigure your sudo ? (WARNING)

[y/n], default to [n]:

> y

Configuring Sudo      OK


------------------------------------------------------------------------

Configure Apache server

------------------------------------------------------------------------

Finding Apache Centreon configuration file

'/etc/httpd/conf.d/centreon.conf' :   OK


Do you want to update Centreon Apache sub configuration file ?

[y/n], default to [n]:

> y

Backup Centreon Apache configuration completed

Create '/etc/httpd/conf.d/centreon.conf'   OK

Configuring Apache      OK


Do you want to reload your Apache ?

[y/n], default to [n]:

> y

Reloading Apache service     OK

Preparing Centreon temporary files

Change right on /usr/local/centreon/log   OK

Change right on /etc/centreon    OK

Change right on /usr/share/nagios/p_w_picpaths/logos  OK

Install nagios documentation    OK

Change macros for insertBaseConf.sql   OK

Change macros for php files    OK

Change right on /etc/nagios    OK

Copy CentWeb in system directory

Install CentWeb (web front of centreon)   OK

Install libraries      OK

Copying libinstall      OK

Change macros for centreon.cron    OK

Install Centreon cron.d file    OK

Change macros for archiveDayLog    OK

Change macros for centAcl.php    OK

Install cron directory     OK


------------------------------------------------------------------------

Pear Modules

------------------------------------------------------------------------

Check PEAR modules

PEAR    1.4.9 1.9.4  OK

DB    1.7.6 1.7.14  OK

DB_DataObject   1.8.4 1.9.6  OK

DB_DataObject_FormBuilder 1.0.0RC4 1.0.1  OK

MDB2    2.0.0 2.4.1  OK

Date    1.4.6 1.4.7  OK

HTML_Common   1.2.2 1.2.5  OK

HTML_QuickForm   3.2.5 3.2.13  OK

HTML_QuickForm_advmultiselect 1.1.0 1.5.1  OK

HTML_Table   1.6.1 1.8.3  OK

Archive_Tar   1.1  1.3.1  OK

Auth_SASL   1.0.1 1.0.6  OK

Console_Getopt   1.2  1.2  OK

Net_SMTP   1.2.8 1.6.1  OK

Net_Socket   1.0.1 1.0.10  OK

Net_Traceroute   0.21 0.21.3  OK

Net_Ping   2.4.1 2.4.5  OK

Validate   0.6.2 0.8.4  OK

XML_RPC    1.4.5 1.5.0  OK

SOAP    0.10.1 0.12.0  OK

Log    1.9.11 1.12.7  OK

All PEAR modules      OK


------------------------------------------------------------------------

Centreon Post Install

------------------------------------------------------------------------

Create /usr/local/centreon/www/install/install.conf.php OK

Create /etc/centreon/instCentWeb.conf   OK


------------------------------------------------------------------------

Start CentStorage Installation

------------------------------------------------------------------------


Where is your Centreon Run Dir directory?

default to [/var/run/centreon]

>

Path /var/run/centreon     OK


Where is your CentStorage binary directory

default to [/usr/local/centreon/bin]

>

Path /usr/local/centreon/bin    OK


Where is your CentStorage RRD directory

default to [/var/lib/centreon]

>

Path /var/lib/centreon     OK

Finding Nagios group :     nagios

Finding Nagios user :     nagios

Preparing Centreon temporary files

/tmp/centreon-setup exists, it will be moved...

install www/install/createTablesCentstorage.sql  OK

CentStorage status Directory already exists  PASSED

CentStorage metrics Directory already exists  PASSED

Change macros for centstorage binary   OK

Install CentStorage binary     OK

Install library for centstorage    OK

Change right : /var/run/centreon    OK

Change macros for centstorage init script   OK


Do you want me to install CentStorage init script ?

[y/n], default to [n]:

> y

CentStorage init script installed    OK


Do you want me to install CentStorage run level ?

[y/n], default to [n]:

> y

Change macros for logAnalyser    OK

Install logAnalyser     OK

Change macros for nagiosPerfTrace    OK

Install nagiosPerfTrace     OK

Change macros for purgeLogs    OK

Install purgeLogs      OK

Change macros for purgeCentstorage    OK

Install purgeCentstorage     OK

Change macros for centreonPurge.sh    OK

Install centreonPurge.sh     OK

Change macros for centstorage.cron    OK

Install CentStorage cron     OK

Create /etc/centreon/instCentStorage.conf   OK


------------------------------------------------------------------------

Start CentCore Installation

------------------------------------------------------------------------


Where is your CentCore binary directory

default to [/usr/local/centreon/bin]

>

Path /usr/local/centreon/bin    OK

/usr/bin/ssh      OK

/usr/bin/scp      OK

Finding Nagios group :     nagios

Finding Nagios user :     nagios

Preparing Centreon temporary files

/tmp/centreon-setup exists, it will be moved...

Change CentCore Macro     OK

Copy CentCore in binary directory    OK

Change right : /var/run/centreon    OK

Change right : /var/lib/centreon    OK

Replace CentCore init script Macro    OK


Do you want me to install CentCore init script ?

[y/n], default to [n]:

> y

CentCore init script installed    OK


Do you want me to install CentCore run level ?

[y/n], default to [n]:

> y

Create /etc/centreon/instCentCore.conf   OK


------------------------------------------------------------------------

Start CentPlugins Installation

------------------------------------------------------------------------


Where is your CentPlugins lib directory

default to [/var/lib/centreon/centplugins]

>

Path /var/lib/centreon/centplugins    OK

Finding Nagios user :     nagios

Finding Nagios group :     nagios

Preparing Centreon temporary files

/tmp/centreon-setup exists, it will be moved...

Change macros for CentPlugins    OK

Installing the plugins     OK

Change right on centreon.conf    OK

CentPlugins is installed


------------------------------------------------------------------------

Start CentPlugins Traps Installation

------------------------------------------------------------------------


Where is your SNMP configuration directory

default to [/etc/snmp]

>

/etc/snmp       OK


Where is your SNMPTT binaries directory

default to [/usr/local/centreon/bin/]

>

/usr/local/centreon/bin/     OK

Finding Nagios group :     nagios

Finding Apache user :     apache

Preparing Centreon temporary files

/tmp/centreon-setup exists, it will be moved...

Change macros for CentPluginsTraps    OK

Installing the plugins Trap binaries   OK

Change macros for snmptrapd.conf    OK

Change macros for snmptt.ini    OK

Install : snmptrapd.conf     OK

Install : snmp.conf     OK

Install : snmptt.ini     OK

Install : snmptt      OK

Install : snmpttconvertmib     OK

Generate SNMPTT configuration    FAIL

Create /etc/centreon/instCentPlugins.conf   OK

###############################################################################

#          #

#   Go to the URL : http://localhost.localdomain/centreon/   #

#   to finish the setup    #

#          #

#   Report bugs at http://forge.centreon.com   #

#          #

#    Thanks for using Centreon.    #

#    -----------------------    #

#   Contact : infos@centreon.com    #

#    http://www.centreon.com    #

#          #

##############################################################################


Centreon安裝完成後,你能夠經過http://yourServerIPAddress/centreon來訪問。

#安裝後在網址中輸入http://IP/centreon 進入Centreon web 配置界面

105406251.png

105408902.png

105411471.png

105413801.png

105415683.png

#填寫mysql數據庫訪問密碼,填寫ndo的用戶及密碼,默認數據庫root密碼爲空

105417677.png

105420423.png


#建立centreon登陸時的帳號和密碼

#登陸後的界面

#安裝完成

C、配置cgi.cfg

105624349.jpg

105627247.jpg

D、應用更改

105716748.jpg

參考:http://www.linuxidc.com/Linux/2011-04/34031p2.htm

出現問題:

一、不顯示主機列表

ps aux | grep ndo2db

啓動ndo2db服務

locate ndo2db

/usr/local/nagios/bin/ndo2db -c /etc/nagios/ndo2db.cfg

參考:

http://wenku.baidu.com/view/98ba2b1752d380eb62946dd0.html

二、不能顯示服務和主機數量

105811933.png

==========

Ubuntu 客戶端安裝 (remote server installation and setup)

#sudo apt-get install nagios-nrpe-server nagios-nrpe-plugin

#sudo vi /etc/nagios/nrpe.cfg (in the following)


Append the Nagios server ip in the following

allowed_hosts=127.0.0.1,your-nagios-server-ip

allowed_hosts=127.0.0.1,192.168.10.247,192.168.10.201

重啓nrpe

#ps aux | grep nrpe


#kill 「nrpe-process-id」

And start nrpe process as

/usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d

============

centos客戶端:

rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

rpm -ivh epel-release-5-4.noarch.rpm

rpm -ivh remi-release-5-8.el5.remi.noarch.rpm

yum install nagios-plugins nagios-plugins-nrpe nagios-nrpe –y

cd //usr/lib64/nagios/plugins/

vim /etc/nagios/nrpe.cfg

修改host_allow字段,添加監控機ip

/etc/init.d/nrpe restart


監控工做主要由nagios完成再經過ndo2db寫入數據庫最後由centreon調用顯示出來


啓動服務:

/etc/init.d/nrpe restart

/usr/local/nagios/bin/ndo2db -c /etc/nagios/ndo2db.cfg

/etc/init.d/httpd restart

/etc/init.d/nagios restart

/etc/init.d/centcore restart

/etc/init.d/centstorage restart




Centreon漢化

1.下載語言文件 # wget http://cacti-nagios.googlecode.com/files/messages.mo

2.建立語言目錄 # mkdir -p /usr/local/centreon/www/locale/zh_CN/LC_MESSAGES/

3.移勱下載的messages.mo至第2步建立的目錄 # mv messages.mo /usr/local/centreon/www/locale/zh_CN/LC_MESSAGES/

4.登陸centreon點擊administartors再點option迚入」my account」更改語言爲zh_CN保存便可。

======

centreon安裝失敗後的卸載

# rm -rf /usr/local/centreon

# rm -rf /etc/centreon

# rm -rf /etc/httpd/conf.d/centreon.conf

# rm -rf /var/lib/centreon



/usr/lib64/nagios/plugins/check_nrpe -H 192.168.18.181



爲10.201添加監控cpu命令步驟

一、下載監控腳本

cd /usr/lib64/nagios/plugins(監控端和被監控端都要有此腳本)

wget http://-------------------------------

chown nagios:nagios check_cpu.sh

chmod +x check_cpu.sh

二、 添加用戶

110405777.png

二、添加主機

110150461.png

(檢測命令要選中check_host_alive,不然會顯示主機爲down)


****四、增長服務

增長check_cpu 服務

110448716.png


使用check_nrpe 則不用在centreon中定義命令

定義check_nrpe命令:

配置-----命令-----增長

$USER1$/check_nrpe  -H  $HOSTADDRESS$ -c $ARG1$

wKioOVLEvFHCrPGvAAB6y-TtYcI084.jpg

check_cpu_load名字隨便定義

check_cpu_234則是監控端和被監控端的nrpe.cfg中command字段中定義。

五、關聯主機

配置——服務——關係


六、定義command字段

在監控端和被監控端都要編輯nrpe.cfg,定義命令,添加command字段

編輯:vim /etc/nagios/nrpe.cfg,添加command字段

command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10

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

command[check_disk_home]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /home

command[check_disk_sda2]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda2

command[check_disk_sda3]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda3

command[check_disk_sdb1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sdb1

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

command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200

command[check_memory]=/usr/lib64/nagios/plugins/check_memory.pl -f -w 30 -c 20

command[check_cpu_234]=/usr/lib64/nagios/plugins/check_cpu.sh -w 60 -c 80

command[check_http]=/usr/lib64/nagios/plugins/check_http -H $HOSTADDRESS$ -u $ARG1$ -w 5 -c 10

command[check_80]=/usr/lib64/nagios/plugins/check_tcp -H $HOSTADDRESS$ -p 80 -w 1 -c 5

command[check_iostat]=/usr/lib64/nagios/plugins/check_iostat -w 10 -c 20

command[check_nrpe]=/usr/lib64/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

監控端重啓nrpe

/etc/init.d/nrpe restart


被監控端重啓nrpe服務

ps aux | grep nrpe

kill 32162

/usr/sbin/nrpe -c /etc/nagios/nrpe.cfg –d

在被監控端測試腳本


在監控機上遠程測試


(注意:寫command字段和測試時,參數要寫正確)

七、激活配置,重啓服務

配置--->nagios

八、查看監控內容

九、mysql監控舉例:

監控端命令定義:

command[check_mysql_connect_time]=/usr/lib64/nagios/plugins/check_mysql_health -hostname $HOSTADDRESS$ -port $ARG1$ -username $ARG2$
-password $ARG3$ -mode connection-time -w 1 -c 5

被監控端命令定義:

command[check_mysql_connect_time]=/usr/lib64/nagios/plugins/check_mysql_health -hostname 127.0.0.1 -port 40238 -username eloancn -pas
sword eloancn158 -mode connection-time -w 1 -c 5

出現問題:

一、CHECK_NRPE: Socket timeout after 10 seconds.

解決方法:

測試NRPE daemon

netstat -ln |grep 5666

tcp 0 0 0.0.0.0:5666  0.0.0.0:*   LISTEN

修改防火牆規則,開放tcp 5666端口


配置短信報警通知:

一、安裝sendEmail

wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz

#tar -zxvf sendEmail-v1.56.tar.gz && cd sendEmail-v1.56

#cp sendEmail /usr/local/bin

#chmod 0755 /usr/local/bin/sendEmail

2. 發送郵件測試

# sendEmail -h  (查看sendMail幫助)

# sendEmail -f dba@lk.com -t encle@lk.com -s 28.4.15.18 -u "nagios測試" -m "nagios test 測試

或者將一個文件的內容做爲附件發出, 而且是gb2312或utf8編碼的html格式文件(能夠顯示中文):

#sendEmail -f dba@lk.com -t encle@lk.com -s 28.4.15.18 -u "nagios測試" -m "pls see the attachement附件" -a /var/log/messages -o message-content-type=html -o message-charset=gb2312

若是測試報錯:

110946823.png

則後面須要加上-xu –xp參數:

111001673.png

各參數含義以下:

-f 表示發送者的郵箱, 可隨意設置 -t 表示接收者的郵箱

-s 表示SMTP服務器的域名或者IP -u 表示郵件的主題 -m 表示郵件的內容

-xu 表示SMTP驗證的用戶名, 若是SMTP服務器須要驗證的話就加上該參數, 通常發給外網用戶則須要

-xp 表示SMTP驗證的密碼, 若是SMTP服務器須要驗證的話就加上該參數, 通常發給外網用戶則須要

三、在聯繫人用戶裏,就能夠定義。


四、定義郵件發送命令:

配置--------命令----------通知


就在下面的「通知」裏,結尾是email的是郵件發送命令。host是主機的報警和恢復,service是服務的報警和恢復。


以host那條命令爲例說明

/usr/bin/printf "%b" "Host: $HOSTNAME$<br>Notification:

$HOSTNOTIFICATIONNUMBER$<br>Command: $HOSTCHECKCOMMAND$<br>Datetime: $LONGDATETIME$<br><br>Info: $HOSTOUTPUT$<br>$LONGHOSTOUTPUT$"

| /usr/local/bin/sendEmail -f jiankong@XXXX.com -t $CONTACTEMAIL$ -s smtp.XXXX.com -xu jiankong@XXXX.com -xp jk@XXXX -u "Host $HOSTSTATE$: $HOSTADDRESS$" -o message-content-type=html -o message-charset=utf8

主要是打紅的地方調用發郵件的命令,路徑是sendEmail命令,-f是發件人地址,-t是收件人地址,這裏是個變量,已經定義了,就是以前那個聯繫人裏填的,-s是郵件服務器地址,也能夠填域名,-xu是郵箱帳號,-xp是郵箱密碼。其餘的都是些郵件內容的定義,因此能夠不用改。-o

message-content-type=html -o message-charset=utf8這段是防止中文亂碼的。

111202874.png

下面這段是原來沒作任何更改的命令行,供參考。

/usr/bin/printf "%b" "***** centreon Notification

*****\n\nType:$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState:

$HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\nDate/Time: $DATE$" | @MAILER@ -s "Host $HOSTSTATE$ alert for $HOSTNAME$!" $CONTACTEMAIL$


下面這段是服務的。

/usr/bin/printf "%b" "Host: $HOSTALIAS$<br>NotifyTimes: $SERVICENOTIFICATIONNUMBER$<br>Command:

$SERVICECHECKCOMMAND$<br>Datetime: $LONGDATETIME$<br><br>Additional

Info:<br>$SERVICEOUTPUT$<br>$LONGSERVICEOUTPUT$" | /usr/local/bin/sendEmail -f jiankong@XXXX.com -t $CONTACTEMAIL$ -s smtp.XXXX.com -xu jiankong@XXXX.com -xp jk@XXXX -u "Service $SERVICESTATE$: $HOSTADDRESS$ | $SERVICEDESC$" -o message-content-type=html -o message-charset=utf8

改完以後保存,別忘了導出文件和重啓nagios,讓其生效。

到這裏,咱們的報警郵件就能夠正常發出了。



爲了防止單搞nagios的由於發不出郵件而頭疼,這裏提一下,若是按照大衆版sendmail作法,那你須要在/etc/mail裏面找到個access文件,裏面須要添加你要發郵件的域。

好比qq郵箱,要添加qq.com進去。

111259230.png

============

說明:「配置短信報警通知」這一塊能夠不配置,centos服務器默認有sendmail,只要在定義聯繫人的時候寫好郵箱,主機和服務通知欄中分別選中:host-notify-by-email和service-notify-by-email即能發送郵件報警,使用139郵箱能夠短信通知。

監控界面以下:

112602398.png

相關文章
相關標籤/搜索