UBUNTU9.10
安装nagios监控软件实现手机短信通知
1. 安装nagios相关软件包,
apt-get install apache2
apt-get install libapache2-mod-php5
apt-get install build-essential
apt-get install libgd2-xpm-dev
apt-get install php5
2. 建立nagios相关账号和组
/usr/sbin/useradd useradd -m -s /bin/bash nagios
passwd nagios
groupadd nagios
usermod -G nagios nagios
#添加nagcmd组并将nagios和apache用户添加到组中,支持通过Web接口提交外部命令
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd www-data
3. 安装nagios
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.0.tar.gz
tar zxvf nagios-3.2.0.tar.gz
cd nagios-3.2.0
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
#配置nagios的配置文件/usr/local/nagios/etc/objects/contacts.cfg,设置正确的邮件账号。
2. 建立nagios相关账号和组
/usr/sbin/useradd useradd -m -s /bin/bash nagios
passwd nagios
groupadd nagios
usermod -G nagios nagios
#添加nagcmd组并将nagios和apache用户添加到组中,支持通过Web接口提交外部命令
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd www-data
3. 安装nagios
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.0.tar.gz
tar zxvf nagios-3.2.0.tar.gz
cd nagios-3.2.0
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
#配置nagios的配置文件/usr/local/nagios/etc/objects/contacts.cfg,设置正确的邮件账号。
4. 配置Web接口
make install-webconf
#创建用于登陆nagios页面的账号和密码
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#重启apache使设置生效
/etc/init.d/apache2 reload
5. 安装nagios插件
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
tar zxvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
6. 启动nagios
#设置nagios随系统启动
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
#检查配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios start
7. 登陆nagios管理页面
登陆地址为:http://ip/nagios,用户名及密码为nagiosadmin及其密码。
9. 使用sendEmail并结合139.COM免费邮箱来实现手机短信通知
首先我们当要申请一个139.com的邮箱: http://mail.10086.cn/
make install-webconf
#创建用于登陆nagios页面的账号和密码
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#重启apache使设置生效
/etc/init.d/apache2 reload
5. 安装nagios插件
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
tar zxvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
6. 启动nagios
#设置nagios随系统启动
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
#检查配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios start
7. 登陆nagios管理页面
登陆地址为:http://ip/nagios,用户名及密码为nagiosadmin及其密码。
9. 使用sendEmail并结合139.COM免费邮箱来实现手机短信通知
首先我们当要申请一个139.com的邮箱: http://mail.10086.cn/
这里邮件服务器的地址为
smtp.139.com
用来发邮件的帐号
手机号@139.com
SMTP验证的用户名:手机号(15****32556)
密码:申请邮箱时的密码(aaa1234)
以下就来介绍一下sendEmail这个软件的使用.
sendEmail的主页
http://caspian.dotconf.net/menu/Software/SendEmail/
下载最新版 wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
安装方法:
1) Extract the package
tar -zxvf sendEmail-v1.XX.tar.gz
2) Copy the sendEmail script to /usr/local/bin
cp -a sendEmail-v1.XX/sendEmail /usr/local/bin
3) Make sure its executable
chmod +x /usr/local/bin/sendEmail
4) Run it
sendEmail
or
/usr/local/bin/sendEmail
安装方法:
1) Extract the package
tar -zxvf sendEmail-v1.XX.tar.gz
2) Copy the sendEmail script to /usr/local/bin
cp -a sendEmail-v1.XX/sendEmail /usr/local/bin
3) Make sure its executable
chmod +x /usr/local/bin/sendEmail
4) Run it
sendEmail
or
/usr/local/bin/sendEmail
先看一个典型的例子
/usr/local/bin/sendEmail –f 15****32556@139.com
–t 15****32556@139.com
–s smtp.139.com
–u “from nagios” –xu 15****32556@139.com
–xp aaa1234
–m happy
解释:
-f 表示发送者的邮箱
-t 表示接收者的邮箱
-s 表示SMTP服务器的域名或者ip
-u 表示邮件的主题
-xu 表示SMTP验证的用户名
-xp 表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
-m 表示邮件的内容
如果你不带-m参数的话,就会提示你自行输入
Reading message body from STDIN because the ‘-m’ option was not used.
If you are manually typing in a message:
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line
|
输入完成后使用CTRL-D来结束
当然我们也可以将一个文件的内容作为邮件的正文发出去的
那么就可以使用:
cat
文件名
| /usr/local/bin/sendEmail –f 15****32556@139.com
–t 15****32556@139.com
–s smtp.139.com
–u “from nagios” –xu 15****32556@139.com
–xp aaa1234
有关sendEmail的用法就讲到这里
既然nagios要使用sendEmail来发警告邮件,那么就要修改commands.cfg中关于发邮件的命令的定义,我们现在来修改notify-by-email这个命令,如下(注意其中粗体的部分)
# 'notify-by-email' command definition
define command{
command_name notify-by-email
command_line /usr/bin/printf "%b" "***** Nagios 2.9 *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" |
/usr/local/bin/sendEmail –f 15****32556@139.com
–t
$CONTACTEMAIL$
–s smtp.139.com
–u
-u "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **"
–xu 15****32556@139.com
–xp aaa1234
}
|
转载于:https://blog.51cto.com/neowlyz/379611