Perl实现批量装配NRPE客户端
Perl实现批量安装NRPE客户端/etc/init.d/xinetd restart?hostlist是需要安装NRPE的主机列表my @hostlist
Perl实现批量安装NRPE客户端
/etc/init.d/xinetd restart
?
hostlist是需要安装NRPE的主机列表
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是否连通
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");}