「nagios」カテゴリーアーカイブ

Nagiosで警告音を鳴らしてみた。

Nagiosで障害検知が出来る様になって、リアルタイムで障害を検知したいということになりました。

メールで通知しても、メールを見るまでは障害を確認出来ない。

と言うことで、Nagiosの監視をブラウザでモニタリングしている状態で、音が鳴る様に設定した。

まず、音のファイルを準備して、以下に配置する。

warning時の音
/usr/local/nagios/share/media/warning.wav

critical時の音
/usr/local/nagios/share/media/critical.wav

/usr/local/nagios/etc/cgi.cfgを開いて以下の様に、criticalとwarningの設定を有効にする。

#host_unreachable_sound=hostdown.wav
#host_down_sound=hostdown.wav
service_critical_sound=critical.wav
service_warning_sound=warning.wav
#service_unknown_sound=warning.wav
#normal_sound=noproblem.wav

nagiosを再起動させれば完了。

# servie nagios restart

ブラウザでモニタリングすると、障害発生時に音が鳴る様になる。

が、ここで問題!ブラウザによって挙動が異なります。

①IE (IE 11)の場合
音が鳴るタイミングで、ネットワーク認証を求められます。

②FireFoxの場合
音が鳴らない。

③Chromeの場合
Chromeは正常に音が鳴る。

この問題を解決しようと試みたが、FireFoxではFireFoxのプラグインがありそうなのだが・・・、鳴らない状態も欲しいので、取りあえず放置!

IEは、解らない。対策を見つけるに至っていない。
解決策が見つかったら、どこかのタイミングで記録を残す予定。

以上

Nagiosの操作方法(ちょっとだけ)

前回までにインストールを行ったNagiosですが、操作方法が解り難いです。

そこで、システム監視サービスの状態だけ簡単に説明します。

まずはインストールを行ったNagiosにログインします。
(デフォルトで、IDとパスワードはnagiosadminになっています。)

Nagiosホーム画面

アナウンスが出ていますが、気にせず(^^ゞ

トップ画面では、状態が確認出来ません。
監視状態を確認するには、左メニューから項目を選択します。

Nagiosメニュー

1.全般

1)ホーム

ログイン後のホーム画面が表示されます。

Nagiosホーム画面

2)ドキュメント

Nagiosのマニュアルなどが公開されている英語のサイトが表示されます。OSSは英語を読まないとダメですね。
ということで、説明は省略します。

2.現在の状態

1)総合監視状態

総合監視状態を表示しています。

  • ネットワーク障害
  • ホストの稼働状態
  • サービスの稼働状態
  • 監視機能の設定状態

など、全体のサマリー的な要素を含んでいます。安定して稼働状態にあるシステムで、現状を大枠で確認したい場合にはこの画面が役立つと思います。

Nagios総合監視状態画面

2)マップ

マップ画面は、ネットワーク構成図を表示しています。

どのマシンで障害が発生しているか全体を俯瞰的に確認出来ます。

Nagiosマップ画面

3)ホスト

ホスト毎の稼働状況が一覧表となって表示されます。

 

Nagiosホスト稼働状況画面

4)サービス

前ホストの監視対象項目が一覧で表示されます。

監視項目を「監視サービス」とし、その一覧をホスト毎の一覧表として表示してくれます。

Nagios全ホストのサービス一覧画面

以下、「T.B.D(未定・後で決める予定)」となっている項目については、適宜更新を予定しています。

障害の発生状況を簡単に確認するぐらいのレベルであれば、この程度で第一歩を踏み切って、詳細については触りながら確認すれば良いと思います。

5)ホストグループ

T.B.D

6)サービスグループ

T.B.D

7)障害

T.B.D

3.レポート

T.B.D

4.システム

T.B.D

nagiosにグラフ機能を追加する。nagiosgraphの追加 【第2回目】

前回に引き続き、nagiosgraphの設定を進めます。

前回までにnagiosgraphの初期インストールが完了したので、確認と設定を行います。

# service nagios configtest

問題がなければ、nagiosをリスタートする。

# service nagios restart

nagiosのホームページを確認して表示されていれば、取りあえずOKです。まだグラフ表示はありません。

nagiosgraphが動いているかどうかを確認します。

ls /var/spool/nagiosgraph/rrd/localhost/

なんか.rrdファイルが出来ていればOK。

Apacheを再起動します。

# service httpd restart

この状態で確認を行ってみます。

以下のURLをブラウザで開きます。

https://hogehoge/nagiosgraph/cgi-bin/show.cgi

エラーが発生したら、取りあえず、SELinuxを止めてみます。

# getenforce
Enforcing
# setenforce 0

再度下記のURLを開いてみます。

https://hogehoge/nagiosgraph/cgi-bin/show.cgi

こんな画面が表示されれば、インストールは完了していると思います。

HostとServiceを適当に選んで表示させてみてください。

 

次に、nagiosのテンプレートファイルを変更します。

以下の内容(INSTALLファイルに記載あり)を/usr/local/nagios/etc/objects/templates.cfgの最後に追加します。

define service {
       name graphed-service
       action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&period=week&rrdopts=-w+450+-j
       register 0
     }

後は、グラフ表示を行いたいサービスに対しgraphed-serviceの設定を追加します。

/usr/local/nagios/etc/objects/localhost.cfgで、グラフ表示を行いたいserviceに対して以下の様に設定を追加する。

define service{
        use                             local-service,graphed-service         ; Name of service template to use
        host_name                       localhost
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }

ホストへのPINGに対してグラフ表示を追加した例です。
後は、必要に応じて同じように設定を追加するだけです。

残念ながら日本語には対応していないようなので、注意してください。

最後に、nagiosを再起動します。チェックはご自身でお願いします。

# service nagios restart

nagiosの画面を確認してみてください。

以上で設定は終わりです。

 

nagiosにグラフ機能を追加する。nagiosgraphの追加【第1回目】

nagiosのインストールがほぼほぼ出来てきたのですが、やはり見栄えがもう少し!ということで、nagiosでグラフ表示を行うことにしました。

ということで、nagiosgraphを追加します。

nagiosgraphを以下の方法でダウンロードしてきます。

# cd /home
# mkdir nagiosgraph
# cd nagiosgraph
# wget https://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.5.2/nagiosgraph-1.5.2.tar.gz

ところが、環境によってはダウンロード出来ないことがあるようです。

私の環境では、2度ほど躓きまして、結局WinSCPを使ってWindows PC転送することになりました(^^ゞ

ダウンロードが完了したら、いつもの調子で展開します。

# tar xvf nagiosgraph-1.5.2.tar.gz
# cd nagiosgraph-1.5.2

ここまでは簡単ですねw

ここで、インストールの方法をWebで検索する前に、インストール方法が記載されているINSTALLファイルを覗いてみます。

# more INSTALL
------------------------       License: OSI Artistic License
nagiosgraph Installation       Author:  (c) 2005 Soren Dossing
------------------------       Author:  (c) 2008 Alan Brenner, Ithaka Harbors
                               Author:  (c) 2010 Matthew Wall

Installation can be done automatically using the install.pl script,
or manually by copying and modifying files.


Install Pre-Requisites
----------------------

To see which pre-requisites are installed:

    install.pl --check-prereq

To install pre-requisites:

  Debian/Ubuntu
    sudo apt-get install libcgi-pm-perl librrds-perl libgd-gd2-perl
  Redhat/Fedora/CentOS
    sudo yum install perl-rrdtool perl-GD
  Mac OS X Homebrew

見てみると、install.pl –check-prereqなる文字列が・・・
インストール前の事前チェックを行う機能がnagiosgraphには備えられているようなので、取りあえず、チェックしてみます。

# ./install.pl --check-prereq
checking required PERL modules
  Carp...1.11
  CGI... ***FAIL***
  Data::Dumper...2.124
  Digest::MD5...2.39
  File::Basename...2.77
  File::Find...1.14
  MIME::Base64...3.08
  POSIX...1.17
  RRDs... ***FAIL***
  Time::HiRes... ***FAIL***
checking optional PERL modules
  GD... ***FAIL***
  Nagios::Config... ***FAIL***
checking nagios installation
  found nagios exectuable at /usr/local/nagios/bin/nagios
  found nagios init script at /etc/init.d/nagios
checking web server installation
  found apache executable at /usr/sbin/httpd
  found apache init script at /etc/init.d/httpd

*** one or more problems were detected!

「FAIL」の文字が見受けられます(TT)
幾つかインストールを行う必要がありそうです。

CGIはperl-CGI
RRDsはrrdtool-perl
Time::HiResはperl-Time-HiRes
GDはperl-GDが必要です。

ということで、yumでインストール開始します。

# yum install perl-CGI rrdtool-perl perl-Time-HiRes perl-GD

もう一度インストール前の確認を行います。

# ./install.pl --check-prereq
checking required PERL modules
  Carp...1.11
  CGI...3.51
  Data::Dumper...2.124
  Digest::MD5...2.39
  File::Basename...2.77
  File::Find...1.14
  MIME::Base64...3.08
  POSIX...1.17
  RRDs...1.3008
  Time::HiRes...1.9721
checking optional PERL modules
  GD...2.44
  Nagios::Config... ***FAIL***
checking nagios installation
  found nagios exectuable at /usr/local/nagios/bin/nagios
  found nagios init script at /etc/init.d/nagios
checking web server installation
  found apache executable at /usr/sbin/httpd
  found apache init script at /etc/init.d/httpd

Nagios::Configの項目にFAILが見受けられます。
最新版のNagiosを使用しているので、一旦無視して作業を進めます。

インストール対象がCentOS(RedHat系)なので、以下のオプションを追加してインストールを実行します。

# ./install.pl --layout redhat
checking required PERL modules
  Carp...1.11
  CGI...3.51
  Data::Dumper...2.124
  Digest::MD5...2.39
  File::Basename...2.77
  File::Find...1.14
  MIME::Base64...3.08
  POSIX...1.17
  RRDs...1.3008
  Time::HiRes...1.9721
checking optional PERL modules
  GD...2.44
  Nagios::Config... ***FAIL***
checking nagios installation
  found nagios exectuable at /usr/local/nagios/bin/nagios
  found nagios init script at /etc/init.d/nagios
checking web server installation
  found apache executable at /usr/sbin/httpd
  found apache init script at /etc/init.d/httpd
Destination directory (prefix)? [/] /usr/local/nagiosgraph
Location of configuration files (etc-dir)? [/etc/nagiosgraph]
Location of executables? [/usr/libexec/nagiosgraph]
Location of CGI scripts? [/usr/lib/nagiosgraph/cgi-bin]
Location of documentation (doc-dir)? [/usr/share/doc/nagiosgraph]
Location of examples? [/usr/share/nagiosgraph/examples]
Location of CSS and JavaScript files? [/usr/share/nagiosgraph/htdocs]
Location of utilities? [/usr/share/nagiosgraph/util]
Location of state files (var-dir)? [/var/spool/nagiosgraph]
Location of RRD files? [/var/spool/nagiosgraph/rrd]
Location of log files (log-dir)? [/var/log/nagiosgraph]
Path of log file? [/var/log/nagiosgraph/nagiosgraph.log]
Path of CGI log file? [/var/log/nagiosgraph/nagiosgraph-cgi.log]
Base URL? [/nagiosgraph]
URL of CGI scripts? [/nagiosgraph/cgi-bin]
URL of CSS file? [/nagiosgraph/nagiosgraph.css]
URL of JavaScript file? [/nagiosgraph/nagiosgraph.js]
URL of Nagios CGI scripts? [/nagios/cgi-bin]
Path of Nagios performance data file? [/tmp/perfdata.log]
username or userid of Nagios user? [nagios]
username or userid of web server user? [apache]
Modify the Nagios configuration? [n] y
Path of Nagios configuration file? [/etc/nagios/nagios.cfg] /usr/local/nagios/etc/nagios.cfg
Path of Nagios commands file? [/etc/nagios/objects/commands.cfg] /usr/local/nagios/etc/objects/commands.cfg
Modify the Apache configuration? [n] y
Path of Apache configuration directory? [/etc/httpd/conf.d]
configuration:
  ng_prefix            /usr/local/nagiosgraph
  ng_etc_dir           /etc/nagiosgraph
  ng_bin_dir           /usr/libexec/nagiosgraph
  ng_cgi_dir           /usr/lib/nagiosgraph/cgi-bin
  ng_doc_dir           /usr/share/doc/nagiosgraph
  ng_examples_dir      /usr/share/nagiosgraph/examples
  ng_www_dir           /usr/share/nagiosgraph/htdocs
  ng_util_dir          /usr/share/nagiosgraph/util
  ng_var_dir           /var/spool/nagiosgraph
  ng_rrd_dir           /var/spool/nagiosgraph/rrd
  ng_log_dir           /var/log/nagiosgraph
  ng_log_file          /var/log/nagiosgraph/nagiosgraph.log
  ng_cgilog_file       /var/log/nagiosgraph/nagiosgraph-cgi.log
  ng_url               /nagiosgraph
  ng_cgi_url           /nagiosgraph/cgi-bin
  ng_css_url           /nagiosgraph/nagiosgraph.css
  ng_js_url            /nagiosgraph/nagiosgraph.js
  nagios_cgi_url       /nagios/cgi-bin
  nagios_perfdata_file /tmp/perfdata.log
  nagios_user          nagios
  www_user             apache
  modify_nagios_config y
  nagios_config_file   /usr/local/nagios/etc/nagios.cfg
  nagios_commands_file /usr/local/nagios/etc/objects/commands.cfg
  modify_apache_config y
  apache_config_dir    /etc/httpd/conf.d
  apache_config_file
Continue with this configuration? [y] y
mkdir /usr/local/nagiosgraph
mkdir /etc/nagiosgraph
move /etc/nagiosgraph/nagiosgraph_de.conf to /etc/nagiosgraph/nagiosgraph_de.conf.20151215170149
copy etc/nagiosgraph_de.conf to /etc/nagiosgraph/nagiosgraph_de.conf
move /etc/nagiosgraph/nagiosgraph.conf to /etc/nagiosgraph/nagiosgraph.conf.20151215170149
copy etc/nagiosgraph.conf to /etc/nagiosgraph/nagiosgraph.conf
move /etc/nagiosgraph/datasetdb.conf to /etc/nagiosgraph/datasetdb.conf.20151215170149
copy etc/datasetdb.conf to /etc/nagiosgraph/datasetdb.conf
move /etc/nagiosgraph/labels.conf to /etc/nagiosgraph/labels.conf.20151215170149
copy etc/labels.conf to /etc/nagiosgraph/labels.conf
move /etc/nagiosgraph/servdb.conf to /etc/nagiosgraph/servdb.conf.20151215170149
copy etc/servdb.conf to /etc/nagiosgraph/servdb.conf
move /etc/nagiosgraph/nagiosgraph_es.conf to /etc/nagiosgraph/nagiosgraph_es.conf.20151215170149
copy etc/nagiosgraph_es.conf to /etc/nagiosgraph/nagiosgraph_es.conf
move /etc/nagiosgraph/access.conf to /etc/nagiosgraph/access.conf.20151215170149
copy etc/access.conf to /etc/nagiosgraph/access.conf
move /etc/nagiosgraph/hostdb.conf to /etc/nagiosgraph/hostdb.conf.20151215170149
copy etc/hostdb.conf to /etc/nagiosgraph/hostdb.conf
move /etc/nagiosgraph/nagiosgraph_fr.conf to /etc/nagiosgraph/nagiosgraph_fr.conf.20151215170149
copy etc/nagiosgraph_fr.conf to /etc/nagiosgraph/nagiosgraph_fr.conf
move /etc/nagiosgraph/groupdb.conf to /etc/nagiosgraph/groupdb.conf.20151215170149
copy etc/groupdb.conf to /etc/nagiosgraph/groupdb.conf
move /etc/nagiosgraph/rrdopts.conf to /etc/nagiosgraph/rrdopts.conf.20151215170149
copy etc/rrdopts.conf to /etc/nagiosgraph/rrdopts.conf
move /etc/nagiosgraph/map to /etc/nagiosgraph/map.20151215170149
copy etc/map to /etc/nagiosgraph/map
copy etc/ngshared.pm to /etc/nagiosgraph
replace text in /etc/nagiosgraph/nagiosgraph.conf
move /etc/nagiosgraph/nagiosgraph.conf-bak to /etc/nagiosgraph/nagiosgraph.conf
replace text in /etc/nagiosgraph/nagiosgraph.conf
move /etc/nagiosgraph/nagiosgraph.conf-bak to /etc/nagiosgraph/nagiosgraph.conf
write stub to /etc/nagiosgraph/nagiosgraph-nagios.cfg
write stub to /etc/nagiosgraph/nagiosgraph-commands.cfg
write stub to /etc/nagiosgraph/nagiosgraph-apache.conf
mkdir /usr/lib/nagiosgraph/cgi-bin
copy cgi/showconfig.cgi to /usr/lib/nagiosgraph/cgi-bin
replace text in /usr/lib/nagiosgraph/cgi-bin/showconfig.cgi
move /usr/lib/nagiosgraph/cgi-bin/showconfig.cgi-bak to /usr/lib/nagiosgraph/cgi-bin/showconfig.cgi
chmod 755 on /usr/lib/nagiosgraph/cgi-bin/showconfig.cgi
copy cgi/showhost.cgi to /usr/lib/nagiosgraph/cgi-bin
replace text in /usr/lib/nagiosgraph/cgi-bin/showhost.cgi
move /usr/lib/nagiosgraph/cgi-bin/showhost.cgi-bak to /usr/lib/nagiosgraph/cgi-bin/showhost.cgi
chmod 755 on /usr/lib/nagiosgraph/cgi-bin/showhost.cgi
copy cgi/show.cgi to /usr/lib/nagiosgraph/cgi-bin
replace text in /usr/lib/nagiosgraph/cgi-bin/show.cgi
move /usr/lib/nagiosgraph/cgi-bin/show.cgi-bak to /usr/lib/nagiosgraph/cgi-bin/show.cgi
chmod 755 on /usr/lib/nagiosgraph/cgi-bin/show.cgi
copy cgi/testcolor.cgi to /usr/lib/nagiosgraph/cgi-bin
replace text in /usr/lib/nagiosgraph/cgi-bin/testcolor.cgi
move /usr/lib/nagiosgraph/cgi-bin/testcolor.cgi-bak to /usr/lib/nagiosgraph/cgi-bin/testcolor.cgi
chmod 755 on /usr/lib/nagiosgraph/cgi-bin/testcolor.cgi
copy cgi/showservice.cgi to /usr/lib/nagiosgraph/cgi-bin
replace text in /usr/lib/nagiosgraph/cgi-bin/showservice.cgi
move /usr/lib/nagiosgraph/cgi-bin/showservice.cgi-bak to /usr/lib/nagiosgraph/cgi-bin/showservice.cgi
chmod 755 on /usr/lib/nagiosgraph/cgi-bin/showservice.cgi
copy cgi/showgraph.cgi to /usr/lib/nagiosgraph/cgi-bin
replace text in /usr/lib/nagiosgraph/cgi-bin/showgraph.cgi
move /usr/lib/nagiosgraph/cgi-bin/showgraph.cgi-bak to /usr/lib/nagiosgraph/cgi-bin/showgraph.cgi
chmod 755 on /usr/lib/nagiosgraph/cgi-bin/showgraph.cgi
copy cgi/export.cgi to /usr/lib/nagiosgraph/cgi-bin
replace text in /usr/lib/nagiosgraph/cgi-bin/export.cgi
move /usr/lib/nagiosgraph/cgi-bin/export.cgi-bak to /usr/lib/nagiosgraph/cgi-bin/export.cgi
chmod 755 on /usr/lib/nagiosgraph/cgi-bin/export.cgi
copy cgi/showgroup.cgi to /usr/lib/nagiosgraph/cgi-bin
replace text in /usr/lib/nagiosgraph/cgi-bin/showgroup.cgi
move /usr/lib/nagiosgraph/cgi-bin/showgroup.cgi-bak to /usr/lib/nagiosgraph/cgi-bin/showgroup.cgi
chmod 755 on /usr/lib/nagiosgraph/cgi-bin/showgroup.cgi
mkdir /usr/libexec/nagiosgraph
copy lib/insert.pl to /usr/libexec/nagiosgraph
replace text in /usr/libexec/nagiosgraph/insert.pl
move /usr/libexec/nagiosgraph/insert.pl-bak to /usr/libexec/nagiosgraph/insert.pl
chmod 755 on /usr/libexec/nagiosgraph/insert.pl
mkdir /usr/share/nagiosgraph/htdocs
move /usr/share/nagiosgraph/htdocs/nagiosgraph.css to /usr/share/nagiosgraph/htdocs/nagiosgraph.css.20151215170149
copy share/nagiosgraph.css to /usr/share/nagiosgraph/htdocs/nagiosgraph.css
copy share/nagiosgraph.js to /usr/share/nagiosgraph/htdocs
mkdir /usr/share/doc/nagiosgraph
copy AUTHORS to /usr/share/doc/nagiosgraph
copy CHANGELOG to /usr/share/doc/nagiosgraph
copy INSTALL to /usr/share/doc/nagiosgraph
copy README to /usr/share/doc/nagiosgraph
copy TODO to /usr/share/doc/nagiosgraph
mkdir /usr/share/nagiosgraph/examples
copy examples/nagiosgraph.2.css to /usr/share/nagiosgraph/examples
copy examples/nagiosgraph-commands.cfg to /usr/share/nagiosgraph/examples
copy examples/nagiosgraph-nagios.cfg to /usr/share/nagiosgraph/examples
copy examples/graphed-service.cfg to /usr/share/nagiosgraph/examples
copy examples/map_examples to /usr/share/nagiosgraph/examples
copy examples/map_1_4_5 to /usr/share/nagiosgraph/examples
copy examples/nagiosgraph.1.css to /usr/share/nagiosgraph/examples
copy examples/map_mwall to /usr/share/nagiosgraph/examples
copy examples/insert.sh to /usr/share/nagiosgraph/examples
copy examples/map_1_4_3 to /usr/share/nagiosgraph/examples
copy examples/nagiosgraph-apache.conf to /usr/share/nagiosgraph/examples
copy examples/map_minimal to /usr/share/nagiosgraph/examples
copy examples/graphed-host.cfg to /usr/share/nagiosgraph/examples
copy examples/map_1_3 to /usr/share/nagiosgraph/examples
copy examples/nagiosgraph-logrotate to /usr/share/nagiosgraph/examples
copy examples/map_1_4_4 to /usr/share/nagiosgraph/examples
copy share/graph.gif to /usr/share/nagiosgraph/examples
copy share/nagiosgraph.ssi to /usr/share/nagiosgraph/examples
mkdir /usr/share/nagiosgraph/util
copy utils/testentry.pl to /usr/share/nagiosgraph/util
copy utils/flat2hier.pl to /usr/share/nagiosgraph/util
chmod 755 on /usr/share/nagiosgraph/util/testentry.pl
chmod 755 on /usr/share/nagiosgraph/util/flat2hier.pl
mkdir /var/spool/nagiosgraph/rrd
chmod 755 on /var/spool/nagiosgraph/rrd
chown nagios,- on /var/spool/nagiosgraph/rrd
touching /var/log/nagiosgraph/nagiosgraph.log
chmod 644 on /var/log/nagiosgraph/nagiosgraph.log
chown nagios,- on /var/log/nagiosgraph/nagiosgraph.log
touching /var/log/nagiosgraph/nagiosgraph-cgi.log
chmod 644 on /var/log/nagiosgraph/nagiosgraph-cgi.log
chown apache,- on /var/log/nagiosgraph/nagiosgraph-cgi.log
append to /usr/local/nagios/etc/nagios.cfg
copy /usr/local/nagios/etc/nagios.cfg to /usr/local/nagios/etc/nagios.cfg.tmp
move /usr/local/nagios/etc/nagios.cfg to /usr/local/nagios/etc/nagios.cfg-20151215.1701
move /usr/local/nagios/etc/nagios.cfg.tmp to /usr/local/nagios/etc/nagios.cfg
append to /usr/local/nagios/etc/objects/commands.cfg
copy /usr/local/nagios/etc/objects/commands.cfg to /usr/local/nagios/etc/objects/commands.cfg.tmp
move /usr/local/nagios/etc/objects/commands.cfg to /usr/local/nagios/etc/objects/commands.cfg-20151215.1701
move /usr/local/nagios/etc/objects/commands.cfg.tmp to /usr/local/nagios/etc/objects/commands.cfg
move /etc/nagiosgraph/nagiosgraph-apache.conf to /etc/httpd/conf.d/nagiosgraph.conf

  * Check the nagios configuration:

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

  * Restart nagios to start data collection:

/etc/init.d/nagios restart

  * Restart apache to enable display of graphs:

/etc/init.d/httpd restart

  * To enable graph links and mouseovers, see README sections:
       Displaying Per-Service and Per-Host Graph Icons and Links
       Displaying Graphs in Nagios Mouseovers

こんな感じで取りあえずのインストールは完了。

次回につづく。。。

nagiosでWindows Serverを監視する。

nagiosのお題はWindows Serverの監視です。

前回までに、nagiosのインストールが完了し、メールの設定も追加しました。
ファイルの更新を監視して、ファイルが一定期間監視出来ているかを監視することにも成功しました。

今回は、Windows Serverを監視します。

あちこちで紹介されている内容を確認しましたが、インストールは色々と課題があるようですね。
特に、Linuxのアクセス権については、各サイトで記載されている内容には課題が残されているとみてよいでしょう。
本サイトで記載している内容でも、アクセス権の付与に関しては、SELinuxの課題などを考えると完ぺきとは言い難い状況にあると思いますが、SELinuxの設定を施すことで回避が可能であることを記載しており、回避策を練る必要があると思います。

さて、そんな課題を一旦棚上げにして、Windowsサーバの監視に移りたいと思います。

Windowsというか、Windows(クライアントOS:7とか8とか10?はやってないけど・・・)でも同じことになると思います。

他のサイトでは、監視ホストつまりnagios本体をインストールした環境における設定をまずは整えてから、Windows側の設定を行っている様なサイトもちらほら見受けられますが、まずは、Windows側の設定を行いたいと思います。

それでは、最初に環境の説明を行います。

1.今回の対象環境

nagiosホスト : Linux Cento OS 6.x

監視対象   : Windows Server 2012 R2

nagios本体バージョン:4.1.1

2.Windows側の準備作業

それでは、最初に以下のサイトから必要なモジュールをダウンロードします。

https://www.nsclient.org/download/

2015-12-16現在において、上記のホームページ上では0.4.4.15がLatestリリースとされていますが、画面上部の「Download」には、0.5.0と0.4.4が見受けられます。
0.5.0のstable releasesが提供されていれば、それを使うのが良いと思いますが、現時点ではnightly buildsしか提供されていませんでした。
どうしても試したい方は、nightly buildsを使ってみるのも良いのですが、stable releasesを選択する方が良いです。

Download→0.4.4を見てみると、0.4.4.19が最新のstable releasesとして提供されておりましたので、そちらを使うことにしました。

ということで、今回使用したのは、NSClient++ 0.4.4.19です。
必要に応じて、最新版をご確認下さい。

ダウンロードしたNSCP-0.4.4.19-x64.msiをダブルクリックすると以下の画面が開きます。後は画面の指示に従って進めます。

「Next」ボタンを押して次へ。

「Generic」で良いと思います。「op5」の事例が見つからなかったのもありますが、過去にセキュリティ問題を抱えた経緯があるので、心配掛けないためにも取りあえず、「Generic」としました。

個人的には、「Custom」もしくは「Complete」でLuaスクリプトまで入れたい気持ちもあるのですが、稼働している環境にLuaを入れてドタバタするには嫌なので、取りあえず「Typical」で作業を進めます。

 

ここからよく解らん(^^ゞ

 

Allowed hosts : NagiosをインストールしてあるサーバのIPアドレスを入力します。

Password   : 任意のパスワードを指定します。
Modules to loadには、必要な項目をチェックします。
Enable Common Check plugins    :基本モジュールなのでチェック
Enable nsclient server (check_nt) :こちら対象となるWindowsの死活監視を行うためにチェックします。
Enable NRPE Server(check_nrpe):使うのでチェック。
一応、Secureな状態にしてみました。

SNCAとWebは取りあえず全部チェックしてみます。

 

インストールの準備が完了しましたので、「Install」ボタンをクリックしてインストールを開始します。

Windows側から変更の許可を求められますので、こちらも「はい」をクリックしてインストール作業を進めます。

インストール作業中です。そんなに時間は掛かりませんでした。

インストールが完了しました。

タスクマネージャ→サービスを確認して、NSClient++が起動していることを確認出来ます。

 

インストールが成功している様子なので、以下続いて設定を少しだけ変更します。

コントロールパネル→管理ツール→サービスを起動します。

「NSClient++(x64)」をダブルクリックして、プロパティの変更を行います。

 

「ログオン」タブを選択。

「デスクトップとの対話をサービスに許可」にチェックを入れて、「OK」をクリック。

以上で、Windows側の設定が完了しました。

3.Nagiosホスト(Linux)側の設定

1)nagiosの監視項目を追加する。

/usr/local/nagios/etc/nagios.cfgファイルにある以下の行を有効にする。

cfg_file=/usr/local/nagios/etc/objects/windows.cfg

2)windows.cfgの設定を変更する。

define host{
        use             windows-server  ; Inherit default values from a template
        host_name       winserver       ; The name we're giving to this host
        alias           My Windows Server       ; A longer name associated with the host
#       address         192.168.1.2     ; IP address of the host
        address         123.456.789.xxx  ;IP address of the host
        }

addres項目に対象となるWindowsのIPアドレスを指定する。

3)nagiosの再起動

設定内容の確認を

# service nagios configtest

で実施して問題なければ、nagiosを再起動します。

service nagios restart

以上で設定が完了し、確認を実施すればOKです。

なお、別途Windows側で、5666と12489ポートを解放する必要があります。

 

nagiosをソースからインストール。SELinuxの対応

前々回の投稿で記載した内容で、nagiosのインストールを行い、SELinuxがPermissiveモードになった状態で動作が出来る様になっていると思います。

SELinuxがPermissiveな状態ですと、セキュリティ上はあまり宜しくない状態です。

SELinuxに設定を行うことで、SELinuxがEnforcingモードになっても動作出来る様に設定を施していきます。

Step1:環境確認と準備

色々と方法はあると思いますが、ここでは、SELinuxの設定を行うために、audit2allowコマンドを使用します。
audit2allowコマンドが使用可能かどうかを確認します。

# audit2allow --version
audit2allow .1

上記の様に表示されれば、audit2allowコマンドは使用可能な状態にあります。

次のステップに進んでください。

audit2allowコマンドが見つからない場合には、インストールを行います。

yum install policycoreutils-python

インストールが正常に終了したことを確認して次のステップへ進みます。

Step2:SELinuxへの設定用ファイルを作成する。

取り敢えず、SELinuxをPermissiveモードにしておきます。

# setenforce 0

この状態で、許可して欲しい操作を行います。

例えば、CRITICALな障害を開いて、通知を強制的に発行します。

操作を実行した後に、以下のコマンドを実行して許可を必要とする内容の確認を行います。

# audit2allow -i /var/log/audit/audit.log


#============= httpd_sys_script_t ==============

#!!!! This avc is allowed in the current policy
allow httpd_sys_script_t httpd_sys_content_t:fifo_file { write getattr open };

私の環境で許可を必要としていたのは、どうも上記の1件だけだった様です。
環境により異なる様ですので、必要に応じて対応を考えてください。
なお、nagiosのサポートページには、この後説明するSELinuxの設定ファイルの記述例が記載されている様です。
使えるかどうかはご自身でご判断下さい。
私は、私の環境に合った方法で対応を試みます。
こちらも、対応が十分とは言えません。全ての操作でセキュリティの許可を取ったとは言えないからです。
ちなみに、何故か?nagiosのフォルダーとかファイルが直接影響していない感じなので、そこそこ上手く設定出来ていたと思いますが・・・その辺は自己責任でお願いします。オープンソースですから(^^ゞ

で、少し余談が入りましたが、以下のコマンドを実行して必要な設定ファイルを作成します。

# grep ":httpd_sys_content_t:" /var/log/audit/audit.log | audit2allow -M httpd_sys_content_t

******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i httpd_sys_content_t.pp

httpd_sys_content_tに関連する項目だけを抜き出して、許可ファイルを作成する例です。
コマンドの出力結果には、次に実施するべき操作が記載されています。
画面の操作に従って、操作を続けます。次のコマンドを実行します。

# semodule -i httpd_sys_content_t.pp

この設定にはしばらく時間が掛かります。

私の環境では1分程度掛かったでしょうか?
止めたくなってしまったりしましたが、我慢して待ちます。

この後、正常に完了しましたら、SELinuxの設定を有効にします。

# setenforce 1

動作確認を行ってOKなら、作業は完了です。

これでセキュアな状態を維持しつつ、nagiosが使える様になりました。

このSELinuxの設定方法は、他でも利用できます。

ご自身の環境に合わせて設定を行ってみてください。

 

nagiosでファイルの更新を監視する。

nagiosでファイルの更新を監視します。

一定期間毎にファイルの更新が行われていることで、死活監視を行いたい場合があります。
今回は、対象ファイルの更新が行われいることを確認することで、障害の検知を行う方法について記載します。

使用するnagiosのチェックモジュールは以下の通りです。

chekc_file_age

では、ファイルの更新監視機能を作成します。

まず最初に、

/usr/local/nagios/etc/objects/commands.cfg

に以下の内容を記載します。(最後で良いでしょう)

define command{
command_name check_file_age
command_line $USER1$/check_file_age $ARG1$
}

これで、このコマンドが使える様になりました。

実際に監視サービスとして記述する為、

/usr/local/nagios/etc/objects/localhost.cfg

に以下の内容を追加します。

# File age Service Check
define service{
 use local-service ; Name of service template to use
 host_name localhost
 service_description file_age
 check_command check_file_age! -f /var/log/messages
 notifications_enabled 1
 }

ここでは、/var/log/messagesファイルの更新状況を監視しています。

更新が一定期間無いと障害として検知されます。

ここで、stderr: Can’t locate utils.pm・・・・・とエラーが発生しました。

 実は・・・・

nagios 4.1.1のcheck_file_ageは問題があるようです。
前回、インストールを行ったnagios-plugin-2.1.1では以下の修正を行うことで、正常に動作させることが可能です。
上記の結果にならない時には

修正個所は以下の通りです。

/usr/local/nagios/libexec/check_file_age

use lib ".";

↓↓↓↓↓変更↓↓↓↓↓↓

use lib "/usr/local/nagios/libexec";

 

これで、check_file_age自体の問題はクリアになるはずです。

 

nagiosをソースからインストール。そして日本語化もやっておこう!

前回まで、nagiosをyumリポジトリでインストールしたが、日本語化が上手くできない。

画面左のメニューを日本語化するのであれば、適当にファイルを日本語に修正すれば出来るのだが・・・・やはり違和感が残る。

取り敢えずやってみよう!?ということで日本語化を行ってみる。

ついでに、せっかくソースからインストールするのであれば、最新版(2015-12-02現在 4.1.1)をインストールすることにした。

# groupadd nagios
# useradd -d /usr/local/nagios -g nagios -m nagios
# chmod 755 /usr/local/nagios
# groupadd nagcmd
# usermod -a -G nagcmd nagios
# usermod -a -G nagcmd apache

# cd /home
# mkdir nagios
# cd nagios

普通は入れていると思うのですが、PHPが入っていないとまずいです。

ということで、以下のコマンドでPHPがインストールされているか確認します。

# yum list installed | grep php

何も表示されない場合は、インストールされていません。
以下のコマンドでインストールしてください。

# yum install php

それ以外にも必要なパッケージが入っているか確認してインストールを開始します。

参考までにインストールしたパッケージのやり方を記載しておきます。

# yum install perl-CGI gd-devel

環境によって異なることにご留意下さい。

では、nagios本体をダウンロードします。
最新版は適宜ネットで確認して下さい。
OSSとして提供してくださっている方に感謝をしながらダウンロードしましょう!

# cd /home/nagios
# curl -L -O https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz

(全部1行で記述)

展開する。

# tar zxvf naios-4.1.1.tar.gz

 

展開されたら、パッチをダウンロードしてパッチを充てる!

# cd nagios-4.1.1

日本語化パッチを提供してくれている方に感謝しながら・・・日本語化パッチを入手しましょう!

# wget --no-check-certificate  https://dev.momo-i.org/attachments/download/5/nagios-jp-4.1.1.patch.gz

(対象ファイルは、https://dev.momo-i.org/projects/nagios/filesで確認 バージョン番号は合わせること)

こんな感じで必要なものを準備する。

とにかくソースを解凍して、パッチ充ててと作業を進める。

# gzip -dc nagios-jp-4.1.1.patch.gz |patch -p1



# ./configure --with-command-group=nagcmd
# make all
# make install
# make  install-init
# make install-config
# make install-commandmode

# make install-webconf
# make install-exfoliation
# make install-classicui

# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

ここで最後に実施したhtpasswdコマンドは、nagiosのウェブ画面へログインする際のIDとパスワードになります。
CGIの動作にも影響するみたいな気がする。

yumでインストールする場合とパスワードの設定が変わっているので注意です。

次にnagiosとapacheのグループを関連付けます。

usermod -G nagios apache

時折、nagiosCGIへのアクセスが拒否されることがあるようです。
サービスを起動する前に、以下のコマンドを発行すると復旧するのですが、下記のコマンドは一時的な対策を行っているだけのものなので、あまり宜しい対策とは言えないと思います。
出来れば、リブートして確認するなどしてみると良いと思います。

それでもダメな時は以下のコマンドを実行してみてください。

chcon -R -t httpd_sys_content_t /usr/local/nagios


# service nagios startサービスを起動する。nagiosとhttpdの両方ともやってみた。

# service httpd restart

 

で、ブラウザで開いてみる。

https://xxxxxx/nagios

開くと、IDとパスワードを聞かれるので、設定したIDとパスワードでログインする。

取り敢えず、なんとなく開くはず。

次に、nagiosプラグインをインストールする。

またしてもダウンロード
https://www.nagios-plugins.org/download/から最新のnagios-plugins-2.1.1.tar.gzをダウンロードする。

# cd /home/nagios
# wget https://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

# tar zxvf nagios-plugins-2.1.1.tar.gz
# cd nagios-plugins-2.1.1
# ./configure
# make
# make install

※INSTALLファイルを読むと書いてあります。

こんな感じで完成….だと思っていました。

ここでトラブル発生です。

selinux がenforce状態(有効)になっている状態では、nagiosのプラグインが正常に動作してくれない場合があります。

例えば、CRITICALな障害を発生させて、通知を行ったときに以下のエラーが発生します。(日本語化しているので日本語メッセージです。)

まずは、簡単な対策としては、SELinuxをPermissiveモードに切り替えて運用する方法です。

SELinuxの稼働状況を確認します。

# getenforce
Enforcing
# setenforce 0
# getenforce
Permissive

getenforceコマンドで現在の状態を確認します。
Enforcing:有効な状態(許可されていないコマンドは実行が出来ません。
Permissive:無許可なコマンドの実行時には、ログを記録して実行を行います。なので、実質的には無効な状態と同じでしょう。
Disable:無効な状態(ログも残しません)

setenforce 0とすることで、Permissiveモードに設定しています。setenforce 1とすると、Enforcingモードになります。

この状態でnagiosは正常に動作するはずです。

さて、ここまででnagios自体の設定に問題が無いことが確認出来るかと思いますが、SELinuxが無効になっている状態なので、セキュリティ的には宜しくないのでは?ということになります。

そこで、セキュアな状態を維持するために、SELinuxをEnforcingモードにしても動作する様にすることが必要となります。

このままでもいいや!と言う方は、ここまででインストール作業は完了です。

いやいや、セキュアな環境を維持したいんだ!!と言う方は、今後の投稿に期待してください。

SELinuxを有効にしても動作させる方法を新しい投稿に記載しました。

nagiosにFTPサーバのチェックを追加する(ローカルホスト)

nagiosを稼働中のローカルサーバで、FTPサーバの稼働状況をチェックする。

下記ファイルに対し以下の設定を追加する。

/usr/local/nagios/etc/objects/localhost.cfg

define service{
	use local-service ; Name of service template to use
	host_name localhost
	service_description FTP
	check_command check_ftp
	notifications_enabled 0
}

 

 

最後にnagiosを再起動します。

service nagios restart

 

 

 

以上

今更だけど、CPANをインストールする。そして、モジュールを追加してみる。

Linux(CentOS 6.7を使用中)で、Perlを使うのはデフォルトでインストールされている環境だけでは物足りなくなることに。

一般的には取りあえずCPANを入れます。

# yum install perl-CPAN.x86_64

 

こんな感じでインストールします。

でcpanを起動する。

# cpan

 

入力を間違って、バックスペースを押すと・・・・^H^Hって・・・あれ?バックスペースがまともに入力出来ねぇじゃねぇか!?

ということで、ネットで調べて以下をインストール

cpan[1]>install Term::ReadLine
cpan[2]>install Term::ReadLine::Gnu

 

自動でインストールしてくれます。

一度CPANから抜けます。

cpan[3]>quit

 

もう一度、cpanへ入ります。

# cpan

cpan[1]>

 

無事、バックスペースが使える様になりました(^^ゞ
#いや~久しく使っていないと忘れますねぇw

さてさて、問題はインストールしたいモジュールがDate::Parseなんです。と言うことで

cpan[1]> install Data::Parse
cpan[2]> q                                    <==これでも抜けられます。

 

ということで、必要なインストール作業は終了しました。

本音は、nagiosで使いたい処理でperlを使っていて、これをやらないと動かないんです(^^ゞ