mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 11:22:27 +00:00 
			
		
		
		
	fix probe bugs
This commit is contained in:
		| @@ -5,6 +5,7 @@ package probe_utils; | ||||
| use strict; | ||||
| use File::Path; | ||||
| use File::Copy; | ||||
| use Time::Local; | ||||
| use Socket; | ||||
|  | ||||
| #----------------------------------------- | ||||
| @@ -439,4 +440,80 @@ sub get_hostname_from_ip { | ||||
|     return $hostname; | ||||
| } | ||||
|  | ||||
| #------------------------------------------ | ||||
|  | ||||
| =head3 | ||||
|     Description: | ||||
|         Check if the free space of specific directory is more than expected value  | ||||
|     Arguments: | ||||
|         targetdir: The directory needed to be checked  | ||||
|         expect_free_space: the expected free space for above directory | ||||
|     Returns: | ||||
|         0: the free space of specific directory is less than expected value | ||||
|         1: the free space of specific directory is more than expected value | ||||
|         2: the specific directory isn't mounted on standalone disk. it is a part of "/"  | ||||
| =cut | ||||
|  | ||||
| #------------------------------------------ | ||||
| sub is_dir_has_enough_space{ | ||||
|     my $targetdir=shift; | ||||
|     $targetdir = shift if (($targetdir) && ($targetdir =~ /probe_utils/)); | ||||
|     my $expect_free_space = shift; | ||||
|     my @output = `df -k`; | ||||
|  | ||||
|     foreach my $line (@output){ | ||||
|         chomp($line); | ||||
|         my @line_array = split(/\s+/, $line); | ||||
|         if($line_array[5] =~ /^$targetdir$/){ | ||||
|             my $left_space = $line_array[3]/1048576; | ||||
|             if($left_space >= $expect_free_space){ | ||||
|                 return 1; | ||||
|             }else{ | ||||
|                 return 0; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     return 2; | ||||
| } | ||||
|  | ||||
| #------------------------------------------ | ||||
|  | ||||
| =head3 | ||||
|     Description: | ||||
|         Convert input time format to the number of non-leap seconds since whatever time the system considers to be the epoch | ||||
|         the format of input time  are two kinds | ||||
|         one like "Aug 15 02:43:31", another likes "15/Aug/2016:01:10:24"  | ||||
|     Arguments: | ||||
|         timestr: the time format need to be converted | ||||
|         yday: the year of current time. | ||||
|     Returns: | ||||
|         the number of non-leap seconds since whatever time the system considers to be the epoch | ||||
| =cut | ||||
|  | ||||
| #------------------------------------------ | ||||
| sub convert_to_epoch_seconds { | ||||
|     my $timestr=shift; | ||||
|     $timestr = shift if (($timestr) && ($timestr =~ /probe_utils/)); | ||||
|     my $yday=shift; | ||||
|     my $ref_seconds=shift; | ||||
|     my $mday; | ||||
|     my $dday; | ||||
|     my $h; | ||||
|     my $m; | ||||
|     my $s; | ||||
|     my $epoch_seconds=-1; | ||||
|     my %monthsmap = ("Jan"=>0,"Feb"=>1,"Mar"=>2,"Apr"=>3,"May"=>4,"Jun"=>5,"Jul"=>6,"Aug"=>7,"Sep"=>8,"Oct"=>9,"Nov"=>10,"Dec"=>11); | ||||
|  | ||||
|     if($timestr =~/(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)/){ | ||||
|         ($mday,$dday,$h,$m,$s)=($1,$2,$3,$4,$5); | ||||
|         $epoch_seconds = timelocal($s,$m,$h,$dday,$monthsmap{$mday},$yday); | ||||
|         if($epoch_seconds>$ref_seconds){ | ||||
|             $yday-=1; | ||||
|             $epoch_seconds = timelocal($s,$m,$h,$dday,$monthsmap{$mday},$yday); | ||||
|         } | ||||
|     }elsif($timestr =~ /(\d+)\/(\w+)\/(\d+):(\d+):(\d+):(\d+)/){ | ||||
|         $epoch_seconds = timelocal($6,$5,$4,$1,$monthsmap{$2},($3-1900)); | ||||
|     } | ||||
|     return $epoch_seconds; | ||||
| } | ||||
| 1; | ||||
|   | ||||
| @@ -363,68 +363,23 @@ sub do_main_job { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     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($outputtarget, "d", "There isn't any filesystem mount on / directory"); | ||||
|         probe_utils->send_msg($outputtarget, "f", "$msg"); | ||||
|         $rst = 1; | ||||
|     } else { | ||||
|         chomp($diskspace); | ||||
|         my ($size, $dir) = split(" ", $diskspace); | ||||
|         $size =~ s/G//g; | ||||
|         probe_utils->send_msg($outputtarget, "d", "The free space of / is $size G") if ($verbose); | ||||
|         if ($size < $expected) { | ||||
|             probe_utils->send_msg($outputtarget, "w", "The free space of / is less than $expected G"); | ||||
|         } else { | ||||
|             probe_utils->send_msg($outputtarget, "o", "$msg"); | ||||
|     #check the free space of specific directory | ||||
|     #if "/var" is mounted on standalone disk, more than 1G free space is expected | ||||
|     #if "/tmp" is mounted on standalone disk, more than 1G free space is expected | ||||
|     #if installdir is mounted on standalone disk, more than 10G free space is expected.  | ||||
|     #if any one of above three directories hasn't standalone disk, "/" directory should cover its space requirement. | ||||
|     my @dir_expectedspace_list = (["/var", "1"], ["/tmp", "1"], ["$installdir", "10"], ["/" , "0"]); | ||||
|     foreach my $dir (@dir_expectedspace_list){ | ||||
|         next if($dir->[0]  eq "/" && $dir->[1] == 0); | ||||
|         my $checkrst = probe_utils->is_dir_has_enough_space($dir->[0], $dir->[1]); | ||||
|         if($checkrst == 2){ | ||||
|             $dir_expectedspace_list[$#dir_expectedspace_list][1] += $dir->[1]; | ||||
|         }elsif($checkrst == 1){ | ||||
|             probe_utils->send_msg($outputtarget, "o", "The free space of '$dir->[0]' directory is more than $dir->[1] G"); | ||||
|         }elsif($checkrst == 0){ | ||||
|             probe_utils->send_msg($outputtarget, "w", "The free space of '$dir->[0]' is less than $dir->[1] G"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     $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($outputtarget, "d", "The free space of /var is $size G") if ($verbose); | ||||
|         if ($size < $expected) { | ||||
|             probe_utils->send_msg($outputtarget, "w", "The free space of /var is less than $expected G"); | ||||
|         } else { | ||||
|             probe_utils->send_msg($outputtarget, "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($outputtarget, "d", "The free space of /tmp is $size G") if ($verbose); | ||||
|         if ($size < $expected) { | ||||
|             probe_utils->send_msg($outputtarget, "w", "The free space of /tmp is less than $expected G"); | ||||
|         } else { | ||||
|             probe_utils->send_msg($outputtarget, "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($outputtarget, "d", "The free space of /install is $size G") if ($verbose); | ||||
|         if ($size < $expected) { | ||||
|             probe_utils->send_msg($outputtarget, "w", "The free space of /install is less than $expected G"); | ||||
|         } else { | ||||
|             probe_utils->send_msg($outputtarget, "o", "$msg"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     $msg = "SELinux is disabled on current server"; | ||||
| @@ -444,8 +399,7 @@ sub do_main_job { | ||||
|  | ||||
|     `which wget > /dev/null 2>&1`; | ||||
|     if ($?) { | ||||
|         probe_utils->send_msg($outputtarget, "w", "wget tool isn't installed on current server, skip checking HTTP service."); | ||||
|         probe_utils->send_msg($outputtarget, "d", "Please do probe again after installing wget"); | ||||
|         probe_utils->send_msg($outputtarget, "w", "'wget' tool isn't installed, skip checking HTTP service. please install wget then try again"); | ||||
|     } else { | ||||
|         $msg = "HTTP service is ready on $serverip"; | ||||
|         if (probe_utils->is_http_ready("$serverip")) { | ||||
| @@ -472,8 +426,7 @@ sub do_main_job { | ||||
|     if ($checktftp) { | ||||
|         `which tftp > /dev/null 2>&1`; | ||||
|         if ($?) { | ||||
|             probe_utils->send_msg($outputtarget, "w", "tftp tool isn't installed on current server, skip checking tftp service."); | ||||
|             probe_utils->send_msg($outputtarget, "d", "Please do probe again after installing tftp"); | ||||
|             probe_utils->send_msg($outputtarget, "w", "'tftp' tool isn't installed, skip checking tftp service. Please install tftp then try again"); | ||||
|         } else { | ||||
|             $msg = "TFTP service is ready on $serverip"; | ||||
|             if (probe_utils->is_tftp_ready("$serverip")) { | ||||
| @@ -499,14 +452,12 @@ sub do_main_job { | ||||
|     if ($checkdns) { | ||||
|         `which nslookup > /dev/null 2>&1`; | ||||
|         if ($?) { | ||||
|             probe_utils->send_msg($outputtarget, "w", "nslookup tool isn't installed in current server, skip checking DNS service."); | ||||
|             probe_utils->send_msg($outputtarget, "d", "Please do probe again after installing nslookup"); | ||||
|             probe_utils->send_msg($outputtarget, "w", "'nslookup' tool isn't installed, skip checking DNS service. please install nslookup then try again"); | ||||
|         } else { | ||||
|             $msg = "DNS server is ready on $serverip"; | ||||
|             probe_utils->send_msg($outputtarget, "d", "Domain used to check DNS is $domain") if ($verbose); | ||||
|  | ||||
|             my $rc = 0; | ||||
|  | ||||
|             if (!$is_sn) { | ||||
|  | ||||
|                 # if this is a hierarchical cluster, nslookup one of sn to check DNS service | ||||
| @@ -517,7 +468,7 @@ sub do_main_job { | ||||
|                     if ($sninfo =~ /(\d+).(\d+).(\d+).(\d+)/) { | ||||
|                         my $snip = "$1.$2.$3.$4"; | ||||
|                         if (!probe_utils->is_dns_ready("$snip", "$serverip", "$sntmp", "$domain")) { | ||||
|                             probe_utils->send_msg("$outputtarget", "d", "nslookup $sntmp $snip failed"); | ||||
|                             probe_utils->send_msg("$outputtarget", "d", "nslookup $sntmp $snip failed") if($verbose); | ||||
|                             $rc = 1; | ||||
|                         } | ||||
|                     } | ||||
| @@ -525,17 +476,11 @@ sub do_main_job { | ||||
|  | ||||
|                     # if there is no sn, nslookup mnip | ||||
|                     my $nslkp = `nslookup $serverip $serverip 2>&1`; | ||||
|  | ||||
|                     if ($?) { | ||||
|                         probe_utils->send_msg($outputtarget, "d", "nslookup $serverip $serverip failed"); | ||||
|                     chomp($nslkp); | ||||
|                     my $tmp = grep {$_ =~ "Server:[\t\s]*$serverip"} split (/\n/, $nslkp); | ||||
|                     if (!$tmp) { | ||||
|                         probe_utils->send_msg($outputtarget, "d", "nslookup $serverip $serverip failed") if($verbose); | ||||
|                         $rc = 1; | ||||
|                     } else { | ||||
|                         chomp($nslkp); | ||||
|                         my $tmp = grep {$_ =~ "Server:[\t\s]*$serverip"} split (/\n/, $output); | ||||
|                         if (!$tmp) { | ||||
|                             probe_utils->send_msg($outputtarget, "d", "nslookup $serverip $serverip failed"); | ||||
|                             $rc = 1; | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 if ($rc) { | ||||
| @@ -861,7 +806,7 @@ sub send_sn_msg { | ||||
|             if ($line =~ /^(\[\w+\]\s*):\s*(.*)/) { | ||||
|                 print "$1:[SN:$node]: $2\n"; | ||||
|             } else { | ||||
|                 print "[failed] :$node: $line\n"; | ||||
|                 print "[failed] :[SN:$node]: $line\n"; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -31,6 +31,7 @@ Options: | ||||
|     -h : get usage information of $program_name  | ||||
|     -l : list all valid sub commands | ||||
|     -V : print verbose information of $program_name | ||||
|     -w : show each line completely. by default if one is too long, the long part will be omitted.  | ||||
| "; | ||||
|  | ||||
| #----------------------------------- | ||||
|   | ||||
| @@ -7,7 +7,7 @@ Standards-Version: 3.7.2 | ||||
|  | ||||
| Package: xcatsn | ||||
| Architecture: all | ||||
| Depends: ${perl:Depends}, xcat-server, perl-xcat, xcat-client, libdbd-sqlite3-perl, libxml-parser-perl, tftpd-hpa, tftp-hpa, conserver-xcat, libnet-telnet-perl, dhcp3-server, apache2, expect, nfs-kernel-server, nmap, bind9, ipmitool-xcat (>=1.8.15-2), syslinux-xcat, xnba-undi, xcat-genesis-scripts-ppc64, xcat-genesis-scripts-amd64, elilo-xcat,libsys-virt-perl | ||||
| Depends: ${perl:Depends}, xcat-server, perl-xcat, xcat-client, libdbd-sqlite3-perl, libxml-parser-perl, tftpd-hpa, tftp-hpa, conserver-xcat, libnet-telnet-perl, dhcp3-server, apache2, expect, nfs-kernel-server, nmap, bind9, ipmitool-xcat (>=1.8.15-2), syslinux-xcat, xnba-undi, xcat-genesis-scripts-ppc64, xcat-genesis-scripts-amd64, elilo-xcat,libsys-virt-perl, xcat-probe (>=2.12) | ||||
| Recommends: yaboot-xcat | ||||
| Description: Metapackage for a common, default xCAT service node setup | ||||
|  xCATsn is a service node management package intended for at-scale management, including hardware management and software management. | ||||
|   | ||||
| @@ -17,7 +17,7 @@ Source3: xCATSN | ||||
| Source5: templates.tar.gz | ||||
| Source6: xcat.conf.apach24 | ||||
| Provides: xCATsn = %{version} | ||||
| Requires: xCAT-server xCAT-client perl-DBD-SQLite xCAT-genesis-scripts-x86_64 xCAT-genesis-scripts-ppc64  | ||||
| Requires: xCAT-server xCAT-client perl-DBD-SQLite xCAT-genesis-scripts-x86_64 xCAT-genesis-scripts-ppc64 xCAT-probe >= 2.12.2  | ||||
|  | ||||
| Conflicts: xCAT | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user