-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhich_ESX_HOST_Clients_By_Groups.pl
117 lines (104 loc) · 4.3 KB
/
Which_ESX_HOST_Clients_By_Groups.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl -w
unshift (@INC,"/home/scriptid/scripts/BACKUPS/SUBROUTINES");
require append_group;
require build_output_record;
require create_group_name_from_esx_host_name;
require check_backups_on_other_server;
require handle_nsradmin_line_continuations;
require is_client_running_jobquery;
require pinger;
require read_tabvInfo_old;
require remove_clients_from_group;
require resolv_name;
require start_group;
require stop_group;
require show_group;
require testport;
require update_clients_group;
# Purpose of utility is to display the ESX Hostname for each client in a speacific group
#
#------------------------------------------------------------------------------------------------------------
#
$BACKUPSERVER = 'sscprodeng';
$ALTERNATESERVER = 'sscprodeng2'; # If blank then only uses BACKUPSERVER
(@servers) = ($BACKUPSERVER,$ALTERNATESERVER);
#################################################################################################################################
# Set up rap logs to track changes
#################################################################################################################################
$date = `/usr/bin/date '+%y%m%d%H%M%S'`;
chomp $date;
open (RAP,">>/home/scriptid/scripts/BACKUPS/RAP/WESXH_RAP_$date.log") or die "Could not open /home/scriptid/scripts/BACKUPS/RAP/WESXH_RAP_$date.log\n";
#################################################################################################################################
# Need to compute totalsize once and only want to compute it on the server on which it is scheduled, it could have been moved
# Don't need to include on the server machines that are not scheduled, that are Decom'd, that are not VADP
# Nothing this script does changes the above
#################################################################################################################################
# Get info from RvTools
# RvTools has all the x86 Virtuals Linux, Windows, VADP backups
# All indexed by lowercase client
print "\nBefore Read of Virtual Center Information\n";
read_tabvInfo_old();
print "After Read of Virtual Center Information\n\n";
#################################################################################################################################
foreach $server (@servers) {
# Build a list of the max size for each server
(@return) = `/usr/sbin/mminfo -s $server -xc, -r 'client,group' -q 'level=full,savetime>last month' | /usr/bin/sort | /usr/bin/uniq`;
#print MAIL " Building list of clients and their groups on $server\n";
foreach $record (@return) {
next if $record =~ /client/;
chomp $record;
($client,$group) = split(/,/,$record);
$client = lc $client;
$groups{$client} = $group;
}
}
#foreach $val (keys %groups) {
# print "Client:$val, ESX_HOST=$Host{$val}\n";
#}
TOP:
print "Enter networker group name to search or all: ";
$search = <STDIN>;
chomp $search;
foreach $val (sort keys %DNS_Name) {
$client = $DNS_Name{$val};
$client =~ s/\.\S+$//;
$client = lc $client;
next if $client =~ /^\s*$/;
next if $client =~ /^\d/;
$dns = resolv_name($val);
if ($dns =~ /Not in DNS/) {
#print "WARN: VM $client not in DNS\n";
} else {
$hostname = reverse_lookup($Host{$val},$Host{$val});
#if ($client =~ /mfom/) {
# print "Client=$client, Group=$groups{$client}, Host=$hostname\n";
#}
if (defined $groups{$client}) {
if ($groups{$client} =~ /$search/ || (lc $search =~ /^all$/)) {
print "Client=$client, Group=$groups{$client}, Host=$hostname\n";
}
} else {
#print "Networker Group not defined for $client\n";
}
}
}
sub reverse_lookup {
my ($check,$key) = @_;
my $IP = $check;
$name = "No DNS Name";
if ($IP !~ /\./) {
print MAIL "WARN: No reverse lookup for $key\n";
} else {
use Socket;
$iaddr = inet_aton("$IP");
$name = gethostbyaddr($iaddr, AF_INET);
if ( !defined $name ) {
$return = build_output_record(-80,$output,$check,18,0,-1,-1 ,'',1,18);
$return = build_output_record(0,$output,'ERROR',10,0,1,1 ,'',19,29);
$return = build_output_record(0,$output,"No reverse lookup for $key",51,0,0,0 ,'',30,80);
print MAIL "$return\n";
$name = "No DNS Name";
}
}
return $name;
}