2011年10月5日 星期三

nagios linux nrpe設定(3)使用nagios-plugins

參考
http://nagios.sourceforge.net/docs/nrpe/NRPE.pdf
http://www.debianhelp.co.uk/nagiospluins.htm

比較:
nagios server端:192.168.1.2 ,已在web server根目錄放 index.html 的 nagios server端
client 端:192.168.1.133,web server根目錄沒東西,check_http 正常會回應 403 Forbidden

兩者在 nrpe.cfg 都沒定義  check_http ,但 command-plugins.cfg 有command[check_http]

nagios linux nrpe設定(2)-基本安裝


*被監視端:
從剛裝好完全沒東西的 VM開始…

CentOS5.5 用 rpmforge 的來源做 yum 安裝,plugins 是放在
/usr/lib64/nagios/plugins/


yum install nrpe
會安裝
fping
nagios-plugins
perl-Crypt-DES
perl-Net-SNMP

2011年10月4日 星期二

nagios linux nrpe設定

server 裝好的 localhost

CentOS5.5 用 rpmforge 的來源做 yum 安裝,plugins 是放在
/usr/lib64/nagios/plugins/

...首先
/etc/nagios/nrpe.cfg 裡的
server_address=
allow_hosts=
後面跟的 IP 不能用逗點加別的 ip (例如:192.168.2.3,127.0.0.1)
目前先試只定義 server_address 1個 IP
allow_hosts 註解掉

iptables 加上   -p tcp -m tcp --dport 5666 -j ACCEPT

nagios linux nrpe設定(5) 另外加 plugins & command(2)


想新增一項目來看Linux client端的記憶體使用情形(Windows的預設有此項目)
預設沒有此command可處理…
記錄改了多少東東…

實作完…問題在佈署

Client 端(安裝 nagios-nrpe ,nagios-nrpe-plugins)
*在 /usr/lib64/nagios/plugins/  新增command用的shell script,
記得chmod 755(權限要跟其它plugin一樣)

實作時用的是下列討論區用的 script:
http://serverfault.com/questions/195815/nagios-memory-configuration
另有一版本可參考
http://www.linuxquestions.org/questions/linux-software-2/nagios-check-ram-usage-on-remote-server-747531/
vi /usr/lib64/nagios/plugins/check_memeory.sh

#!/bin/bash
#
# Script to check memory usage on Linux. Ignores memory used by disk cache. 
#
# Requires the bc command
#
print_help() {
    echo "Usage:"
    echo "[-w] Warning level as a percentage" 
    echo "[-c] Critical level as a percentage" 
    exit 0
}

while test -n "$1"; do
    case "$1" in
        --help|-h)
            print_help
            exit 0
            ;;
        -w)
            warn_level=$2
            shift
            ;;
        -c)
            critical_level=$2
            shift
            ;;
        *)
            echo "Unknown Argument: $1"
            print_help
            exit 3
            ;;
    esac
    shift
done

if [ "$warn_level" == "" ]; then
    echo "No Warning Level Specified"
    print_help
    exit 3;
fi

if [ "$critical_level" == "" ]; then
    echo "No Critical Level Specified"
    print_help
    exit 3;
fi


free=`free -m | grep "buffers/cache" | awk '{print $4}'`
used=` free -m | grep "buffers/cache" | awk '{print $3}'`

total=$(($free+$used))

result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

if [ "$result" -lt "$warn_level" ]; then
    echo "Memory OK. $result% used."
    exit 0;
elif [ "$result" -ge "$warn_level" ] && [ "$result" -le "$critical_level" ]; then
    echo "Memory WARNING. $result% used."
    exit 1;
elif [ "$result" -gt "$critical_level" ]; then
    echo "Memory CRITICAL. $result% used."
    exit 2;
fi

chmod 755 /usr/lib64/nagios/plugins/check_memeory.sh
Client本機端試用:
sh  /usr/lib64/nagios/plugins/check_memory.sh
sh  /usr/lib64/nagios/plugins/check_memory.sh -w 80 -c 95


*在 /etc/nagios/nrpe.cfg 新增 command
##self defined## MEMORY Check
# check_mem   = MEMORY at defined warning and critical use %.
command[check_memory]=/usr/local/nagios/libexec/check_memory.sh -w $ARG1$ -c $ARG2$

service nrpe restart


Nagios Server端
*在 /etc/nagios/objects/commands.cfg 新定義 command

define command{
command_name check_memory
command_line $USER1$/check_memory.sh -w $ARG1$ -c $ARG2$
}

*在 對象設定檔.cfg 新增 service
測試對象:localhost.cfg
  vi /etc/nagios/objects/localhost.cfg
define service{
        use                   local-service;Name of service template to use
        host_name             localhost
        service_description   Memory Use
        check_command         check_memory!80!90
        }
service nagios restart

nagios linux nrpe設定(5) 另外加 plugins & command(1)


起因:看到 check_nt 可以看 Windows Client 的 memory usage ...Linux預設沒有...
由於預設沒有此command可處理,所以開始…

小記:實作記錄見下篇
*在 /usr/lib64/nagios/plugins/  新增command用的shell script,
記得chmod 755(權限要跟其它plugin一樣)
*在 /etc/nagios/objects/commands.cfg 新增 command
*在 /etc/nagios/nrpe.cfg 新增 command
*在 /etc/nagios/objects/對象設定檔.cfg 新增 service

Service definition on the server in the host config:
define service {
       use                     generic-service
       host_name               
       service_description     Memory Usage
       check_command           check_nrpe_1arg!check_memory
}
This needs to be defined in /etc/nagios/nrpe.cfg on the client, amended for the values you want to check for:
command[check_memory]=/usr/lib/nagios/plugins/check_memory.sh -w 85 -c 90
Example output:
#:~$ ./check_memory.sh -w 80 -c 90
Memory OK. 44% used.


#:~$ ./check_memory.sh -w 40 -c 50
Memory WARNING. 44% used.
The script:
#!/bin/bash
#
# Script to check memory usage on Linux. Ignores memory used by disk cache. 
#
# Requires the bc command
#
print_help() {
    echo "Usage:"
    echo "[-w] Warning level as a percentage" 
    echo "[-c] Critical level as a percentage" 
    exit 0
}

while test -n "$1"; do
    case "$1" in
        --help|-h)
            print_help
            exit 0
            ;;
        -w)
            warn_level=$2
            shift
            ;;
        -c)
            critical_level=$2
            shift
            ;;
        *)
            echo "Unknown Argument: $1"
            print_help
            exit 3
            ;;
    esac
    shift
done

if [ "$warn_level" == "" ]; then
    echo "No Warning Level Specified"
    print_help
    exit 3;
fi

if [ "$critical_level" == "" ]; then
    echo "No Critical Level Specified"
    print_help
    exit 3;
fi


free=`free -m | grep "buffers/cache" | awk '{print $4}'`
used=` free -m | grep "buffers/cache" | awk '{print $3}'`

total=$(($free+$used))

result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

if [ "$result" -lt "$warn_level" ]; then
    echo "Memory OK. $result% used."
    exit 0;
elif [ "$result" -ge "$warn_level" ] && [ "$result" -le "$critical_level" ]; then
    echo "Memory WARNING. $result% used."
    exit 1;
elif [ "$result" -gt "$critical_level" ]; then
    echo "Memory CRITICAL. $result% used."
    exit 2;
fi


2011年10月3日 星期一

nagios 小記 - Windows Client 安裝 NSClient++


* Windows Client 要安裝的 NSClient++
新版的 client 會自動加規則到內建的防火牆
但這次遇到 nagios server端的 objects/commands.cfg, 
預設 $HOSTADDRESS& -p 這段後面不是 IP,會有"server port is not interger" 之類的訊息
就算 NSClient 的設定檔不刻意設定 port ,也要在 commands.cfg 裡指定“ -p 12489

NSClient++ 安裝時(或事後更改設定檔)設定的密碼
為明碼,在 nagios server端的 objects/commands.cfg 
找到(預設應該完全沒有?)
 command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p portnumber
後面加上“ -s 密碼” 搭配使用

參考:


NSClient++ Port Forwarding and Firewall

The default port for NSClient++ is 12489
You must allow the firewall at your remote server to allow this port access.
Changing NSClient++ port:
You can change the NSClient++ port by modifying the NSC.ini file located at C:\Program Files\NSClient++ (remove “;”)
;# NSCLIENT PORT NUMBER
;  This is the port the NSClientListener.dll will listen to.
port=12489
Restart the NSClient++ service
Change check_nt -p 12489 argument in /usr/local/nagios/etc/objects/commands.cfg
# 'check_nt' command definition
define command{
        command_name    check_nt
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p portnumber -s cjr-nagios -v $ARG1$ $ARG2$
        }

參考來源:
http://nagios.sourceforge.net/docs/3_0/monitoring-windows.html
http://www.kernelhardware.org/nagios-nsclient-to-monitor-remote-windows-server/
http://www.thegeekstuff.com/2008/07/how-to-monitor-remote-windows-machine-using-nagios-on-linux/
http://creative1223.pixnet.net/blog/post/1302004


*檢查 D磁碟機,注意後面的參數是 -l  d    (小寫L)

        check_command           check_nt!USEDDISKSPACE!-l d -w 80 -c 90

http://nagiosplugins.org/man/check_disk
http://nagiosplugins.org/man/check_nt


待試:
http://nagiosplugins.org/man/check_nt
http://nagioswiki.com/wiki/index.php/Checking_NT_Services_with_Nagios

[轉貼]CentOS install Nagios

*這次實作卡在... 漏裝 gcc glibc glibc-common gd gd-devel 也沒啥差!?
…要先啟動 nagios service 再啟動 httpd ??

手工安裝(含服務、權限)...愈下文愈新
http://blog.haohtml.com/archives/4565
http://blog.prosight.me/index.php/2009/06/10
http://www.ibm.com/developerworks/cn/linux/l-ganglia-nagios-2/

http://forum.icst.org.tw/phpbb/viewtopic.php?t=17761

http://www.xtgly.com/2010/09/21/centos-5-5-nginx-nagios%E7%9B%91%E6%8E%A7%E7%AB%AF%E5%92%8C%E8%A2%AB%E6%8E%A7%E7%AB%AF%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE%E6%8C%87%E5%8D%97.htm


http://www.openfoundry.org/tw/tech-column/8308--nagios-
http://creative1223.pixnet.net/blog/category/61902

步驟詳盡…在unix下...
http://homepage.mac.com/duling/halfdozen/Nagios-Howto-p1.html
http://homepage.mac.com/duling/halfdozen/Nagios-Howto-p2.html

yum 安裝:需先下載安裝 rpmforge
http://wiki.centos.org/zh-tw/AdditionalResources/Repositories/RPMForge
http://wiki.centos.org/zh-tw/HowTos/Nagios
http://docs.cslabs.clarkson.edu/wiki/Install_Nagios_on_CentOS_5

Install

Add RPMForge Yum Repository

Install & Configure Prerequisites

  • Install Apache
    • yum install httpd php gcc glibc glibc-common gd gd-devel
  • Configure Apache to start on boot
    • /sbin/chkconfig --levels 345 httpd on
  • Configure iptables to allow Apache traffic
    • /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
    • /etc/init.d/iptables save
    • /etc/init.d/iptables restart

Install & Configure Nagios

  • Install Nagios & Plugins
    • yum install nagios nagios-plugins nagios-plugins-setuid
  • Create the default Nagios web access user & set a password
    • htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
  • Verify default config files
    • nagios -v /etc/nagios/nagios.cfg
  • Start Nagios
    • /etc/init.d/nagios start
  • Start Apache
    • /etc/init.d/httpd start

Verify Install

  • Try logging into your new Nagios installation by going to http://servername/nagios/ and logging in with nagiosadmin and the password you set.


BloggerAds