Nagios

交换机端口死活监视

#24口交换机
cd /usr/lib64/nagios/plugins
for i in {1..24}; do ./check_snmp -H IPADDRESS -C adlantis -o ifOperStatus.$i -r 1 -t 1 -m ALL;done

yum 安装客户端

yum -y --enablerepo=epel,epel-testing install nagios-plugins-all
yum -y install nagios-nrpe.x86_64 nagios-plugins-nrpe.x86_64 nrpe.x86_64
vi /etc/nagios/nrpe.cfg
#添加允许访问的服务器IP
service nrpe start

#服务器端 yum安装服务器端
/usr/lib64/nagios/plugins/check_nrpe -H hd06 N

Linux客户端安装

#!/bin/bash

wget http://downloads.sourceforge.net/nagios/nrpe-2.12.tar.gz

wget http://downloads.sourceforge.net/nagiosplug/nagios-plugins-1.4.13.tar.gz

yum -y install xinetd mysql-devel openssl-devel

/usr/sbin/useradd -d /usr/local/nagios/ -M nagios

mkdir /usr/local/nagios

chown nagios:nagios /usr/local/nagios/

tar zxvf nrpe-2.12.tar.gz

cd nrpe-2.12

./configure && make nrpe && make install-daemon && make install-daemon-config && make install-xinetd &&

cd ..

rm -rf nrpe-2.12 nrpe-2.12.tar.gz

tar zxvf nagios-plugins-1.4.13.tar.gz

cd nagios-plugins-1.4.13

./configure && make && make install &&

cp contrib/check_mem.pl /usr/local/nagios/libexec/ &&

chmod +x /usr/local/nagios/libexec/check_mem.pl &&

cd ..

rm -rf nagios-plugins-1.4.13 nagios-plugins-1.4.13.tar.gz

echo "nrpe            5666/tcp                        # NRPE" >> /etc/services

sed -i '/only_from/a\        only_from       = 10.100.11.223' /etc/xinetd.d/nrpe   #此处需要修改为服务器IP

sed -i 's/_hda1/_disk/' /usr/local/nagios/etc/nrpe.cfg
sed -i 's/\/dev\/hda1/\//' /usr/local/nagios/etc/nrpe.cfg
sed -i '/check_total_procs/a\command[check_mem]=/usr/local/nagios/libexec/check_mem.pl -f -w 10 -c 5' /usr/local/nagios/etc/nrpe.cfg
sed -i '/check_total_procs/a\command[check_ssh]=/usr/local/nagios/libexec/check_ssh -H 127.0.0.1' /usr/local/nagios/etc/nrpe.cfg
sed -i '/check_total_procs/a\command[check_http]=/usr/local/nagios/libexec/check_http -H 127.0.0.1' /usr/local/nagios/etc/nrpe.cfg
sed -i '/check_total_procs/a\command[check_mysql]=/usr/local/nagios/libexec/check_mysql -H 127.0.0.1 -u root' /usr/local/nagios/etc/nrpe.cfg

/etc/init.d/xinetd start

/sbin/chkconfig nrpe on

netstat -an|grep 5666

echo "Install complete"

Solaris客户端安装

#!/bin/bash

PATH=/usr/sfw/bin:/usr/ccs/bin:/usr/sfw/sbin:$PATH
export PATH
echo "nameserver 219.170.122.170" >> resolv.conf

mkdir -p /usr/local/nagios
/usr/sbin/useradd -d /usr/local/nagios/ -m nagios
/usr/sbin/groupadd nagios
chown nagios:nagios /usr/local/nagios/

wget ftp://ftp.ring.gr.jp/pub/GNU/make/make-3.81.tar.gz
gunzip -c make-3.81.tar.gz|tar -xvf -
cd make-3.81
./configure --prefix=/usr/local/ && make && make install

mv /usr/ccs/bin/make /usr/ccs/bin/make.orig
ln -s /usr/local/bin/make /usr/ccs/bin/make


wget http://downloads.sourceforge.net/nagiosplug/nagios-plugins-1.4.13.tar.gz
gunzip -c nagios-plugins-1.4.13.tar.gz |tar -xvf -
cd nagios-plugins-1.4.13
./configure --without-ipv6 --with-nagios-user=nagios --with-nagios-group=nagios --without-mysql
make && make install
cp contrib/check_mem.pl /usr/local/nagios/libexec/
chmod +x /usr/local/nagios/libexec/check_mem.pl



wget http://downloads.sourceforge.net/nagios/nrpe-2.12.tar.gz
gunzip -c nrpe-2.12.tar.gz | tar -xvf -
cd nrpe-2.12
./configure --enable-command-args --disable-ssl
sed '616,619d' src/nrpe.c > /tmp/nrpe.c.tmp
mv /tmp/nrpe.c.tmp src/nrpe.c
make all && make install && make install-plugin && make install-daemon-config

echo '#!/usr/bin/perl -w' > /usr/local/nagios/libexec/check_procs2
echo '#' >> /usr/local/nagios/libexec/check_procs2
echo '# This Nagios plug-in checks the existence of processes' >> /usr/local/nagios/libexec/check_procs2
echo '#' >> /usr/local/nagios/libexec/check_procs2
echo '# check_procs2 <process name> <relation> <number> ...' >> /usr/local/nagios/libexec/check_procs2
echo '#' >> /usr/local/nagios/libexec/check_procs2
echo '# where <relation> can be' >> /usr/local/nagios/libexec/check_procs2
echo '#    eq        equal' >> /usr/local/nagios/libexec/check_procs2
echo '#    gt        greater than' >> /usr/local/nagios/libexec/check_procs2
echo '#    ge        greater equal' >> /usr/local/nagios/libexec/check_procs2
echo '#    lt        less than' >> /usr/local/nagios/libexec/check_procs2
echo '#    le        less equal' >> /usr/local/nagios/libexec/check_procs2
echo '#' >> /usr/local/nagios/libexec/check_procs2
echo '# Example:' >> /usr/local/nagios/libexec/check_procs2
echo '#    check_procs2 sendmail gt 2' >> /usr/local/nagios/libexec/check_procs2
echo '#' >> /usr/local/nagios/libexec/check_procs2
echo '# Michael Hocke, NYU, 6/16/2006' >> /usr/local/nagios/libexec/check_procs2
echo '' >> /usr/local/nagios/libexec/check_procs2
echo 'use strict;' >> /usr/local/nagios/libexec/check_procs2
echo '' >> /usr/local/nagios/libexec/check_procs2
echo 'my $ME = substr ("/usr/bin/perl -w $0 " . join (" ", @ARGV), 0, 79);' >> /usr/local/nagios/libexec/check_procs2
echo 'my $USAGE = "$0: <process name> <relation> <number> [and] ...\n";' >> /usr/local/nagios/libexec/check_procs2
echo '' >> /usr/local/nagios/libexec/check_procs2
echo '# parse command line and store rules' >> /usr/local/nagios/libexec/check_procs2
echo 'my %rules;' >> /usr/local/nagios/libexec/check_procs2
echo '' >> /usr/local/nagios/libexec/check_procs2
echo 'if ($#ARGV == -1) {' >> /usr/local/nagios/libexec/check_procs2
echo '  print $USAGE;' >> /usr/local/nagios/libexec/check_procs2
echo '  exit 3;' >> /usr/local/nagios/libexec/check_procs2
echo '}' >> /usr/local/nagios/libexec/check_procs2
echo '' >> /usr/local/nagios/libexec/check_procs2
echo 'my $parm = 0;' >> /usr/local/nagios/libexec/check_procs2
echo 'while ($parm <= $#ARGV) {' >> /usr/local/nagios/libexec/check_procs2
echo '  if ($ARGV[$parm] eq "and") {' >> /usr/local/nagios/libexec/check_procs2
echo '    if ($parm == 0 or $parm == $#ARGV) {' >> /usr/local/nagios/libexec/check_procs2
echo '      print "$0: dangling 'and'\n";' >> /usr/local/nagios/libexec/check_procs2
echo '      exit 3;' >> /usr/local/nagios/libexec/check_procs2
echo '    }' >> /usr/local/nagios/libexec/check_procs2
echo '    $parm ++;' >> /usr/local/nagios/libexec/check_procs2
echo '  } elsif ($ARGV[$parm] eq "or") {' >> /usr/local/nagios/libexec/check_procs2
echo '    print "$0: 'or' operator not implemented (yet)\n";' >> /usr/local/nagios/libexec/check_procs2
echo '    exit 3;' >> /usr/local/nagios/libexec/check_procs2
echo '  } elsif ($parm + 2 > $#ARGV) {' >> /usr/local/nagios/libexec/check_procs2
echo '    print "$0: incomplete expression\n";' >> /usr/local/nagios/libexec/check_procs2
echo '    exit 3;' >> /usr/local/nagios/libexec/check_procs2
echo '  } else {' >> /usr/local/nagios/libexec/check_procs2
echo '    my ($crit_level, $warn_level) = split /:/, $ARGV[$parm + 2];' >> /usr/local/nagios/libexec/check_procs2
echo '    $rules{$ARGV[$parm]} = [$ARGV[$parm + 1], $crit_level, $warn_level, 0];' >> /usr/local/nagios/libexec/check_procs2
echo '    $parm += 3;' >> /usr/local/nagios/libexec/check_procs2
echo '  }' >> /usr/local/nagios/libexec/check_procs2
echo '}' >> /usr/local/nagios/libexec/check_procs2
echo '' >> /usr/local/nagios/libexec/check_procs2
echo '# get content of process table and match process names' >> /usr/local/nagios/libexec/check_procs2
echo 'my $proc_no = 0;' >> /usr/local/nagios/libexec/check_procs2
echo 'open PS, "/usr/bin/ps -e -o comm |";' >> /usr/local/nagios/libexec/check_procs2
echo 'my $skip_header = <PS>;' >> /usr/local/nagios/libexec/check_procs2
echo 'while (<PS>) {' >> /usr/local/nagios/libexec/check_procs2
echo '  chomp;' >> /usr/local/nagios/libexec/check_procs2
echo '  $proc_no ++;' >> /usr/local/nagios/libexec/check_procs2
echo '  next if ($_ eq $ME);' >> /usr/local/nagios/libexec/check_procs2
echo '  for my $pattern (keys %rules) {' >> /usr/local/nagios/libexec/check_procs2
echo '    if (/$pattern/) {' >> /usr/local/nagios/libexec/check_procs2
echo '      #print "MATCH ($pattern) $_";' >> /usr/local/nagios/libexec/check_procs2
echo '      $rules{$pattern}[3] ++;' >> /usr/local/nagios/libexec/check_procs2
echo '    }' >> /usr/local/nagios/libexec/check_procs2
echo '  }' >> /usr/local/nagios/libexec/check_procs2
echo '}' >> /usr/local/nagios/libexec/check_procs2
echo 'close PS;' >> /usr/local/nagios/libexec/check_procs2
echo '' >> /usr/local/nagios/libexec/check_procs2
echo '# go through all rules and see if all conditions are met' >> /usr/local/nagios/libexec/check_procs2
echo 'sub add_result {' >> /usr/local/nagios/libexec/check_procs2
echo '  my ($met, $rule, $want, $is, $prev_result) = @_;' >> /usr/local/nagios/libexec/check_procs2
echo '  my $str = "";' >> /usr/local/nagios/libexec/check_procs2
echo '  if (not $met) {' >> /usr/local/nagios/libexec/check_procs2
echo '    $str .= ", " if ($prev_result);' >> /usr/local/nagios/libexec/check_procs2
echo '    $str .= "$rule: $is/$want";' >> /usr/local/nagios/libexec/check_procs2
echo '  }' >> /usr/local/nagios/libexec/check_procs2
echo '  return $str;' >> /usr/local/nagios/libexec/check_procs2
echo '}' >> /usr/local/nagios/libexec/check_procs2
echo '' >> /usr/local/nagios/libexec/check_procs2
echo 'my $crit_result = "";' >> /usr/local/nagios/libexec/check_procs2
echo 'my $warn_result = "";' >> /usr/local/nagios/libexec/check_procs2
echo 'for my $rule (keys %rules) {' >> /usr/local/nagios/libexec/check_procs2
echo '  my $op = $rules{$rule}->[0];' >> /usr/local/nagios/libexec/check_procs2
echo '  my $crit_want = $rules{$rule}->[1];' >> /usr/local/nagios/libexec/check_procs2
echo '  my $warn_want = $rules{$rule}->[2];' >> /usr/local/nagios/libexec/check_procs2
echo '  my $is = $rules{$rule}->[3];' >> /usr/local/nagios/libexec/check_procs2
echo '  if ($op eq "eq") {' >> /usr/local/nagios/libexec/check_procs2
echo '    $crit_result .= add_result ($is == $crit_want, $rule, $crit_want, $is, $crit_result) if (defined $crit_want);' >> /usr/local/nagios/libexec/check_procs2
echo '    $warn_result .= add_result ($is == $warn_want, $rule, $warn_want, $is, $warn_result) if (defined $warn_want);' >> /usr/local/nagios/libexec/check_procs2
echo '  } elsif ($op eq "ge") {' >> /usr/local/nagios/libexec/check_procs2
echo '    $crit_result .= add_result ($is >= $crit_want, $rule, $crit_want, $is, $crit_result) if (defined $crit_want);' >> /usr/local/nagios/libexec/check_procs2
echo '    $warn_result .= add_result ($is >= $warn_want, $rule, $warn_want, $is, $warn_result) if (defined $warn_want);' >> /usr/local/nagios/libexec/check_procs2
echo '  } elsif ($op eq "gt") {' >> /usr/local/nagios/libexec/check_procs2
echo '    $crit_result .= add_result ($is > $crit_want, $rule, $crit_want, $is, $crit_result) if (defined $crit_want);' >> /usr/local/nagios/libexec/check_procs2
echo '    $warn_result .= add_result ($is > $warn_want, $rule, $warn_want, $is, $warn_result) if (defined $warn_want);' >> /usr/local/nagios/libexec/check_procs2
echo '  } elsif ($op eq "le") {' >> /usr/local/nagios/libexec/check_procs2
echo '    $crit_result .= add_result ($is <= $crit_want, $rule, $crit_want, $is, $crit_result) if (defined $crit_want);' >> /usr/local/nagios/libexec/check_procs2
echo '    $warn_result .= add_result ($is <= $warn_want, $rule, $warn_want, $is, $warn_result) if (defined $warn_want);' >> /usr/local/nagios/libexec/check_procs2
echo '  } elsif ($op eq "lt") {' >> /usr/local/nagios/libexec/check_procs2
echo '    $crit_result .= add_result ($is < $crit_want, $rule, $crit_want, $is, $crit_result) if (defined $crit_want);' >> /usr/local/nagios/libexec/check_procs2
echo '    $warn_result .= add_result ($is < $warn_want, $rule, $warn_want, $is, $warn_result) if (defined $warn_want);' >> /usr/local/nagios/libexec/check_procs2
echo '  }' >> /usr/local/nagios/libexec/check_procs2
echo '}' >> /usr/local/nagios/libexec/check_procs2
echo '' >> /usr/local/nagios/libexec/check_procs2
echo '# return result' >> /usr/local/nagios/libexec/check_procs2
echo 'if ($crit_result) {' >> /usr/local/nagios/libexec/check_procs2
echo '  print "PROCS CRITICAL: $proc_no processes - $crit_result\n";' >> /usr/local/nagios/libexec/check_procs2
echo '  exit 2;' >> /usr/local/nagios/libexec/check_procs2
echo '} elsif ($warn_result) {' >> /usr/local/nagios/libexec/check_procs2
echo '  print "PROCS WARNING: $proc_no processes - $warn_result\n";' >> /usr/local/nagios/libexec/check_procs2
echo '  exit 1;' >> /usr/local/nagios/libexec/check_procs2
echo '} else {' >> /usr/local/nagios/libexec/check_procs2
echo '  print "PROCS OK: $proc_no processes - no problems found\n";' >> /usr/local/nagios/libexec/check_procs2
echo '  exit 0;' >> /usr/local/nagios/libexec/check_procs2
echo '}' >> /usr/local/nagios/libexec/check_procs2

chmod +x /usr/local/nagios/libexec/check_procs2

sed -e "s/_hda1/_disk/" \
-e "s/\/dev\/hda1/\//" \
-e "s/allowed_hosts=127.0.0.1/allowed_hosts=127.0.0.1\,10.100.11.223/" \
-e "s/check_procs -w 150 -c 200/check_procs2 cbserver ge 2/" \
/usr/local/nagios/etc/nrpe.cfg > /tmp/nrpe.cfg.tmp
echo "command[check_mem]=/usr/local/nagios/libexec/check_mem.pl -f -w 10 -c 5" >> /tmp/nrpe.cfg.tmp
echo "command[check_ssh]=/usr/local/nagios/libexec/check_ssh -H 127.0.0.1" >> /tmp/nrpe.cfg.tmp

mv /tmp/nrpe.cfg.tmp /usr/local/nagios/etc/nrpe.cfg

echo "nrpe            5666/tcp                        # NRPE" >> /etc/services
echo "nrpe stream tcp nowait nagios /usr/sfw/sbin/tcpd /usr/local/nagios/bin/nrpe -n -c /usr/local/nagios/etc/nrpe.cfg -i" >> /etc/inet/inetd.conf
inetconv
inetconv -e
inetadm -m svc:/network/nrpe/tcp:default tcp_wrappers=TRUE

netstat -an|grep 5666
svcs |grep nrpe
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -n

echo "Install complete"
/var/lib/openshift/bccd8eac1968476490eaee9ced33c7bf/app-root/runtime/repo/php/data/pages/nagios.txt · 最后更改: 2012/09/07 09:21 (外部编辑)
到顶部
CC Attribution-Noncommercial-Share Alike 3.0 Unported
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0