差分
この文書の現在のバージョンと選択したバージョンの差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
management:centreon:hddtemp:start [2011/03/15 16:14] yuki |
— (現在) | ||
---|---|---|---|
ライン 1: | ライン 1: | ||
- | ====== HDDの温度監視 ====== | ||
- | HDDの温度をCentreonに監視させて、グラフを書く。前半はNagiosとやること一緒。 | ||
- | <note important> | ||
- | * 対象OS : FreeBSD 8.1-R | ||
- | * コンポーネント : net-snmp-5.5_4 , smartmontools-5.40 | ||
- | * 注記 : 各コンポーネントは単体では動作が確認できていることとする) | ||
- | </note> | ||
- | |||
- | ===== 概要手順 ===== | ||
- | |||
- | - SNMPのextend機能を使用して、HDDの温度がMIB値として取得できるようにする。 | ||
- | - MIB値を調べる。 | ||
- | - 対象のMIB値を取得してきて、Centreon用の出力をするようにプラグインを作成。 | ||
- | * これはnagiosのパフォーマンス出力とほぼ同義だ。 | ||
- | - CentreonのWebUIでcommandを登録。 | ||
- | - 同様に監視対象となるホストを選択して、Servicesを登録。 | ||
- | - 終わり。 | ||
- | |||
- | ===== 詳細 ===== | ||
- | |||
- | * まずextend機能を使用してMIB値を登録する。 | ||
- | * 以下のスクリプトを実行可能な形で作成 | ||
- | * <code>#!/bin/sh | ||
- | |||
- | for dev in `ls -t /dev/* | awk '/(ad|da)[0-9]+$/ {print $1}'`; do | ||
- | case $1 in | ||
- | name) echo $dev;; | ||
- | temprature) smartctl -A $dev | awk '$1=="194" {print $10}';; | ||
- | esac | ||
- | done</code> | ||
- | |||
- | * snmpd.confにextend行を記載(今回は最終行に2行追加)。 | ||
- | * <code># cat snmpd.conf | tail -2 | ||
- | extend ataDevice /usr/local/share/snmp/ata_device_temperature.sh name | ||
- | extend ataDeviceTemperature /usr/local/share/snmp/ata_device_temperature.sh temprature</code> | ||
- | * snmpdの再起動 | ||
- | * <code># /usr/local/etc/rc.d/snmpd restart</code> | ||
- | |||
- | * MIB値の確認 | ||
- | * nsExtensionsは1.3.6.1.4.1.8072.1.3なので、snmpwalkで一通り見てみる。 | ||
- | * http://www.oidview.com/mibs/8072/NET-SNMP-AGENT-MIB.html | ||
- | * snmpwalk -v 1 -c private 127.0.0.1 .1.3.6.1.4.1.8072.1.3 | ||
- | * 一部抜粋 | ||
- | * <code>NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."ataDevice" = INTEGER: 4 | ||
- | NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."ataDeviceTemperature" = INTEGER: 4 | ||
- | NET-SNMP-EXTEND-MIB::nsExtendResult."ataDevice" = INTEGER: 0 | ||
- | NET-SNMP-EXTEND-MIB::nsExtendResult."ataDeviceTemperature" = INTEGER: 0 | ||
- | NET-SNMP-EXTEND-MIB::nsExtendOutLine."ataDevice".1 = STRING: /dev/ad8 | ||
- | NET-SNMP-EXTEND-MIB::nsExtendOutLine."ataDevice".2 = STRING: /dev/da0 | ||
- | NET-SNMP-EXTEND-MIB::nsExtendOutLine."ataDevice".3 = STRING: /dev/da1 | ||
- | NET-SNMP-EXTEND-MIB::nsExtendOutLine."ataDevice".4 = STRING: /dev/da2 | ||
- | NET-SNMP-EXTEND-MIB::nsExtendOutLine."ataDeviceTemperature".1 = STRING: 36 | ||
- | NET-SNMP-EXTEND-MIB::nsExtendOutLine."ataDeviceTemperature".2 = STRING: 36 | ||
- | NET-SNMP-EXTEND-MIB::nsExtendOutLine."ataDeviceTemperature".3 = STRING: 33 | ||
- | NET-SNMP-EXTEND-MIB::nsExtendOutLine."ataDeviceTemperature".4 = STRING: 34</code> | ||
- | * 値にシェルスクリプトのエラー値が入っている場合は、スクリプトを見直します。 | ||
- | * その後、-Onオプションを付与してOIDを数値形式で出力し、Centreon用のスクリプトに記載します。 | ||
- | * <code>snmpwalk -v 1 -On -c private 127.0.0.1 .1.3.6.1.4.1.8072.1.3</code> | ||
- | |||
- | * Centreon用のシェルスクリプト作成 | ||
- | * 参考文献 | ||
- | * http://nagiosplug.sourceforge.net/developer-guidelines.html | ||
- | * http://junrei.dip.jp/wordpress/nagios/nagios%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E9%96%8B%E7%99%BA%E3%82%AC%E3%82%A4%E3%83%89%E3%83%A9%E3%82%A4%E3%83%B3/ | ||
- | * 端的に、以下の2点が守られていればとりあえず機能する。 | ||
- | * スクリプトの戻り値が、下記のいずれかであること | ||
- | * <code>0(=OK), 1(=WARNING), 2(=CRITICAL), 3(=UNKNOWN), 4(=DEPENDENT) | ||
- | * スクリプトのstdout(ようするにprintの出力)が、以下の形式であること | ||
- | * <code>ぶんしょー | こんぽーねんと=値</code> | ||
- | * 「ぶんしょー」部分は、画面出力に使用するだけ。自由に設定。 | ||
- | * パイプの後ろ側はグラフを描画するときに使用。グラフの要素名=値となるように記述。複数ある場合は半角スペースで区切る。 | ||
- | * 今回作成したスクリプト | ||
- | * <code>#!/usr/bin/perl -w | ||
- | ################################################################# | ||
- | # | ||
- | # Help : ./check_snmp_hddtemp_temp.pl -h | ||
- | # | ||
- | use strict; | ||
- | use Net::SNMP; | ||
- | use Getopt::Long; | ||
- | |||
- | # Nagios specific | ||
- | use lib "/usr/local/nagios/libexec"; | ||
- | use utils qw(%ERRORS $TIMEOUT); | ||
- | |||
- | # Net-snmp hddtemp | ||
- | # ここは人によりけりだと思うので、自分で調べる。 | ||
- | # 今思ったけど、tempratureの略をtempにしたのはアレだなぁ。 | ||
- | my $hddtemp_lines = ".1.3.6.1.4.1.8072.1.3.2.3.1.3.9.97.116.97.68.101.118.105.99.101"; | ||
- | my $hddtemp_name = ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.97.116.97.68.101.118.105.99.101"; | ||
- | my $hddtemp_temp = ".1.3.6.1.4.1.8072.1.3.2.4.1.2.20.97.116.97.68.101.118.105.99.101.84.101.109.112.101.114.97.116.117.114.101"; | ||
- | |||
- | # Globals | ||
- | my $Version= '0.1'; # version | ||
- | my $o_host= undef; # hostname | ||
- | my $o_community= undef; # community | ||
- | my $o_port= 161; # port | ||
- | my $o_help= undef; # wan't some help ? | ||
- | my $o_version= undef; # print version | ||
- | my $o_netsnmp= 1; # Check with netsnmp (default) | ||
- | my $o_warn= undef; # warning level option | ||
- | my $o_crit= undef; # Critical level option | ||
- | my $o_perf= undef; # Performance data option | ||
- | my $o_timeout= undef; # Timeout (Default 5) | ||
- | my $o_version2= undef; # use snmp v2c | ||
- | |||
- | sub print_usage { | ||
- | print "Usage: $0 [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd [-X pass -L <authp>,<privp>]) [-p <port>] -w <warn level> -c <crit level> [-f] [-t <timeout>] [-V]\n"; | ||
- | } | ||
- | |||
- | sub help { | ||
- | print "\nSNMP S.M.A.R.T. Temprature Monrotr for Nagios version ",$Version,"\n"; | ||
- | print "(c)2011 ainoniwa.net\n\n"; | ||
- | print_usage; | ||
- | print <<EOT; | ||
- | -h, --help | ||
- | print this help message | ||
- | -H, --hostname=HOST | ||
- | name or IP address of host to check | ||
- | -C, --community=COMMUNITY NAME | ||
- | community name for the host's SNMP agent (implies SNMP v1 or v2c with option) | ||
- | -2, --v2c | ||
- | Use snmp v2c | ||
- | -P, --port=PORT | ||
- | SNMP port (Default 161) | ||
- | -w, --warn=INTEGER | INT,INT | ||
- | warning level for memory in percent (0 for no checks) | ||
- | Default (-N switch) : comma separated level for Real Memory and Swap | ||
- | -I switch : warning level | ||
- | -c, --crit=INTEGER | INT,INT | ||
- | critical level for memory in percent (0 for no checks) | ||
- | Default (-N switch) : comma separated level for Real Memory and Swap | ||
- | -I switch : critical level | ||
- | -f, --perfdata | ||
- | Performance data output | ||
- | -t, --timeout=INTEGER | ||
- | timeout for SNMP in seconds (Default: 5) | ||
- | -V, --version | ||
- | prints version number | ||
- | EOT | ||
- | } | ||
- | |||
- | sub isnnum { | ||
- | my $num = shift; | ||
- | if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;} | ||
- | return 1; | ||
- | } | ||
- | |||
- | sub check_options { | ||
- | Getopt::Long::Configure ("bundling"); | ||
- | GetOptions( | ||
- | 'h' => \$o_help, 'help' => \$o_help, | ||
- | 'H:s' => \$o_host, 'hostname:s' => \$o_host, | ||
- | 'p:i' => \$o_port, 'port:i' => \$o_port, | ||
- | 'C:s' => \$o_community, 'community:s' => \$o_community, | ||
- | 't:i' => \$o_timeout, 'timeout:i' => \$o_timeout, | ||
- | 'V' => \$o_version, 'version' => \$o_version, | ||
- | 'f' => \$o_perf, 'perfdata' => \$o_perf, | ||
- | '2' => \$o_version2, 'v2c' => \$o_version2, | ||
- | 'c:s' => \$o_crit, 'critical:s' => \$o_crit, | ||
- | 'w:s' => \$o_warn, 'warn:s' => \$o_warn, | ||
- | ); | ||
- | if ( defined($o_help) ) | ||
- | { help(); exit $ERRORS{"UNKNOWN"}}; | ||
- | if ( defined($o_version)) | ||
- | { p_version(); exit $ERRORS{"UNKNOWN"}}; | ||
- | if (!defined($o_host) ) | ||
- | { print "No host defined!\n";print_usage(); exit $ERRORS{"UNKNOWN"}} | ||
- | if (!defined($o_community)) | ||
- | { print "Put snmp login info!\n";print_usage(); exit $ERRORS{"UNKNOWN"}} | ||
- | if ( ! defined($o_warn) || ! defined($o_crit)) | ||
- | { print "Put warning and critical values!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}} | ||
- | if ( isnnum($o_warn) || isnnum($o_crit)) | ||
- | { print "Numeric value for warning or critical !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}} | ||
- | if (($o_crit!= 0) && ($o_warn > $o_crit)) | ||
- | { print "warning <= critical ! \n"; print_usage(); exit $ERRORS{"UNKNOWN"}} | ||
- | if (!defined($o_timeout)) {$o_timeout=5;} | ||
- | } | ||
- | |||
- | check_options(); | ||
- | |||
- | # Connect to host | ||
- | my ($session,$error); | ||
- | if (defined ($o_version2)) { | ||
- | # SNMPv2 Login | ||
- | ($session, $error) = Net::SNMP->session( | ||
- | -hostname => $o_host, | ||
- | -version => 2, | ||
- | -community => $o_community, | ||
- | -port => $o_port, | ||
- | -timeout => $o_timeout | ||
- | ); | ||
- | } else { | ||
- | # SNMPV1 login | ||
- | ($session, $error) = Net::SNMP->session( | ||
- | -hostname => $o_host, | ||
- | -community => $o_community, | ||
- | -port => $o_port, | ||
- | -timeout => $o_timeout | ||
- | ); | ||
- | } | ||
- | if (!defined($session)) { | ||
- | printf("ERROR opening session: %s.\n", $error); | ||
- | exit $ERRORS{"UNKNOWN"}; | ||
- | } | ||
- | |||
- | # Global variable | ||
- | my $resultat=undef; | ||
- | my $result=undef; | ||
- | my @data=undef; | ||
- | my $lines=undef; | ||
- | my $name=undef; | ||
- | my $output="Temprature :"; | ||
- | my $n_status = "OK"; | ||
- | my $NAME=0; | ||
- | my $DATA=1; | ||
- | |||
- | ########### Net snmp memory check ############ | ||
- | |||
- | # Get NetSNMP hddtemp lines | ||
- | $resultat = $session->get_request($hddtemp_lines); | ||
- | if (!defined($resultat)) { | ||
- | printf("ERROR: get_request hddtemp_lines : %s.\n", $session->error); | ||
- | $session->close; | ||
- | exit $ERRORS{"UNKNOWN"}; | ||
- | } | ||
- | |||
- | # Get NetSNMP hddtemp data and ouput text create. | ||
- | $lines = $$resultat{$hddtemp_lines}; | ||
- | while ( $lines > 0) { | ||
- | $name = $session->get_request($hddtemp_name.".".$lines); | ||
- | $result = $session->get_request($hddtemp_temp.".".$lines); | ||
- | if ( !defined($name) && !defined($result) ) { | ||
- | printf("ERROR: get_request hddtemp_name : %s.\n", $session->error); | ||
- | $session->close; | ||
- | exit $ERRORS{"UNKNOWN"}; | ||
- | } | ||
- | |||
- | # '5' is length of '/dev/'. | ||
- | $data[$lines][$NAME] = substr($$name{$hddtemp_name.".".$lines},5); | ||
- | $data[$lines][$DATA] = $$result{$hddtemp_temp.".".$lines}; | ||
- | $output .= " ".$data[$lines][$NAME].":".$data[$lines][$DATA]; | ||
- | if ($data[$lines][$DATA] > $o_crit) { | ||
- | $output .= ">$o_crit!CRITICAL"; | ||
- | $n_status = "CRITICAL"; | ||
- | } else { | ||
- | if ($data[$lines][$DATA] > $o_warn) { | ||
- | $output .= ">$o_warn!WARNING"; | ||
- | $n_status = "WARNING"; | ||
- | } | ||
- | } | ||
- | $lines--; | ||
- | } | ||
- | |||
- | ### Perfdata Create | ||
- | if (defined ($o_perf)) { | ||
- | $output .= " | "; | ||
- | $lines = $$resultat{$hddtemp_lines}; | ||
- | while ( $lines > 0) { | ||
- | $output .= $data[$lines][$NAME] ."=".$data[$lines][$DATA]." "; | ||
- | $lines--; | ||
- | } | ||
- | } | ||
- | |||
- | ### Last Output. | ||
- | $session->close; | ||
- | print "$output \n"; | ||
- | exit $ERRORS{$n_status};</code> |