ここでは日本語化したNagiosで監視をします。
statusmap.cgiを使いたい場合は、別途GDとかのライブラリが必要になります。
たぶんGDだけで大丈夫だったかと思いますが、
GD入れるのにjpegとかのライブラリも必要になるかもしれません。
また、説明がものすごく長いですが、ご容赦を。。
ちなみに現在2.12がLegacy Stableです。
監視項目は以下の通りとしてみます。
- 監視サーバ(192.168.0.1)
HTTP HTTPS PING DISK PROCCESS CURRENTUSER PING
- ルータ(192.168.0.254)
PING
- WEBサーバ(192.168.0.2)
HTTP HTTPS FTP SSH PING
- ファイルサーバ(192.168.0.3)
SAMBA FTP SSH PING
- メールサーバ兼ニュースサーバ(192.168.0.4)
SMTP SMTPS POP3 POP3S IMAP IMAPS NEWS PING
- DNSサーバ兼NTPサーバ(192.168.0.5)
DNS DIG NTP PING
- PROXYサーバ(192.168.0.6)
PROXY(プラグインに無いので設定ファイルにて構成) PING
事前準備
rpm -aq | grep gd
gd-2.xxxxx
gd-devel-2.xxxxx
もしgdがインストールされていなければyumなりでインストールしてください。
インストール
cd /usr/local/src
mkdir -p nagios
cd nagios
wget http://ftp.momo-i.org/pub/security/nagios-2.9jp.tar.bz2
wget http://jaist.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.9.tar.gz
tar jxvf nagios-2.9ja.tar.bz2
cd nagios-2.9ja
./configure
make all
make fullinstall
make install-config
cd /usr/local/src/nagios
tar zxvf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure
make
make install
hostextinfo用の画像
ここから適当に画像を持ってきて、/usr/local/nagios/share/images/logosに
展開してください。
設定
cd /usr/local/nagios/etc
mkdir -p sample
cp bigger.cfg-sample bigger.cfg
cp cgi.cfg-sample cgi.cfg
cp checkcommands.cfg-sample checkcommands.cfg
cp nagios.cfg-sample nagios.cfg
cp resource.cfg-sample resource.cfg
mv *-sample sample
そのほかにinstall-configで入らないファイルや
サービスごとにcfgファイルを分けるので以下をとりあえず作成
touch escalation.cfg
touch hostextinfo.cfg
touch h_kanshi.cfg
touch s_kanshi.cfg
touch h_web.cfg
touch s_web.cfg
touch h_file.cfg
touch s_file.cfg
touch h_mail.cfg
touch s_mail.cfg
touch h_dns.cfg
touch s_dns.cfg
touch h_proxy.cfg
touch s_proxy.cfg
設定ファイルの編集
設定ファイルが大きいため、変更点のみ
nagios.cfg
cfg_file=/usr/local/nagios/etc/minimal.cfg
↓
cfg_file=/usr/local/nagios/etc/bigger.cfg
cfg_file=/usr/local/nagios/etc/escalation.cfg
cfg_file=/usr/local/nagios/etc/hostextinfo.cfg
cfg_file=/usr/local/nagios/etc/h_kanshi.cfg
cfg_file=/usr/local/nagios/etc/h_web.cfg
cfg_file=/usr/local/nagios/etc/h_file.cfg
cfg_file=/usr/local/nagios/etc/h_mail.cfg
cfg_file=/usr/local/nagios/etc/h_dns.cfg
cfg_file=/usr/local/nagios/etc/h_proxy.cfg
cfg_file=/usr/local/nagios/etc/s_kanshi.cfg
cfg_file=/usr/local/nagios/etc/s_web.cfg
cfg_file=/usr/local/nagios/etc/s_file.cfg
cfg_file=/usr/local/nagios/etc/s_mail.cfg
cfg_file=/usr/local/nagios/etc/s_dns.cfg
cfg_file=/usr/local/nagios/etc/s_proxy.cfg
check_external_commands=0
↓
check_external_commands=1
command_check_interval=-1
↓
command_check_interval=60s
date_format=us
↓
date_format=iso8601
cgi.cfg
#authorized_for_system_information=nagiosadmin,theboss,jdoe
↓
authorized_for_system_information=nagiosadmin
#authorized_for_configuration_information=nagiosadmin,jdoe
↓
authorized_for_configuration_information=nagiosadmin
#authorized_for_system_commands=nagiosadmin
↓
authorized_for_system_commands=nagiosadmin
#authorized_for_all_services=nagiosadmin,guest
#authorized_for_all_hosts=nagiosadmin,guest
↓
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin,momo-i
#authorized_for_all_service_commands=nagiosadmin
#authorized_for_all_host_commands=nagiosadmin
↓
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
default_statusmap_layout=5
default_statusmap_layout=3
misccommand.cfg
# 'notify-by-email' command definition
define command{
command_name notify-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\n
Type : $NOTIFICATIONTYPE$\n\n
Service: $SERVICEDESC$\n
Host : $HOSTALIAS$ ($HOSTNAME$)\n
Address: $HOSTADDRESS$\n
State : $SERVICESTATE$\n
Date : $SHORTDATETIME$\n
Info : $SERVICEOUTPUT$\n
COUNT : $NOTIFICATIONNUMBER$\n
URL : https://www.momo-i.org/nagios/\n\n"
| /bin/mail -s "** $NOTIFICATIONTYPE$
alert - $HOSTALIAS$ ($HOSTNAME$)/$SERVICEDESC$ is
$SERVICESTATE$ **" $CONTACTEMAIL$
}
# 'host-notify-by-email' command definition
define command{
command_name host-notify-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\n
Type : $NOTIFICATIONTYPE$\n
Host : $HOSTNAME$\nState : $HOSTSTATE$\n
Address: $HOSTADDRESS$\n
Info : $HOSTOUTPUT$\n
COUNT : $NOTIFICATIONNUMBER$\n
URL : https://www.momo-i.org/nagios/\n
Date : $SHORTDATETIME$\n"
| /bin/mail -s "Host $HOSTSTATE$ alert for $HOSTNAME$!"
$CONTACTEMAIL$
}
checkcommands.cfg
# 'check_https' command definition
define command{
command_name check_https
command_line $USER1$/check_http -H $HOSTADDRESS$ -S
}
# 'check_proxy' command definition
define command{
command_name check_proxy
command_line $USER1$/check_http -H $HOSTADDRESS$ -p $ARG1$ -u $ARG2$ -t 60 -w $ARG3$ -c $ARG4$
}
# 'check_ssh' command definition
define command{
command_name check_ssh
command_line $USER1$/check_ssh -t $ARG1$ $HOSTADDRESS$
}
# 'check_ntp' command definition
define command{
command_name check_ntp
command_line $USER1$/check_ntp -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
}
# 'check_smb' command definition
define command{
command_name check_smb
command_line $USER1$/check_disk_smb -H $HOSTADDRESS$ -s $ARG1$ -u $ARG2$ -p $ARG3$
}
# 'check_pop3s' command definition
define command{
command_name check_pop3s
command_line $USER1$/check_spop -H $HOSTADDRESS$
}
# 'check_smtps' command definition
define command{
command_name check_smtps
command_line $USER1$/check_ssmtp -H $HOSTADDRESS$
}
# 'check_imap' command definition
define command{
command_name check_imap
command_line $USER1$/check_imap -H $HOSTADDRESS$
}
# 'check_simap' command definition
define command{
command_name check_simap
command_line $USER1$/check_simap -H $HOSTADDRESS$
}
hostextinfo.cfg
define hostextinfo{
name nagios
icon_image nagios.gif
icon_image_alt Naios
vrml_image nagios.gif
statusmap_image nagios.gd2
register 0
}
define hostextinfo{
name linux
icon_image linux40.jpg
icon_image_alt Linux
vrml_image linux40.png
statusmap_image linux40.gd2
register 0
}
define hostextinfo{
name router
icon_image router40.jpg
icon_image_alt Router
vrml_image router40.png
statusmap_image router40.gd2
register 0
}
define hostextinfo{
use router
host_name 192.168.0.254
2d_coords 150,50
}
define hostextinfo{
use linux
host_name 192.168.0.1
2d_coords 150,50
}
define hostextinfo{
use linux
host_name 192.168.0.2
2d_coords 150,50
}
define hostextinfo{
use linux
host_name 192.168.0.3
2d_coords 150,50
}
define hostextinfo{
use linux
host_name 192.168.0.4
2d_coords 150,50
}
define hostextinfo{
use linux
host_name 192.168.0.5
2d_coords 150,50
}
define hostextinfo{
use linux
host_name 192.168.0.6
2d_coords 150,50
}
長くなってきたので、ホストの各種設定は手短に
h_kanshi.cfg
define host{
use generic-host ; Name of host template to use
host_name kanshi
alias kanshi Server #1
address 192.168.0.1
check_command check-host-alive
max_check_attempts 10
notification_interval 10
notification_period 24x7
notification_options d,u,r
contact_groups kanshi-admins
parents 192.168.0.1
}
s_kanshi.cfg
define service{
use generic-service ; Name of service template to use
host_name kanshi
service_description SSH
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 5
retry_check_interval 1
contact_groups kanshi-admins
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
check_command check_ssh!2
}
その他のサービスについても同様に行います。
(気が向いたら設定ファイルを添付であげて置きます。)
最後にbigger.cfgを改造しますが、
これも暇なときに添付であげて置きます。
bigger.cfg
# '24x7' timeperiod definition
define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
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
}
# 'workhours' timeperiod definition
define timeperiod{
timeperiod_name workhours
alias "Normal" Working Hours
monday 09:00-17:00
tuesday 09:00-17:00
wednesday 09:00-17:00
thursday 09:00-17:00
friday 09:00-17:00
}
# 'nonworkhours' timeperiod definition
define timeperiod{
timeperiod_name nonworkhours
alias Non-Work Hours
sunday 00:00-24:00
monday 00:00-09:00,17:00-24:00
tuesday 00:00-09:00,17:00-24:00
wednesday 00:00-09:00,17:00-24:00
thursday 00:00-09:00,17:00-24:00
friday 00:00-09:00,17:00-24:00
saturday 00:00-24:00
}
# 'none' timeperiod definition
define timeperiod{
timeperiod_name none
alias No Time Is A Good Time
}
###############################################################################
# CONTACT DEFINITIONS
###############################################################################
# 'nagios' contact definition
define contact{
contact_name nagios
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email webmaster@momo-i.org
}
##############################################################################
# CONTACT GROUP DEFINITIONS
###############################################################################
define contactgroup{
contactgroup_name kanshi-admins
alias Kanshi Administrators
members kanshi-admin
}
###############################################################################
# HOST DEFINITIONS
###############################################################################
# Generic host definition template
define host{
name generic-host ; The name of this host template - referenced in other host definitions, used for template recursion/resolution
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}
#register 0 でテンプレートとして機能します。
###############################################################################
# HOST GROUP DEFINITIONS
###############################################################################
define hostgroup{
hostgroup_name nagios-servers
alias nagios Servers
members (各h_****.cfg内で記述したhost_nameを記述複数ある場合はカンマで区切る)
}
##############################################################################
# SERVICE DEFINITIONS
###############################################################################
# Generic service definition template
define service{
name generic-service ; The 'name' of this service template, referenced in other service definitions
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
起動
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios 2.2
Copyright (c) 1999-2006 Ethan Galstad (http://www.nagios.org)
Last Modified: 04-07-2006
License: GPL
Reading configuration data...
Running pre-flight check on configuration data...
Checking services...
Checked 212 services.
Checking hosts...
Checked 109 hosts.
Checking host groups...
Checked 11 host groups.
Checking service groups...
Checked 0 service groups.
Checking contacts...
Checked 4 contacts.
Checking contact groups...
Checked 14 contact groups.
Checking service escalations...
Checked 374 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 31 commands.
Checking time periods...
Checked 4 time periods.
Checking extended host info definitions...
Checked 95 extended host info definitions.
Checking extended service info definitions...
Checked 0 extended service info definitions.
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
Things look okay - No serious problems were detected during the pre-flight check
コンフィグファイルがおかしい場合などは以下のように表示が出ます。
何が原因か教えてくれるので、それにしたがって修正しましょう。
エラー例(そんなコンフィグファイル無いよ!)
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios 2.9
Copyright (c) 1999-2006 Ethan Galstad (http://www.nagios.org)
Last Modified: 04-07-2006
License: GPL
Reading configuration data...
Error: Cannot open config file '/var/faewfa' for reading: No such file or directory
***> One or more problems was encountered while processing the config files...
Check your configuration file(s) to ensure that they contain valid
directives and data defintions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
'Whats New' section to find out what has changed.
3Dステータスマップを使うには
こいつをインストールすればいけると思います。
コメントを追加