Nagios Gmail Server sub

Hướng dẫn gửi thông báo bằng Nagios Gmail Server

Nagios Gmail Server là gì?

Nagios Gmail Server là việc sử dụng tài khoản gmail của google để gửi thông báo khi server gặp bất cứ vấn đề gì.

Trong bài viết trước mình đã giới thiệu cách cài đặt giám sát các linux host. Trong bài viết này, mình sẽ hướng dẫn các bạn cách thiết lập cho Nagios gửi thông báo bằng tài khoản Gmail.

Hướng dẫn cài đặt server Nagios Monitoring Server.

1. Cài đặt các thư viện cần thiết.

apt-get install libio-socket-ssl-perl libnet-ssleay-perl perl
apt-get install 'perl(Net::SSLeay)' 'perl(IO::Socket::SSL)'

2. Download file sendmail.

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

3. Giải nén và cấu hình.

tar -zxvf sendEmail-v1.56.tar.gz
cp -a sendEmail-v1.56/sendEmail /usr/local/bin
touch /var/log/sendEmail
chmod 666 /var/log/sendEmail

4. Kiểm tra gửi mail.

sendEmail -v -f $username -s $host -t $recipient -o tls=yes -u $subject -m $content

5. Cấu hình Nagios.

Chỉnh sữa file resource.cfg  trong /usr/local/nagios/etc/resource.cfg

vi /usr/local/nagios/etc/resource.cfg

Thêm những dòng sau cho thông tin host SMTP và lưu lại:

$USER5$=email@gmail.com
$USER7$=smtp.gmail.com:587
$USER9$=email
$USER10$=password

6. Chỉnh sửa thông tin file commands.cfg.

Tạo file dự phòng

cd /usr/local/nagios/etc/objects/
cp commands.cfg commands.cfg.old

Tìm những dòng sau ‘notify-host-by-emailand notify-service-by-email’

Trường hợp SMTP bảo mật thay những dòng sau tương ứng với những dòng trên:

# 'notify-host-by-email' command definition 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" | /usr/local/bin/sendEmail -s $USER7$ -xu $USER9$ -xp $USER10$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" }

# '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$" | /usr/local/bin/sendEmail -s $USER7$ -xu $USER9$ -xp $USER10$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" }

Trường hợp SMTP không bảo mật thay những dòng sau tương ứng với những dòng trên:

# 'notify-host-by-email' command definition 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" | /usr/local/bin/sendEmail -s $USER7$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" }

# '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$" | /usr/local/bin/sendEmail -s $USER7$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" }

7. Kiểm tra config và restart nagios.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart

8. Kiểm tra lỗi send mail.

tail -f /var/log/sendEmail

Lưu ý: Có thể bạn sẽ cần cài đặt như sau:

apt-cache search IO::Socket::SSL
libevent-rpc-perl - Event based transparent Client/Server RPC framework
libhttp-daemon-ssl-perl - A simple HTTP server class with SSL support
libio-socket-ssl-perl - Perl module implementing object oriented interface to SSL sockets
libnet-imap-simple-perl - Perl module to manage an IMAP account
libnet-smtp-ssl-perl - SSL support for Net::SMTP

Xuất hiện lỗi SSL version làm theo cách sau:

Tìm file trong usr/bin/sendEmail

Chỉnh sữa dòng sau if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv3 TLSv1')) thành if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'TLSv1')) 

Kết luận:

Mình vừa giới thiệu đến các bạn cách cài đặt gửi mail thông báo cho Nagios Monitoring Server bằng Nagios Gmail Server. Các bạn có thắc mắc gì có thể để lại comment chia sẽ bên dưới. Nếu bài viết có nhiều sai sót xin các bạn góp ý
Cảm ơn các bạn theo dõi.

17 thoughts to “Hướng dẫn gửi thông báo bằng Nagios Gmail Server”

  1. Good day! I could have sworn I’ve been to this website before but
    after looking at many of the posts I realized it’s new to me.
    Anyways, I’m definitely pleased I found it and
    I’ll be book-marking it and checking back frequently!

  2. Hi, I do think this is an excellent website. I stumbledupon it 😉 I may return once
    again since I book marked it. Money and freedom is thee greatest way to
    change, may you be rich and continue to help other people.

    бесплатные онлайн казино игры sitte бонусный
    гид по онлайн-казино

  3. Superb blog! Do you have any suggestions for aspiring writers?

    I’m hoping to start my own website soon but I’m a little lost on everything.

    Would you advise starting with a free platform like WordPress or go for a
    paid option? There are so many choices out there that I’m
    totally confused .. Any suggestions? Thanks!

  4. I must thank you for the efforts you have put in penning this website.
    I’m hoping to see the same high-grade blog posts by you
    later on as well. In truth, your creative writing abilities has
    encouraged me to get my very own site now 😉

  5. I was curious if you ever thought of changing the page layout of
    your site? Its very well written; I love what youve got to
    say. But maybe you could a little more in the
    way of content so people could connect with it better.
    Youve got an awful lot of text for only having one or two
    images. Maybe you could space it out better?

  6. With havin so much content do you ever run into any problems of plagorism or copyright infringement?
    My website has a lot of exclusive content I’ve either created myself or outsourced but it looks like a lot of it is popping it up all over
    the web without my permission. Do you know any ways to help prevent content from being stolen? I’d genuinely appreciate it.

Trả lời

Thư điện tử của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

4 × 1 =