-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnsr_cli_ver_rpt.pl
More file actions
276 lines (257 loc) · 8.13 KB
/
nsr_cli_ver_rpt.pl
File metadata and controls
276 lines (257 loc) · 8.13 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#!/bin/perl
# $Id: nsr_cli_ver_rpt.pl,v 1.4 2017/03/03 14:53:33 gbrandt Exp $
#
#
#
#
##########################################################################
############### S P A W A R S H A R E D S E R V I C E S ############
##########################################################################
#
# File: nsr_cli_ver_rpt.pl.pl
# Author:
# Date: Friday, August 28, 2015
#
# Generated by bshdr
# Developed by Gene Brandt
# 504 452-3250
#
##########################################################################
#
# Description:
# Generate NetWorker Clients Version Report
#
# $Log: nsr_cli_ver_rpt.pl,v $
# Revision 1.4 2017/03/03 14:53:33 gbrandt
# Added a csv output file version.
#
# Revision 1.3 2017/03/03 14:30:31 gbrandt
# Fixed hardcopy output lines perpage.
#
# Revision 1.2 2017/03/03 14:06:44 gbrandt
# Added script introduction and output to a file. The page header includes
# the script file name and version.
#
# Revision 1.1 2017/03/03 13:32:18 gbrandt
# Initial revision
#
#
##########################################################################
############### S P A W A R S H A R E D S E R V I C E S ############
##########################################################################
# Environmentals #
##########################################################################
#
#
$DEBUG=0;
$QRY_FILE_NAME="/tmp/nsr_cli_ver_rpt_qry.$$";
$RPTDATE=`date '+%m/%d/%Y'`;
$RPTTIME=`date '+%H:%M:%S'`;
$MaxLines=60;
$RPT_FILE_NAME="/tmp/nsr_cli_ver_rpt_";
#
#
##########################################################################
############### S P A W A R S H A R E D S E R V I C E S ############
##########################################################################
# Processing #
##########################################################################
#
#
introduction("Networker Client Version Report");
#
# Get NSR server from command line.
#
if ( $#ARGV != 0 )
{
printf "\n\n Usage $0 NetWorker Server Name\n\n";
exit;
}
chomp($RPTDATE);
chomp($RPTTIME);
$NSR_Server=$ARGV[0];
$RPT_FILE_NAME.= $NSR_Server;
$CSV_FILE_NAME = $RPT_FILE_NAME . ".csv";
#
# Open report file.
#
open(RPT, ">$RPT_FILE_NAME") || die " Error: Unable to open $RPT_FILE_NAME $!!\n\n";
open(CSV, ">$CSV_FILE_NAME") || do {
printf " Error: Unable to open $CSV_FILE_NAME$!!\n\n";
};
#
# Build NetWorker Query
#
open(QRY, ">$QRY_FILE_NAME") || die "Unable to write $QRY_FILE_NAME $!!\n\n";
printf QRY ". type: nsr client;scheduled backup: Enabled\n";
printf QRY "show name;client OS type;NetWorker version\n";
printf QRY "print\n";
close(QRY);
chmod(0666, $QRY_FILE_NAME);
$QRY_COMMAND="nsradmin -s $NSR_Server -i $QRY_FILE_NAME|";
#
# Run run the querry
#
open(RESULT,$QRY_COMMAND) || die "Unable to run $QRY_COMMAND $!!\n\n";
while(<RESULT>)
{
if ($DEBUG)
{
print ;
}
chomp();
tr /;//d;
tr /"//d;
if (/name/)
{
@words=split(/\s+/);
$Client_Name=$words[-1];
}
if (/client OS/)
{
@words=split(/:/);
$StrLen=length($words[-1]);
if($DEBUG)
{
printf " Debug Line: %3d Value - $words[-1] Length- $StrLen\n",__LINE__;
}
$ClientOS{$Client_Name}=$words[-1];
$ClientOS{$Client_Name}=~ s/^\s+//; # remove leading spaces.
if ( $ClientOS{$Client_Name} =~ "Windows" )
{
$ClientOS{$Client_Name} = "Windows";
}
if ($StrLen <= 1)
{
$ClientOS{$Client_Name}="Unknown";
}
}
if(/NetWorker/)
{
@words=split(/:/);
$StrLen=length($words[-1]);
$Clientver{$Client_Name}=$words[-1];
$Clientver{$Client_Name}=~ s/^\s+//; # remove leading spaces.
if ($StrLen <= 1)
{
$Clientver{$Client_Name}="Unknown";
}
}
}
#
# Display results
#
$PageCount=0;
page_hdr();
$ClinetCount=0;
foreach $ClientName (sort keys %ClientOS)
{
if ($LineCount > $MaxLines)
{
if ($PageCount > 0)
{
printf RPT "\n\n";
}
page_hdr();
}
$ClientCount++;
$LineCount++;
$Warn = "";
if ( $ClientName =~ $NSR_Server )
{
$Warn = "*******";
}
if ( $Clientver{$ClientName} =~ "8.1" )
{
$Warn = "++";
}
if ( $Clientver{$ClientName} =~ "^7." )
{
$Warn = "+++++";
}
printf RPT " %3d %-28s %-8s %s %s\n",$ClientCount, $ClientName, $ClientOS{$ClientName}, $Clientver{$ClientName},$Warn;
printf CSV "%d,%s,%s,%s,%s\n",$ClientCount, $ClientName, $ClientOS{$ClientName}, $Clientver{$ClientName},$Warn;
}
#
##########################################################################
############### S P A W A R S H A R E D S E R V I C E S ############
##########################################################################
# House Keeping #
##########################################################################
#
#
close(RPT);
close(CSV);
unlink($QRY_FILE_NAME);
printf "\n Your report is in $RPT_FILE_NAME\n A csv version: $CSV_FILE_NAME\n\n";
#
##########################################################################
############### S P A W A R S H A R E D S E R V I C E S ############
##########################################################################
# Sub Routines #
##########################################################################
#
#
sub introduction {
$ProgName = shift;
$NameLength = length($ProgName);
$NameHeader = "| +++ ";
$NameTrailer = " +++ |";
$NameOffset = 10;
$DashCount = 16 + $NameLength;
$VersionLength = 18; # Length of Version information.
$VersionOffset = ( $DashCount - $VersionLength ) / 2;
if ($DEBUG) {
printf " Debug Line: %3d Program name:%s\n Length:%d",
__LINE__, $ProgName, $NameLength;
printf " VersionOffset: %d\n", $VersionOffset;
}
open( SOURCE, $0 ) || die "Unable to open $0 for reading\n\n";
while (<SOURCE>) {
if (/Id:/) {
@Column = split(/\s+/);
$ProgVer = $Column[3];
printf "\n\n";
print ' ' x $NameOffset;
printf "+";
print '-' x $DashCount;
print "+\n";
print ' ' x $NameOffset;
printf "%s", $NameHeader;
printf "%s", $ProgName;
printf "%s\n", $NameTrailer;
print ' ' x $NameOffset;
print "|";
print ' ' x $VersionOffset;
printf "-- Version %4s --", $ProgVer;
print " "
if ( $NameLength % 2 == 1 )
; # Print an extra " " if the name length is an odd number.
print ' ' x $VersionOffset;
print "|\n";
print ' ' x $NameOffset;
printf "+";
print '-' x $DashCount;
print "+\n";
last;
}
}
close(SOURCE);
}
sub page_hdr
{
$PageCount++;
printf RPT " NetWorker Client Version Report %10s\n",$NSR_Server;
printf RPT " ========= ====== ======= ====== ===========\n";
printf RPT " %s Version: %4s\n",$0,$ProgVer;
printf RPT " Report Date: $RPTDATE Page: %2d\n",$PageCount;
printf RPT " Report Time: $RPTTIME\n\n";
printf RPT " CLI %-26s %-8s %s\n","Client Name","Client OS","NetWorker Version";
printf RPT " CNT %-26s %-8s %s\n","===========","=========","=================";
$LineCount=8;
if ($PageCount == 1 )
{
printf CSV "\"NetWorker Client Version Report\",\"$ProgVer\",\"$RPTDATE\",\"$RPTTIME\"\n";
printf CSV "\"Line Number\",\"Client Name\",\"Client OS\",\"NetWorker Version\"\n";
}
}