`

Perl实现批量安装NRPE客户端

 
阅读更多

近期要安装N多台Linux主机的NRPE客户端,话说我这么“懒”的人怎么可能会一个个自己安.批量处理的简单小程序就用perl来做吧!

 

# tar -tf BatchNrpe.tar.gz
BatchNrpe/
BatchNrpe/install.sh
BatchNrpe/Check_Nrpe.pl
BatchNrpe/nrpe-2.15.tar.gz
BatchNrpe/Batch_Installation_Nrpe.pl
BatchNrpe/hostlist
BatchNrpe/nagios-plugins-1.5.tar.gz

BatchNrpe.tar.gz为主主程序包.

 

install.sh是自动部署NRPE的Shell脚本

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

 

hostlist是需要安装NRPE的主机列表

#IC Server

#格式 IP->密码
172.20.105.1->sunnorth
172.20.105.2->sunnorth
172.20.105.3->7234567
172.20.105.4->1128@123
172.20.105.5->8888@321
172.20.105.6->ggggggg@
172.20.105.7->sunnorth
172.20.105.8->9999990000@
172.20.105.9->sun

 

 

nagios-plugins-1.5.tar.gz  nrpe-2.15.tar.gz是安装必须要的Tarball

 

Batch_Installation_Nrpe.pl用于自动scp必要的Tarball和install.sh安装脚本至hostlist列表主机

#!/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");
}

分享到:
评论

相关推荐

    nagios客户端安装nrpe.rar

    安装包已经 安装说明 具体如下 nagios-plugins-2.2.1.tar.gz nagios-plugins-2.2.1.tar.gz xinetd-2.3.14-40.el6.x86_64.rpm 安装说明.txt 、、、、、、、、、、、

    nrped:在go中实现的nrpe客户端和服务器

    GO NRPE-Nagios远程插件执行器 状态:已维护 内容 此附加组件有两部分: NRPE-该程序在远程主机上作为后台进程运行,并处理Nagios主机上check_nrpe插件发出的命令执行请求。 收到来自授权主机的插件请求后,它将...

    NRPE-3.2.1安装手册

    当前2018年,nagios监控客户端需要安装的NRPE,最新3.2.1版本手册,英文版

    开源项目-envimate-nrpe.zip

    开源项目-envimate-nrpe.zip,支持SSL的Golang中的NRPE客户端和服务器实现

    nagios+nrpe详细安装配置

    服务器状态监控软件安装部署和配置指导文档

    icinga-nrpe-2.14.tar.zip

    icinga-nrpe.2.14.tar.gz icinga客户端安装包 安装在被检测服务器端 service icinga-nrpe start

    NAGIOS代理程序NRPE 2.15

    NAGIOS的监控代理,NRPE 2.15.

    nrpe及配置說明

    nrpe及配置說明,非常詳細,下載會有很大的驚喜

    nrpe-2.15

    nrpe-2.15

    nrpe-2.13.tar.gz

    nrpe-2.13.tar.gz nrpe-2.13 nrpe

    nrpe-2.15.tar.gz

    nrpe 2.15 .tar.gz格式。 site:http://www.nrpe.org nrpe-2.15.tar.gz 源代码。

    Nagios+Centreon+Nrpe+PHP+Mysql+NSClient完全安装

    一个全攻略的Nagios+Centreon+Nrpe+PHP+Mysql+NSClient完全安装

    nrpe3.1版本的官方说明

    NRPE是监控软件nagios的一个扩展,它被用于被监控的服务器上,向nagios监控平台提供该服务器的一些本地的情况。

    nrpe-3.1.0.tar.gz

    NRPE是监控软件nagios的一个扩展,它被用于被监控的服务器上,向nagios监控平台提供该服务器的一些本地的情况。例如,cpu负载、内存使用、硬盘使用等等。NRPE可以称为nagios的for linux 客户端。

    nagios nrpe

    naigos 集群套件 远程监控管理模块 nrpe 。。。

    nrpe-2.12.tar.gz

    nagios客户端,使用nagios服务器监控的客户端,该客户端安装在被监控的主机上,和nagios服务器相配合使用

    nrpe-3.0.1.tar.gz

    nrpe-3.0.1.tar.gz

    nrpe安装过程.docx

    2安装nagios插件 解压缩 tar -zxvf nagios-plugins-1.4.9.tar.gz cd nagios-plugins-1.4.9 编译安装 ./configure make make install 这一步完成后会在/usr/local/nagios/下生成两个目录libexec和share [root@dbpi ...

    nrpe监控mysql.docx

    nagios监控mysql服务器: 1、建立专用数据库: [root@svr3 ~]# /usr/local/webserver/mysql/bin/mysql -u root -p Enter password: Welcome to the MySQL monitor.... or \g. Your MySQL connection id is 51910 ...

    nrpe-2.9.tar.gz

    nagios主动检测插件,主要实现nagios的主动检测机制,网上其他地方没有哦!

Global site tag (gtag.js) - Google Analytics