https://www.youtube.com/watch?v=tGhGmWrYpVM
https://www.youtube.com/watch?v=DapOC2QG6nM
Thứ Tư, 11 tháng 2, 2015
Chủ Nhật, 8 tháng 2, 2015
Check IDS
#!/usr/bin/python
import os, smtplib
from threading import Thread
def sendmail(subject):
"Sends an email to the specified recipent "
username = 'checkipwingame@gmail.com'
password = 'xxxxx'
server = smtplib.SMTP('smtp.gmail.com:25')
server.starttls()
server.login(username, password)
fromAddr ='checkipwingame@gmail.com'
toAddr = 'cuvanhai@gmail.com'
header = 'To: ' + toAddr + '\n' + 'From: ' + fromAddr + '\n' + 'Subject: ' + subject + '\n'
msg = header + '\nCheck it now!\n'
server.sendmail(fromAddr, toAddr, msg)
server.close()
def checkIpDown(ip):
ISP = ip
ret = os.system('ping -c 4 ' + ip + ' &> /dev/null')
fr = open(ip,"r")
str = fr.read(1)
fr.close()
if ISP == "118.70.183.107":
ISP = "118.70.183.107"
if ret != 0 and str == "1":
message = ISP+' has been DOWN'
sendmail(message)
fo1 = open(ip,"w")
fo1.write("0")
fo1.close()
print message
elif (ret == 0 and str == "0") :
message = ISP+' has been UP'
sendmail(message)
fo2 = open(ip,"w")
fo2.write("1")
fo2.close()
print message
elif (ret != 0 and str == "0") :
print ISP, "network not connect" # Co the xoa dong nay
ip2Check = ['118.70.183.107']
for ip in ip2Check:
t = Thread(target=checkIpDown, args=(ip,))
t.start()
import os, smtplib
from threading import Thread
def sendmail(subject):
"Sends an email to the specified recipent "
username = 'checkipwingame@gmail.com'
password = 'xxxxx'
server = smtplib.SMTP('smtp.gmail.com:25')
server.starttls()
server.login(username, password)
fromAddr ='checkipwingame@gmail.com'
toAddr = 'cuvanhai@gmail.com'
header = 'To: ' + toAddr + '\n' + 'From: ' + fromAddr + '\n' + 'Subject: ' + subject + '\n'
msg = header + '\nCheck it now!\n'
server.sendmail(fromAddr, toAddr, msg)
server.close()
def checkIpDown(ip):
ISP = ip
ret = os.system('ping -c 4 ' + ip + ' &> /dev/null')
fr = open(ip,"r")
str = fr.read(1)
fr.close()
if ISP == "118.70.183.107":
ISP = "118.70.183.107"
if ret != 0 and str == "1":
message = ISP+' has been DOWN'
sendmail(message)
fo1 = open(ip,"w")
fo1.write("0")
fo1.close()
print message
elif (ret == 0 and str == "0") :
message = ISP+' has been UP'
sendmail(message)
fo2 = open(ip,"w")
fo2.write("1")
fo2.close()
print message
elif (ret != 0 and str == "0") :
print ISP, "network not connect" # Co the xoa dong nay
ip2Check = ['118.70.183.107']
for ip in ip2Check:
t = Thread(target=checkIpDown, args=(ip,))
t.start()
Chủ Nhật, 25 tháng 1, 2015
Install icinga2 + icinga-web on Centos
ICINGA
1.
Giới thiệu Icinga:
-
Icinga là một hệ
thống theo dõi các máy chủ và dịch vụ
được chỉ định và thông báo
cho khi cho người quản trị khi có sự cố xảy ra và khi sự
cố được khắc phục
-
Icinga có thể chạy trên nhiều hệ điều
hành nhân linux : Redhat, Centos, Fedora, Ubuntu, and openSuSE cũng như một
nền tảng Unix khác như Solaris, HP
-
Một số trong nhiều tính năng của Icinga bao
gồm:
+ Giám sát các dịch vụ mạng (SMTP, POP3, HTTP, SSH, PING, vv)
+ Giám sát tài nguyên máy chủ (load CPU, DISK,RAM, vv)
+ Thiết kế plugin đơn giản cho phép người dùng dễ dàng tự phát triển
+ Thông báo khi dịch vụ có vấn đề xảy ra và được giải quyết (qua email, nhắn tin..)
+ Giám sát các dịch vụ mạng (SMTP, POP3, HTTP, SSH, PING, vv)
+ Giám sát tài nguyên máy chủ (load CPU, DISK,RAM, vv)
+ Thiết kế plugin đơn giản cho phép người dùng dễ dàng tự phát triển
+ Thông báo khi dịch vụ có vấn đề xảy ra và được giải quyết (qua email, nhắn tin..)
+ Giao diện
web than thiện, dễ sử dụng.
2. CÀI ĐẶT ICINGA2 Monitor server
2.1 Yêu cầu trước khi cài đặt Icinga
#
rpm --import http://packages.icinga.org/icinga.key
#
yum makecache
2.2 Cài đặt Icinga2
#
yum install icinga2
2.3 Cài đặt MySQL database
#
yum install mysql-server mysql
#
chkconfig mysqld on
#
service mysqld start
2.4 Cài đặt IDO modul cho MySQL
#
yum install icinga2-ido-mysql
2.5 Cấu hình MySQL cho icinga2
- Import schema icinga2
# mysql -u root –p
mysql> CREATE DATABASE icinga;
GRANT SELECT, INSERT, UPDATE, DELETE,
DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost'
IDENTIFIED BY 'icinga';
#
mysql -u root -p icinga < /usr/share/icinga2-ido-mysql/schema/mysql.sql
2.6 Enabling the IDO MySQL module
#
icinga2 feature enable ido-mysql
Module
'ido-mysql' was enabled.
Make
sure to restart Icinga 2 for these changes to take effect.
#
service icinga2 restart
2.7 Cài đặt icinga-web:
#
yum install icinga-web icinga-web-mysql
#
service httpd restart
#
service icinga2 restart
-
Set
permission /var/log/icinga-web for apache
-
Disable
Selinux : edit “/etc/sysconfig/selinux”
SELINUX=disabled
# init 6
2.8 Setting Up External Command Pipe
#
icinga2 feature enable command
#
service icinga2 restart
edit
/etc/icinga-web/conf.d/access.xml
<resource
name="icinga_pipe">/var/run/icinga2/cmd/icinga2.cmd</resource>
# icinga-web-clearcache
Cài đặt giao diện icinga-web
2.9 Webserver – php
#
yum install httpd
#
chkconfig httpd on
#
service httpd start
#
yum install php php-cli php-pear php-xmlrpc php-xsl php-pdo php-soap php-gd
php-ldap php-mysql
2.10 Firewall Rules
#
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
#
service iptables save
2.11 Cấu hình MySQL cho icinga-web
-
Import schema icinga2
#
mysql -u root –p
mysql> CREATE DATABASE icinga_web;
GRANT SELECT, INSERT, UPDATE, DELETE,
DROP, CREATE VIEW, INDEX, EXECUTE ON icinga_web.* TO 'icinga_web'@'localhost'
IDENTIFIED BY 'icinga_web';
#
mysql -u root
-p icinga_web < /usr/share/doc/icinga-web-1.11.2/schema/mysql.sql #import database icinga_web
2.12 Login kiểm tra icigna-web:
user:
root
pass:
password
2.13 Enabled Features during Installation
The default installation will enable three features required for a basic Icinga 2 installation:checker
for executing checksnotification
for sending notificationsmainlog
for writing theicinga2.log
file
icinga2
feature list
CLI
command to see which features are enabled and disabled.# icinga2 feature list
Disabled features: api command compatlog debuglog graphite icingastatus ido-mysql ido-pgsql livestatus notification perfdata statusdata syslog
Enabled features: checker mainlog notification
2.14 Installation Paths
Đường
dẫn mặc định khi cài đặt icinga2 của các file và thư mục:
Path
|
Description
|
/etc/icinga2
|
Contains Icinga 2 configuration files.
|
/etc/init.d/icinga2
|
The Icinga 2 init script.
|
/usr/sbin/icinga2*
|
The Icinga 2 binary.
|
/usr/share/doc/icinga2
|
Documentation files that come with Icinga 2.
|
/usr/share/icinga2/include
|
The Icinga Template Library and plugin command
configuration.
|
/var/run/icinga2
|
PID file.
|
/var/run/icinga2/cmd
|
Command pipe and Livestatus socket.
|
/var/cache/icinga2
|
status.dat/objects.cache, icinga2.debug files
|
/var/spool/icinga2
|
Used for performance data spool files.
|
/var/lib/icinga2
|
Icinga 2 state file, cluster log, local CA and
configuration files.
|
/var/log/icinga2
|
Log file location and compat/ directory for the
CompatLogger feature.
|
3. Cài đặt agent và plugins trên client
# yum install nagios-plugins-all
# ls /usr/lib64/nagios/plugins/
# yum install xinetd
nagios-nrpe –y
-
edit /etc/xinetd.d/nrpe:
disable = no
only_from = x.x.x.x # IP address Icinga Server
# service xinetd
restart
-
edit
/etc/nagios/nrpe.cfg
4. Cài đặt P4PNagios plugins cho icinga-web
yum install pnp4nagios
icinga-web-module-pnp –y
# ls
/var/spool/icinga2/perfdata/
# icinga2
feature enable perfdata
# service icinga2 restart
# ls /var/spool/icinga2/perfdata/
# service httpd restart
# vi /etc/pnp4nagios/npcd.cfg
# ls /var/spool/icinga2/perfdata/
# service httpd restart
# vi /etc/pnp4nagios/npcd.cfg
user = icinga
group = icinga
…..
perfdata_spool_dir = /var/spool/icinga2/perfdata/
# service
npcd start
# chkconfig
npcd on
# service
httpd restart
# vi
/etc/nagios/passwd
icingaadmin:$apr1$ipM6pQLU$mXHz4PJc9.pbhWK.Hntts1
(pass: admin)
htpasswd /etc/nagios/passwd icingaadmin
# chown -R icinga.icinga
/var/lib/pnp4nagios/
# service httpd restart
# service icinga2 restart
Youtube:
https://www.youtube.com/watch?v=DapOC2QG6nM
https://www.youtube.com/watch?v=tGhGmWrYpVM
Đăng ký:
Bài đăng (Atom)