useradd nagios /bin/tar -zxvf nagios-plugins-1.5.tar.gz cd nagios-plugins-1.5 ./configure make make install /bin/chown nagios.nagios /usr/local/nagios cd .. yum -y install xinetd --nogpgcheck /bin/tar -zxvf nrpe-2.15.tar.gz cd nrpe-2.15 ./configure make all make install-plugin make install-daemon make install-daemon-config make install-xinetd perl -i -p -e 's/(127.0.0.1)/$1 172.20.11.2/' /etc/xinetd.d/nrpe echo "nrpe 5666/tcp # nrpe" >> /etc/services /etc/init.d/xinetd restart
#!/bin/env perl # # This program is used to batch install NRPE # # # Created : Yumeng # Creation Date : 4 December 2013 # # E-mail : mixmaomao@163.com # # Use Statement # use strict; use warnings; use Expect; # # Read the installation list # File Format: IP address->Passwd # such as : 172.20.1.1->password # open HOSTLIST,"<","hostlist" or die "Can't open file :$!\n"; my @hostlist = <HOSTLIST>; close HOSTLIST; # my %hostlist; for (@hostlist) { chomp; next if m{^#}; my $host; my $pass; $host = (split(/\->/))[0]; $pass = (split(/\->/))[1]; $hostlist{$host}=$pass; } # # Login host # while (my ($host,$pass)=each %hostlist) { my $exp_scp = Expect->new; $exp_scp = Expect->spawn("scp install.sh nagios-plugins-1.5.tar.gz nrpe-2.15.tar.gz $host:/root"); $exp_scp->expect(2, [ 'password', sub { my $self_scp = shift; $self_scp->send("$pass\n"); } ], [ '\(yes/no\)?', sub { my $self_scp = shift; $self_scp->send("yes\n"); exp_continue; } ], ); #$exp->send("exit\n") if ($exp->expect(undef,'#')); my $exp_ssh = Expect->spawn("ssh $host"); $exp_ssh->expect(2, [ 'password', sub { my $self = shift; $self->send("$pass\n"); } ], [ '\(yes/no\)?', sub { my $self = shift; $self->send("yes\n"); exp_continue; } ], ); $exp_ssh->send("sh install.sh\n") if ($exp_ssh->expect(undef,'#')); $exp_ssh->send("exit\n") if ($exp_ssh->expect(undef,'#')); }
Check_Nrpe.pl用于检测NRPE是否连通
#!/bin/env perl open HOSTLIST,"<","hostlist" or die "Can't open file :$!\n"; my @hostlist = <HOSTLIST>; close HOSTLIST; for (@hostlist) { chomp; next if m{^#}; my $host; $host = (split(/\->/))[0]; system("/usr/local/nagios/libexec/check_nrpe -H $host"); }