mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-31 01:56:39 +00:00
Merge pull request #1216 from hu-weihua/xcatprobe
The code of xcat probe component
This commit is contained in:
commit
1578038632
341
xCAT-probe/lib/perl/probe_utils.pm
Normal file
341
xCAT-probe/lib/perl/probe_utils.pm
Normal file
@ -0,0 +1,341 @@
|
||||
package probe_utils;
|
||||
|
||||
# IBM(c) 2016 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
use strict;
|
||||
use File::Path;
|
||||
use File::Copy;
|
||||
|
||||
#-----------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Format output message depending on probe framework requirement
|
||||
Format is [<flag>] : <message>
|
||||
The valid <flag> are debug, warning, failed and ok
|
||||
Arguments:
|
||||
output: where should output the message
|
||||
num: the number of <flag>
|
||||
d: debug
|
||||
w: warning
|
||||
f: failed
|
||||
o: ok
|
||||
msg: the information need to output
|
||||
Returns:
|
||||
1 : Failed
|
||||
0 : success
|
||||
=cut
|
||||
|
||||
#----------------------------------------
|
||||
sub send_msg {
|
||||
my $output = shift;
|
||||
$output = shift if (($output) && ($output =~ /probe_utils/));
|
||||
my $tag = shift;
|
||||
my $msg = shift;
|
||||
my $flag;
|
||||
|
||||
if ($tag eq "d") {
|
||||
$flag = "[debug] :";
|
||||
} elsif ($tag eq "w") {
|
||||
$flag = "[warning]:";
|
||||
} elsif ($tag eq "f") {
|
||||
$flag = "[failed] :";
|
||||
} elsif ($tag eq "o") {
|
||||
$flag = "[ok] :";
|
||||
}
|
||||
|
||||
if ($output eq "stdout") {
|
||||
print "$flag $msg\n";
|
||||
} else {
|
||||
if (!open(LOGFILE, ">> $output")) {
|
||||
return 1;
|
||||
}
|
||||
print LOGFILE "$flag $msg\n";
|
||||
close LOGFILE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Test if a string is a IP address
|
||||
Arguments:
|
||||
addr: the string want to be judged
|
||||
Returns:
|
||||
1 : yes
|
||||
0 : no
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub is_ip_addr {
|
||||
my $addr = shift;
|
||||
$addr = shift if (($addr) && ($addr =~ /probe_utils/));
|
||||
return 0 unless ($addr);
|
||||
return 0 if ($addr !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
|
||||
return 0 if ($1 > 255 || $1 == 0 || $2 > 255 || $3 > 255 || $4 > 255);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Test if a IP address belongs to a network
|
||||
Arguments:
|
||||
net : network address, such like 10.10.10.0
|
||||
mask: network mask. suck like 255.255.255.0
|
||||
ip: a ip address
|
||||
Returns:
|
||||
1 : yes
|
||||
0 : no
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub is_ip_belong_to_net {
|
||||
my $net = shift;
|
||||
$net = shift if (($net) && ($net =~ /probe_utils/));
|
||||
my $mask = shift;
|
||||
my $targetip = shift;
|
||||
|
||||
return 0 if ($net !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
|
||||
return 0 if ($mask !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
|
||||
return 0 if (!is_ip_addr($targetip));
|
||||
|
||||
my $bin_mask = 0;
|
||||
$bin_mask = (($1 + 0) << 24) + (($2 + 0) << 16) + (($3 + 0) << 8) + ($4 + 0) if ($mask =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
|
||||
|
||||
my $bin_ip = 0;
|
||||
$bin_ip = (($1 + 0) << 24) + (($2 + 0) << 16) + (($3 + 0) << 8) + ($4 + 0) if ($targetip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
|
||||
|
||||
my $tmp_net = $bin_mask & $bin_ip;
|
||||
|
||||
my $bin_net = 0;
|
||||
$bin_net = (($1 + 0) << 24) + (($2 + 0) << 16) + (($3 + 0) << 8) + ($4 + 0) if ($net =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
|
||||
|
||||
return 0 if ($tmp_net != $bin_net);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Get distro name of current operating system
|
||||
Arguments:
|
||||
None
|
||||
Returns:
|
||||
A string, include value are sles, redhat and ubuntu
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub get_os {
|
||||
my $os = "unknown";
|
||||
my $output = `cat /etc/*release* 2>&1`;
|
||||
if ($output =~ /suse/i) {
|
||||
$os = "sles";
|
||||
} elsif ($output =~ /Red Hat/i) {
|
||||
$os = "redhat";
|
||||
} elsif ($output =~ /ubuntu/i) {
|
||||
$os = "ubuntu";
|
||||
}
|
||||
|
||||
return $os;
|
||||
}
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Test if a IP address is a static IP address
|
||||
Arguments:
|
||||
ip: a ip address
|
||||
nic: the network adapter which ip belongs to
|
||||
Returns:
|
||||
1 : yes
|
||||
0 : no
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub is_static_ip {
|
||||
my $ip = shift;
|
||||
$ip = shift if (($ip) && ($ip =~ /probe_utils/));
|
||||
my $nic = shift;
|
||||
my $os = get_os();
|
||||
my $rst = 0;
|
||||
|
||||
if ($os =~ /redhat/) {
|
||||
my $output1 = `cat /etc/sysconfig/network-scripts/ifcfg-$nic 2>&1 |grep -i IPADDR`;
|
||||
my $output2 = `cat /etc/sysconfig/network-scripts/ifcfg-$nic 2>&1 |grep -i BOOTPROTO`;
|
||||
$rst = 1 if (($output1 =~ /$ip/) && ($output2 =~ /static/i));
|
||||
} elsif ($os =~ /sles/) {
|
||||
my $output1 = `cat /etc/sysconfig/network/ifcfg-$nic 2>&1 |grep -i IPADDR`;
|
||||
my $output2 = `cat /etc/sysconfig/network/ifcfg-$nic 2>&1 |grep -i BOOTPROTO`;
|
||||
$rst = 1 if (($output1 =~ /$ip/) && ($output2 =~ /static/i));
|
||||
} elsif ($os =~ /ubuntu/) {
|
||||
my $output = `cat /etc/network/interfaces 2>&1|grep -E "iface\s+$nic"`;
|
||||
$rst = 1 if ($output =~ /static/i);
|
||||
}
|
||||
return $rst;
|
||||
}
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Test if SELinux is opened in current operating system
|
||||
Arguments:
|
||||
None
|
||||
Returns:
|
||||
1 : yes
|
||||
0 : no
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub is_selinux_enable {
|
||||
if (-e "/usr/sbin/selinuxenabled") {
|
||||
`/usr/sbin/selinuxenabled`;
|
||||
if ($? == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Test if firewall is opened in current operating system
|
||||
Arguments:
|
||||
None
|
||||
Returns:
|
||||
1 : yes
|
||||
0 : no
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub is_firewall_open {
|
||||
my $os = get_os();
|
||||
my $output;
|
||||
my $rst = 0;
|
||||
|
||||
if ($os =~ /redhat/) {
|
||||
$output = `service iptables status 2>&1`;
|
||||
$rst = 1 if ($output =~ /running/i);
|
||||
} elsif ($os =~ /sles/) {
|
||||
$output = `service SuSEfirewall2_setup status`;
|
||||
$rst = 1 if ($output =~ /running/i);
|
||||
} elsif ($os =~ /ubuntu/) {
|
||||
$output = `ufw status`;
|
||||
$rst = 1 if ($output =~ /Status: active/i);
|
||||
}
|
||||
return $rst;
|
||||
}
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Test if http service is ready to use in current operating system
|
||||
Arguments:
|
||||
ip: http server's ip
|
||||
Returns:
|
||||
1 : yes
|
||||
0 : no
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub is_http_ready {
|
||||
my $mnip = shift;
|
||||
$mnip = shift if (($mnip) && ($mnip =~ /probe_utils/));
|
||||
|
||||
my $http = "http://$mnip/install/postscripts/syslog";
|
||||
rename("./syslog", "./syslog.org") if (-e "./syslog");
|
||||
|
||||
my $outputtmp = `wget $http 2>&1`;
|
||||
my $rst = $?;
|
||||
if (($outputtmp =~ /200 OK/) && (!$rst) && (-e "./syslog")) {
|
||||
unlink("./syslog");
|
||||
rename("./syslog.org", "./syslog") if (-e "./syslog.org");
|
||||
return 1;
|
||||
} else {
|
||||
rename("./syslog.org", "./syslog") if (-e "./syslog.org");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Test if tftp service is ready to use in current operating system
|
||||
Arguments:
|
||||
ip: tftp server's ip
|
||||
Returns:
|
||||
1 : yes
|
||||
0 : no
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub is_tftp_ready {
|
||||
my $mnip = shift;
|
||||
$mnip = shift if (($mnip) && ($mnip =~ /probe_utils/));
|
||||
|
||||
rename("/tftpboot/tftptestt.tmp", "/tftpboot/tftptestt.tmp.old") if (-e "/tftpboot/tftptestt.tmp");
|
||||
rename("./tftptestt.tmp", "./tftptestt.tmp.old") if (-e "./tftptestt.tmp");
|
||||
|
||||
system("touch /tftpboot/tftptestt.tmp");
|
||||
my $output = `tftp -4 -v $mnip -c get tftptestt.tmp`;
|
||||
if ((!$?) && (-e "./tftptestt.tmp")) {
|
||||
unlink("./tftptestt.tmp");
|
||||
rename("./tftptestt.tmp.old", "./tftptestt.tmp") if (-e "./tftptestt.tmp.old");
|
||||
rename("/tftpboot/tftptestt.tmp.old", "/tftpboot/tftptestt.tmp") if (-e "/tftpboot/tftptestt.tmp.old");
|
||||
return 1;
|
||||
} else {
|
||||
rename("./tftptestt.tmp.old", "./tftptestt.tmp") if (-e "./tftptestt.tmp.old");
|
||||
rename("/tftpboot/tftptestt.tmp.old", "/tftpboot/tftptestt.tmp") if (-e "/tftpboot/tftptestt.tmp.old");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#------------------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Test if DNS service is ready to use in current operating system
|
||||
Arguments:
|
||||
ip: DNS server's ip
|
||||
Returns:
|
||||
1 : yes
|
||||
0 : no
|
||||
=cut
|
||||
|
||||
#------------------------------------------
|
||||
sub is_dns_ready {
|
||||
my $mnip = shift;
|
||||
$mnip = shift if (($mnip) && ($mnip =~ /probe_utils/));
|
||||
my $hostname = shift;
|
||||
my $domain = shift;
|
||||
|
||||
my $output = `nslookup $mnip $mnip 2>&1`;
|
||||
|
||||
if ($?) {
|
||||
return 0;
|
||||
} else {
|
||||
chomp($output);
|
||||
my $tmp = `echo "$output" |grep "Server:[\t\s]*$mnip" >/dev/null 2>&1`;
|
||||
print "$tmp";
|
||||
return 0 if ($?);
|
||||
$tmp = `echo "$output"|grep "name ="|grep "$hostname\.$domain" >/dev/null 2>&1`;
|
||||
return 0 if ($?);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
550
xCAT-probe/subcmds/xcatmn
Executable file
550
xCAT-probe/subcmds/xcatmn
Executable file
@ -0,0 +1,550 @@
|
||||
#! /usr/bin/perl
|
||||
# IBM(c) 2016 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; }
|
||||
|
||||
use lib "$::XCATROOT/probe/lib/perl";
|
||||
use probe_utils;
|
||||
use File::Basename;
|
||||
use Getopt::Long qw(:config no_ignore_case);
|
||||
|
||||
my $proname = basename("$0");
|
||||
my $help;
|
||||
my $installnic;
|
||||
my $test;
|
||||
my $output = "stdout";
|
||||
my $verbose = 0;
|
||||
my $rst = 0;
|
||||
|
||||
$::USAGE = "Usage:
|
||||
$proname -h
|
||||
$proname -t
|
||||
$proname [-n] <install_nic> [-V]
|
||||
|
||||
Description:
|
||||
After xcat installation, use this command to check if xcat has been installed correctly and is ready for use.
|
||||
|
||||
Options:
|
||||
-h : Get usage information of $proname
|
||||
-t : To verify if $proname can work, reserve option for probe framework
|
||||
-n : Required. Specify the network interface name of provision network
|
||||
-V : Output more information for debug
|
||||
";
|
||||
|
||||
sub returncmdoutput {
|
||||
my $rst = shift;
|
||||
chomp($rst);
|
||||
my @lines = split("[\n\r]", $rst);
|
||||
foreach my $line (@lines) {
|
||||
probe_utils->send_msg("$output", "d", "$line");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------
|
||||
# main process
|
||||
#-------------------------------------
|
||||
if (
|
||||
!GetOptions("--help|h" => \$help,
|
||||
"t" => \$test,
|
||||
"V" => \$verbose,
|
||||
"n=s" => \$installnic))
|
||||
{
|
||||
probe_utils->send_msg("$output", "f", "Invalid parameter for $proname");
|
||||
probe_utils->send_msg("$output", "d", "$::USAGE");
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if ($help) {
|
||||
if ($output ne "stdout") {
|
||||
probe_utils->send_msg("$output", "d", "$::USAGE");
|
||||
} else {
|
||||
print "$::USAGE";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ($test) {
|
||||
probe_utils->send_msg("$output", "o", "After xcat installation, use this command to check if xcat has been installed correctly and is ready for use. Before using this command, please install tftp, nslookup and wget commands ahead. The platform supported are redhat, sles and ubuntu.");
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if (!defined($installnic)) {
|
||||
probe_utils->send_msg("$output", "f", "Option -n is required");
|
||||
probe_utils->send_msg("$output", "d", "$::USAGE");
|
||||
exit 1;
|
||||
}
|
||||
|
||||
my $msg = "NIC $installnic exists on current server";
|
||||
my $nics = `ip addr show $installnic >/dev/null 2>&1`;
|
||||
if ($?) {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
probe_utils->send_msg("$output", "d", "Please use 'ip addr show' to check if there is NIC named $installnic on current server");
|
||||
exit 1;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
|
||||
$msg = "Get ip address of NIC $installnic";
|
||||
my $mnip = `ip addr show $installnic | awk -F" " '/inet / {print \$2}'|awk -F"/" '{print \$1}'`;
|
||||
chomp($mnip);
|
||||
if (!defined($mnip) || ($mnip eq "")) {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
probe_utils->send_msg("$output", "d", "Please use 'ip addr show' to check if there is ip assigned to $installnic");
|
||||
exit 1;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "d", "The IP of NIC $installnic is $mnip") if ($verbose);
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
|
||||
$msg = "Sub process 'xcatd: SSL listener' is running";
|
||||
my $xcatdproc = `ps aux|grep -v grep|grep xcatd`;
|
||||
chomp($xcatdproc);
|
||||
if ($xcatdproc =~ /xcatd: SSL listener/) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
|
||||
$msg = "Sub process 'xcatd: DB Access' is running";
|
||||
if ($xcatdproc =~ /xcatd: DB Access/) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
|
||||
$msg = "Sub process 'xcatd: UDP listener' is running";
|
||||
if ($xcatdproc =~ /xcatd: UDP listener/) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
|
||||
$msg = "Sub process 'xcatd: install monitor' is running";
|
||||
if ($xcatdproc =~ /xcatd: install monitor/) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
|
||||
$msg = "Sub process 'xcatd: Discovery worker' is running";
|
||||
if ($xcatdproc =~ /xcatd: Discovery worker/) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
|
||||
$msg = "Sub process 'xcatd: Command log writer' is running";
|
||||
if ($xcatdproc =~ /xcatd: Command log writer/) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "w", "Sub process 'xcatd: Command log writer' isn't running");
|
||||
}
|
||||
exit 1 if ($rst);
|
||||
|
||||
|
||||
my $xcatdport = `tabdump site 2>&1 | awk -F',' '/xcatdport/ { gsub(/"/, "", \$2) ; print \$2 }'`;
|
||||
chomp($xcatdport);
|
||||
probe_utils->send_msg("$output", "d", "The port used by the xcatd daemon for client/server communication is $xcatdport") if ($verbose);
|
||||
$msg = "xcatd is listening on port $xcatdport";
|
||||
my $cmdoutput = `netstat -ant|grep LISTEN|grep $xcatdport`;
|
||||
if ($?) {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
|
||||
my $xcatiport = `tabdump site 2>&1| awk -F',' '/xcatiport/ { gsub(/"/, "", \$2) ; print \$2 }'`;
|
||||
chomp($xcatiport);
|
||||
probe_utils->send_msg("$output", "d", "The port used by xcatd to receive install status updates from nodes is $xcatiport") if ($verbose);
|
||||
$msg = "xcatd is listening on port $xcatiport";
|
||||
$cmdoutput = `netstat -antp | grep -i xcatd|grep LISTEN|grep $xcatiport`;
|
||||
if ($?) {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
exit 1 if ($rst);
|
||||
|
||||
$msg = "'lsxcatd -a' works";
|
||||
$cmdoutput = `lsxcatd -a 2>&1`;
|
||||
$rst = $?;
|
||||
returncmdoutput($cmdoutput) if ($verbose);
|
||||
if ($rst) {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
exit $rst;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
|
||||
my $masteripinsite = `tabdump site | awk -F',' '/master/ { gsub(/"/, "", \$2) ; print \$2 }'`;
|
||||
chomp($masteripinsite);
|
||||
probe_utils->send_msg("$output", "d", "The value of 'master' in 'site' table is $masteripinsite") if ($verbose);
|
||||
probe_utils->send_msg("$output", "f", "There isn't 'master' definition in 'site' talbe") if ($masteripinsite eq "");
|
||||
|
||||
$msg = "The value of 'master' in 'site' table is a IP address";
|
||||
if (probe_utils->is_ip_addr("$masteripinsite")) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if ($mnip) {
|
||||
$msg = "The IP $mnip of $installnic equals the value of 'master' in 'site' table";
|
||||
if ($mnip eq $masteripinsite) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$msg = "IP $mnip of NIC $installnic is a static IP on current server";
|
||||
if (probe_utils->is_static_ip("$mnip", "$installnic")) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "w", "IP $mnip of $installnic is not a static ip on current server");
|
||||
}
|
||||
|
||||
$msg = "$mnip belongs to one of networks defined in 'networks' table";
|
||||
my $networks = `tabdump networks|grep -v "^#"`;
|
||||
$networks =~ s/\"//g;
|
||||
my $netcnt = `echo "$networks"|wc -l`;
|
||||
my $hit = 0;
|
||||
for (my $i = 1 ; $i < $netcnt + 1 ; $i++) {
|
||||
my $line = `echo "$networks" |sed -n ${i}p |awk -F"," '{print \$2,\$3,\$4}'`;
|
||||
chomp($line);
|
||||
if ($line =~ /(.+) (.+) (.+)/) {
|
||||
$hit = 1 if (probe_utils->is_ip_belong_to_net("$1", "$2", $mnip) && ("$3" eq "$installnic"));
|
||||
}
|
||||
}
|
||||
if ($hit) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
|
||||
$msg = "There is domain definition in 'site' table";
|
||||
my $domain = `tabdump site | awk -F',' '/domain/ { gsub(/"/, "", \$2) ; print \$2 }'`;
|
||||
chomp($domain);
|
||||
if ($domain) {
|
||||
probe_utils->send_msg("$output", "d", "The value of 'domain' in 'site' table is $domain") if ($verbose);
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
|
||||
$msg = "There is configuration in 'passwd' table for 'system' for node provision";
|
||||
my $passwd = `tabdump passwd |awk -F',' '/system/ { gsub(/"/, "", \$2); gsub(/"/, "", \$3); print \$2,\$3 }'`;
|
||||
chomp($passwd);
|
||||
my ($username, $pw) = split(" ", $passwd);
|
||||
if ($username eq "" || $pw eq "") {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
probe_utils->send_msg("$output", "d", "Please define username and password for 'system' in 'passwd' table");
|
||||
$rst = 1;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
|
||||
my $installdir = `tabdump site 2>&1 | awk -F',' '/installdir/ { gsub(/"/, "", \$2) ; print \$2 }'`;
|
||||
chomp($installdir);
|
||||
probe_utils->send_msg("$output", "d", "The 'install' directory is set to $installdir in 'site' table on current server") if ($verbose);
|
||||
my $tftpdir = `tabdump site 2>&1 | awk -F',' '/tftpdir/ { gsub(/"/, "", \$2) ; print \$2 }'`;
|
||||
chomp($tftpdir);
|
||||
probe_utils->send_msg("$output", "d", "The 'tftp' directory is set to $tftpdir in 'site' talbe on current server") if ($verbose);
|
||||
|
||||
$msg = "There is $installdir directory on current server";
|
||||
if (-e "$installdir/postscripts/") {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
|
||||
$msg = "There is $tftpdir directory on current server";
|
||||
if (-e "$tftpdir") {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
|
||||
my $expected = 10;
|
||||
$msg = "The free space of / directory is more than $expected G";
|
||||
my $diskspace = `df -h|awk '{print \$4,\$6}'|grep -E "/\$"`;
|
||||
if ($?) {
|
||||
probe_utils->send_msg("$output", "d", "There isn't any filesystem mount on / directory");
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
} else {
|
||||
chomp($diskspace);
|
||||
my ($size, $dir) = split(" ", $diskspace);
|
||||
$size =~ s/G//g;
|
||||
probe_utils->send_msg("$output", "d", "The free space of / is $size G") if ($verbose);
|
||||
if ($size < $expected) {
|
||||
probe_utils->send_msg("$output", "w", "The free space of / is less than $expected G");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
}
|
||||
|
||||
$expected = 1;
|
||||
$msg = "The free space of /var directory is more than $expected G";
|
||||
$diskspace = `df -h|awk '{print \$4,\$6}'|grep -E "/var\$"`;
|
||||
if (!$?) {
|
||||
chomp($diskspace);
|
||||
my ($size, $dir) = split(" ", $diskspace);
|
||||
$size =~ s/G//g;
|
||||
probe_utils->send_msg("$output", "d", "The free space of /var is $size G") if ($verbose);
|
||||
if ($size < $expected) {
|
||||
probe_utils->send_msg("$output", "w", "The free space of /var is less than $expected G");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
}
|
||||
|
||||
$expected = 1;
|
||||
$msg = "The free space of /tmp directory is more than $expected G";
|
||||
$diskspace = `df -h|awk '{print \$4,\$6}'|grep -E "/tmp\$"`;
|
||||
if (!$?) {
|
||||
chomp($diskspace);
|
||||
my ($size, $dir) = split(" ", $diskspace);
|
||||
$size =~ s/G//g;
|
||||
probe_utils->send_msg("$output", "d", "The free space of /tmp is $size G") if ($verbose);
|
||||
if ($size < $expected) {
|
||||
probe_utils->send_msg("$output", "w", "The free space of /tmp is less than $expected G");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$expected = 10;
|
||||
$msg = "The free space of $installdir directory is more than $expected G";
|
||||
$diskspace = `df -h|awk '{print \$4,\$6}'|grep -E "$installdir\$"`;
|
||||
if (!$?) {
|
||||
chomp($diskspace);
|
||||
my ($size, $dir) = split(" ", $diskspace);
|
||||
$size =~ s/G//g;
|
||||
probe_utils->send_msg("$output", "d", "The free space of /install is $size G") if ($verbose);
|
||||
if ($size < $expected) {
|
||||
probe_utils->send_msg("$output", "w", "The free space of /install is less than $expected G");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
}
|
||||
|
||||
$msg = "SELinux is disabled on current server";
|
||||
if (probe_utils->is_selinux_enable()) {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
|
||||
$msg = "Firewall is closed on current server";
|
||||
if (probe_utils->is_firewall_open()) {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
|
||||
`which wget > /dev/null 2>&1`;
|
||||
if ($?) {
|
||||
probe_utils->send_msg("$output", "w", "wget tool isn't installed on current server, skip checking HTTP service.");
|
||||
probe_utils->send_msg("$output", "d", "Please do probe again after installing wget");
|
||||
} else {
|
||||
$msg = "HTTP service is ready on $mnip";
|
||||
if (probe_utils->is_http_ready("$mnip")) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
}
|
||||
|
||||
`which tftp > /dev/null 2>&1`;
|
||||
if ($?) {
|
||||
probe_utils->send_msg("$output", "w", "tftp tool isn't installed on current server, skip checking tftp service.");
|
||||
probe_utils->send_msg("$output", "d", "Please do probe again after installing tftp");
|
||||
} else {
|
||||
$msg = "TFTP service is ready on $mnip";
|
||||
if (probe_utils->is_tftp_ready("$mnip")) {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
}
|
||||
}
|
||||
|
||||
`which nslookup > /dev/null 2>&1`;
|
||||
if ($?) {
|
||||
probe_utils->send_msg("$output", "w", "nslookup tool isn't installed in current server, skip checking DNS service.");
|
||||
probe_utils->send_msg("$output", "d", "Please do probe again after installing nslookup");
|
||||
} else {
|
||||
$msg = "DNS server is ready on $mnip";
|
||||
probe_utils->send_msg("$output", "d", "Domain used to check DNS is $domain") if ($verbose);
|
||||
|
||||
my $rc = 0;
|
||||
{ #very important brace to create a block
|
||||
my $tmp = `chdef xcatmntest groups=all ip=$mnip`;
|
||||
if ($?) {
|
||||
returncmdoutput($tmp) if ($verbose);
|
||||
probe_utils->send_msg("$output", "d", "Simulate a node by chdef failed") if ($verbose);
|
||||
$rc = 1;
|
||||
last;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "d", "Simulate a node xcatmntest<ip=$mnip> to do DNS test") if ($verbose);
|
||||
}
|
||||
|
||||
probe_utils->send_msg("$output", "d", "To do 'makehosts xcatmntest'") if ($verbose);
|
||||
$tmp = `makehosts xcatmntest`;
|
||||
if ($?) {
|
||||
returncmdoutput($tmp) if ($verbose);
|
||||
probe_utils->send_msg("$output", "d", "makehosts xcatmntest failed") if ($verbose);
|
||||
$rc = 1;
|
||||
`rmdef xcatmntest`;
|
||||
last;
|
||||
}
|
||||
|
||||
$tmp = `cat /etc/hosts |grep xcatmntest |grep $mnip`;
|
||||
if ($?) {
|
||||
probe_utils->send_msg("$output", "d", "makehosts failed to add test node xcatmntest to /etc/hosts") if ($verbose);
|
||||
$rc = 1;
|
||||
`rmdef xcatmntest`;
|
||||
last;
|
||||
}
|
||||
|
||||
probe_utils->send_msg("$output", "d", "To do 'makedns -n xcatmntest'") if ($verbose);
|
||||
$tmp = `makedns -V -n xcatmntest 2>&1`;
|
||||
if ($?) {
|
||||
returncmdoutput($tmp) if ($verbose);
|
||||
probe_utils->send_msg("$output", "d", "makedns -n xcatmntest failed") if ($verbose);
|
||||
$rc = 1;
|
||||
`makehosts -d xcatmntest && rmdef xcatmntest`;
|
||||
last;
|
||||
}
|
||||
|
||||
if (!probe_utils->is_dns_ready("$mnip", "xcatmntest", "$domain")) {
|
||||
probe_utils->send_msg("$output", "d", "nslookup xcatmntest $mnip failed");
|
||||
$rc = 1;
|
||||
`makehosts -d xcatmntest && rmdef xcatmntest`;
|
||||
last;
|
||||
}
|
||||
|
||||
probe_utils->send_msg("$output", "d", "Start to clear simulate information for DNS test") if ($verbose);
|
||||
$tmp = `makedns -d xcatmntest && makehosts -d xcatmntest && rmdef xcatmntest`;
|
||||
returncmdoutput($tmp) if ($verbose);
|
||||
}
|
||||
|
||||
if ($rc) {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
}
|
||||
|
||||
my $os = probe_utils->get_os();
|
||||
my $leasefile = "";
|
||||
$leasefile = "/var/lib/dhcpd/dhcpd.leases" if ($os =~ /redhat/i);
|
||||
$leasefile = "/var/lib/dhcp/db/dhcpd.leases" if ($os =~ /sles/i);
|
||||
$leasefile = "/var/lib/dhcp/dhcpd.leases" if ($os =~ /ubuntu/i);
|
||||
$msg = "The size of $leasefile is less than 100M";
|
||||
my $filesizetmp = `du -sb $leasefile`;
|
||||
if ($?) {
|
||||
returncmdoutput($filesizetmp) if ($verbose);
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
$rst = 1;
|
||||
} else {
|
||||
chomp($filesizetmp);
|
||||
my ($size, $file) = split(" ", $filesizetmp);
|
||||
probe_utils->send_msg("$output", "d", "The size of $leasefile is $size bytes") if ($verbose);
|
||||
if ($size > 104857600) {
|
||||
probe_utils->send_msg("$output", "w", "The size of $leasefile is more than 100M");
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
}
|
||||
|
||||
my $msg = "DHCP service is ready on $mnip";
|
||||
my $rc = 0;
|
||||
{ #very important brace to create a block
|
||||
my $tmp = `chdef xcatmntest groups=all ip=$mnip mac=aa:aa:aa:aa:aa:aa`; if ($?) {
|
||||
returncmdoutput($tmp) if ($verbose);
|
||||
probe_utils->send_msg("$output", "d", "Simulate a node by chdef failed") if ($verbose);
|
||||
$rc = 1;
|
||||
last;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "d", "Simulate a node xcatmntest<ip=$mnip mac=aa:aa:aa:aa:aa:aa> to do dhcp test") if ($verbose);
|
||||
}
|
||||
|
||||
probe_utils->send_msg("$output", "d", "To do 'makehosts xcatmntest'") if ($verbose);
|
||||
$tmp = `makehosts xcatmntest`;
|
||||
if ($?) {
|
||||
returncmdoutput($tmp) if ($verbose);
|
||||
probe_utils->send_msg("$output", "d", "makehosts xcatmntest failed") if ($verbose);
|
||||
$rc = 1;
|
||||
`rmdef xcatmntest`;
|
||||
last;
|
||||
}
|
||||
|
||||
$tmp = `cat /etc/hosts |grep xcatmntest |grep $mnip`;
|
||||
if ($?) {
|
||||
probe_utils->send_msg("$output", "d", "makehosts failed to add test node xcatmntest to /etc/hosts") if ($verbose);
|
||||
$rc = 1;
|
||||
`rmdef xcatmntest`;
|
||||
last;
|
||||
}
|
||||
|
||||
probe_utils->send_msg("$output", "d", "To do 'makedhcp xcatmntest'") if ($verbose);
|
||||
$tmp = `makedhcp xcatmntest 2>&1`;
|
||||
if ($?) {
|
||||
returncmdoutput($tmp) if ($verbose);
|
||||
probe_utils->send_msg("$output", "d", "makedhcp xcatmntest failed") if ($verbose);
|
||||
$rc = 1;
|
||||
`makehosts -d xcatmntest && rmdef xcatmntest`;
|
||||
last;
|
||||
}
|
||||
|
||||
probe_utils->send_msg("$output", "d", "To do 'makedhcp -q xcatmntest'") if ($verbose);
|
||||
$tmp = `makedhcp -q xcatmntest`;
|
||||
if ($?) {
|
||||
returncmdoutput($tmp) if ($verbose);
|
||||
probe_utils->send_msg("$output", "d", "makedhcp -q xcatmntest failed") if ($verbose);
|
||||
$rc = 1;
|
||||
`makedhcp -d xcatmntest && makehosts -d xcatmntest && rmdef xcatmntest`;
|
||||
last;
|
||||
}
|
||||
chomp($tmp);
|
||||
if ($tmp !~ /xcatmntest: ip-address = $mnip, hardware-address = aa:aa:aa:aa:aa:aa/) {
|
||||
returncmdoutput($tmp) if ($verbose);
|
||||
probe_utils->send_msg("$output", "d", "DHCP server's reply is wrong") if ($verbose);
|
||||
$rc = 1;
|
||||
`makedhcp -d xcatmntest && makehosts -d xcatmntest && rmdef xcatmntest`;
|
||||
last;
|
||||
}
|
||||
|
||||
probe_utils->send_msg("$output", "d", "Start to clear simulate information for dhcp test") if ($verbose);
|
||||
$tmp = `makedhcp -d xcatmntest && makehosts -d xcatmntest && rmdef xcatmntest`;
|
||||
returncmdoutput($tmp) if ($verbose);
|
||||
}
|
||||
if ($rc) {
|
||||
probe_utils->send_msg("$output", "f", "$msg");
|
||||
probe_utils->send_msg("$output", "d", "please run 'makedhcp -n' if never run it before.");
|
||||
$rst = 1;
|
||||
} else {
|
||||
probe_utils->send_msg("$output", "o", "$msg");
|
||||
}
|
||||
exit $rst;
|
233
xCAT-probe/xcatprobe
Executable file
233
xCAT-probe/xcatprobe
Executable file
@ -0,0 +1,233 @@
|
||||
#!/usr/bin/env perl
|
||||
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
use File::Basename;
|
||||
use Data::Dumper;
|
||||
use File::Path;
|
||||
use POSIX qw(WNOHANG setsid :errno_h);
|
||||
use Term::ANSIColor qw(:constants);
|
||||
$Term::ANSIColor::AUTORESET = 1;
|
||||
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
|
||||
my $pro_name = basename($0);
|
||||
|
||||
my $pro_dir="$::XCATROOT/probe/";
|
||||
my $plugin_dir = "$pro_dir/subcmds";
|
||||
my %cmds = ();
|
||||
|
||||
my $verbose = 0;
|
||||
my $nocolor = 0;
|
||||
my $help = 0;
|
||||
my $list = 0;
|
||||
|
||||
$::USAGE = "Usage:
|
||||
xcatprobe -h
|
||||
xcatprobe -l
|
||||
xcatprobe [-n] [-V] <subcommand> <attrbute_to_subcommand>
|
||||
|
||||
Options:
|
||||
-h : get usage information of $pro_name
|
||||
-l : list all valid sub commands
|
||||
-V : print verbose information of $pro_name
|
||||
-n : print output without colors
|
||||
";
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Load sub commands from ~/subcmds directory
|
||||
Using -t option of command to judge if it is valid.
|
||||
If command in ~/subcmds has syntax error, or doesn't follow interface specification, this command will be skipped
|
||||
=cut
|
||||
|
||||
#-----------------------------------
|
||||
sub loadsubcmds {
|
||||
my @candidate = glob("$plugin_dir/*");
|
||||
my @subcmds = ();
|
||||
my $output;
|
||||
|
||||
print "Starting to load sub command form ~/subcmds.............\n" if ($verbose);
|
||||
|
||||
foreach (@candidate) {
|
||||
my $cmdname = basename("$_");
|
||||
$output = `$_ -t 2>&1`;
|
||||
chomp($output);
|
||||
|
||||
print "\n-->$_\n[OUTPUT]:\n$output\n" if ($verbose);
|
||||
if ($output !~ /\[(\w+)\]\s*:\s*(.+)/) {
|
||||
print "skip $_ for doing '$_ -t' failed, bad format\n" if ($verbose);
|
||||
next;
|
||||
} else {
|
||||
my $desc = $2;
|
||||
unless ($1 ~~ /^ok$/) {
|
||||
print "skip $_ for doing '$_ -t' failed, invalid flag\n" if ($verbose);
|
||||
next;
|
||||
}
|
||||
$cmds{$cmdname} = $desc;
|
||||
print "load $_ \n" if ($verbose);
|
||||
}
|
||||
}
|
||||
print "\nLoad sub command.........[done]\n" if ($verbose);
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
Format the output of sub command, make them colorfully.
|
||||
=cut
|
||||
|
||||
#----------------------------------
|
||||
sub format_cmd_output {
|
||||
my $line = shift;
|
||||
my $nocolor = shift;
|
||||
|
||||
if ($line =~ /\[(\w+)\]\s*:\s*(.+)/) {
|
||||
my $flag = $1;
|
||||
my $msg = $2;
|
||||
if ($flag =~ /failed/i) {
|
||||
if ($nocolor) {
|
||||
print "[FAIL] ";
|
||||
} else {
|
||||
print BOLD RED "[FAIL] ";
|
||||
}
|
||||
} elsif ($flag =~ /warning/i) {
|
||||
if ($nocolor) {
|
||||
print "[WARN] ";
|
||||
} else {
|
||||
print BOLD BLUE "[WARN] ";
|
||||
}
|
||||
} elsif ($flag =~ /ok/i) {
|
||||
if ($nocolor) {
|
||||
print "[ OK ] ";
|
||||
} else {
|
||||
print BOLD GREEN "[ OK ] ";
|
||||
}
|
||||
} elsif ($flag =~ /debug/i) {
|
||||
print " ";
|
||||
}
|
||||
print "$msg\n";
|
||||
} else {
|
||||
print "$line\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#-----------------------------------
|
||||
|
||||
=head3
|
||||
Description:
|
||||
List all valid sub command in ~/subcmds directory
|
||||
=cut
|
||||
|
||||
#----------------------------------
|
||||
sub listvalidsubcmd {
|
||||
my $maxlen = 0;
|
||||
foreach my $key (keys %cmds) {
|
||||
$maxlen = length($key) if (length($key) > $maxlen);
|
||||
}
|
||||
$maxlen += 4;
|
||||
print "Supported sub commands are:\n";
|
||||
foreach my $key (keys %cmds) {
|
||||
my @desc = split(" ", $cmds{$key});
|
||||
my $str = "";
|
||||
my @formatdesc = ();
|
||||
foreach my $word (@desc) {
|
||||
$str .= $word . " ";
|
||||
if (length($str) > 100) {
|
||||
push @formatdesc, $str;
|
||||
$str = "";
|
||||
}
|
||||
}
|
||||
push @formatdesc, $str;
|
||||
if ($nocolor) {
|
||||
print "$key";
|
||||
} else {
|
||||
print BOLD GREEN "$key";
|
||||
}
|
||||
my $space = " " x ($maxlen - length($key));
|
||||
print "$space $formatdesc[0]\n";
|
||||
delete $formatdesc[0];
|
||||
$space = " " x $maxlen;
|
||||
foreach my $line (@formatdesc) {
|
||||
print "$space $line\n" if (length($line));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#######################################
|
||||
# main
|
||||
#######################################
|
||||
my @tmpargv = @ARGV;
|
||||
my @supportopt = ("-V", "-h", "-l", "-n");
|
||||
my $pluginname;
|
||||
my $optnum = 0;
|
||||
foreach my $attr (@tmpargv) {
|
||||
if ($attr =~ /^-/) {
|
||||
unless (@supportopt ~~ /^$attr$/) {
|
||||
print "Unsupported attribute: $attr\n";
|
||||
print $::USAGE;
|
||||
exit 1;
|
||||
}
|
||||
$optnum++;
|
||||
$help = 1 if ($attr eq "-h");
|
||||
$verbose = 1 if ($attr eq "-V");
|
||||
$list = 1 if ($attr eq "-l");
|
||||
$nocolor = 1 if ($attr eq "-n");
|
||||
} else {
|
||||
$pluginname = $attr;
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
&loadsubcmds;
|
||||
if (defined($pluginname)) {
|
||||
my $hit = 0;
|
||||
foreach my $key (keys %cmds) {
|
||||
$hit = 1 if ($pluginname eq $key);
|
||||
}
|
||||
unless ($hit) {
|
||||
print "Unsupported sub command: $pluginname\n";
|
||||
&listvalidsubcmd;
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($help) {
|
||||
print $::USAGE;
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ($ARGV[0] eq "-l") {
|
||||
&listvalidsubcmd;
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if (!defined($pluginname)) {
|
||||
print "There isn't sub command input from command line\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
for (my $i = 0 ; $i < $optnum + 1 ; $i++) {
|
||||
shift @tmpargv;
|
||||
}
|
||||
my $pluginattrs = join(" ", @tmpargv);
|
||||
my $subcmd = "$plugin_dir/$pluginname $pluginattrs";
|
||||
|
||||
print "\nsubcmd = $subcmd\n" if ($verbose);
|
||||
|
||||
open(PIPE, "$subcmd |");
|
||||
while (<PIPE>) {
|
||||
chomp;
|
||||
format_cmd_output($_, $nocolor);
|
||||
}
|
||||
close(PIPE); # This will set the $? properly
|
||||
|
||||
my $ret = $? >> 8;
|
||||
|
||||
exit $ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user