-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFleet_Check_Tail_Provisioning.pl
executable file
·152 lines (129 loc) · 4.13 KB
/
Fleet_Check_Tail_Provisioning.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
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
#!/usr/bin/perl -w
$! = 1;
my $Verbose=1;
my $FileOut="F";
my $Year=`date +%Y`; chomp( $Year );
my $Month=`date +%m`; chomp( $Month );
my $Subject; my @Errors; my $Loop; my @Found;
my $FirstError; my $LastError; my $Count;
my $Status="Undefined";;
my $UserInfo="/tmp/ba_users_info.csv";
#
# Lets check the status of the Provisioning file
#
my $dev; my $ino; my $mode; my $nlink; my $uid; my $gid; my $rdev;
my $size; my $atime; my $mtime; my $ctime; my $blksize; my $blocks;
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($UserInfo);
# How long should we look back
my $Days="24 hours ago";
#my $Days="48 hours ago";
# Use last modified time
my $Type="-newermt ";
#
# Who are we going to email?
#
my $Users="rharris\@aircell.com";
#my $Users="networkopsco\@aircell.com";
#my $Users="networkopsco\@aircell.com,techsupport-co\@aircell.com,twasinger\@aircell.com,cusrey\@aircell.com,mzable\@aircell.com,rhamrin\@gogoair.com";
#
# Lets get our list of tails to check on
#
chdir( "/opt/log/atg/$Year/$Month" );
#open(TAILS, "ls -1 | sort | grep ^10[0123] |");
#open(TAILS, "ls -1 | sort | grep ^138 |");
open(TAILS, "ls -1 | sort |");
while(<TAILS>) {
chomp;
push(@TAILS, $_);
}
my $Date=`date`; chomp( $Date );
my $MaxDiff="1200";
my $StatusString = "User Info File was last modified ". localtime( $mtime );
push(@Errors, "" );
push(@Errors, "Current Date: $Date" );
push(@Errors, $StatusString );
push(@Errors, " * If this file is more than 1.5 hours ago, something is wrong.");
push(@Errors, "" );
#
# Lets look for the Auth errors for our tails
#
foreach $Loop (@TAILS) {
$FirstError="";
$Count=0;
print "Processing $Loop\n" if ( $Verbose );
my $FindCMD= "/bin/find $Loop -type f -iname $Loop*console*gz $Type \"$Days\" -exec /usr/local/bin/Check_Provisioning.pl \{\} \\; \n";
print "\$FindCMD :$FindCMD:\n";
open(INPUT, "$FindCMD |");
while(<INPUT>) {
chomp;
print "\$_ :$_:\n" if ( $Verbose );
$Count++;
$FirstError=$_ if ( $FirstError eq "" );
$LastError=$_;
}
if ( $FirstError ne "" ) {
print "Found Problems with $Loop in $Count Log Files\n" if ( $Verbose );
print " First Error was: $FirstError\n" if ( $Verbose );
print " Last Error was: $LastError\n" if ( $Verbose );
push(@Errors, "Found Problems with $Loop in $Count Log Files");
push(@Errors, " First Error was: $FirstError");
push(@Errors, " Last Error was: $LastError");
push(@Errors, " ** Provisioning Status :");
open(STATUS, "/usr/local/bin/Check_Tail_Provisioning.pl -T $Loop -s |");
while(<STATUS>) {
chomp;
next if ( /out of date/ );
push(@Errors, " $_");
}
push(@Errors, "");
}
if ( ! grep( /SUSPENDED/, @Errors ) ) {
push(@FinalErrors, @Errors);
undef(@Errors);
} else {
undef(@Errors);
}
}
#
# Here we actually send our mail/save logs
#
if ( $#FinalErrors < 0 ) {
$Subject="Provisioning Check found no new issues.\n";
open(MAILME, "| mailx -s \"$Subject\" $Users");
print "No Errors found.\n" if ( $Verbose );
print MAILME "No Errors found.\n";
if ( $FileOut eq "T" ) {
open(SAVEME, ">/tmp/ProvCheck.txt");
print SAVEME "No Errors found.\n";
close(SAVEME);
}
exit 0;
} else {
print "Sending mail with errors.\n" if ( $Verbose );
$Subject="Provisioning Check for last $Days days in $Year/$Month";
open(MAILME, "| mailx -s \"$Subject\" $Users");
print MAILME "\n";
print MAILME "Provisioning Errors found on the following Tails in the last $Days days.\n";
print MAILME "\n";
print MAILME "** Check Service Activation/Suspended First **\n";
print MAILME "\n";
foreach $Loop (@FinalErrors) {
print MAILME " $Loop\n";
}
print MAILME "\n";
if ( $FileOut eq "T" ) {
open(SAVEME, ">/tmp/ProvCheck.txt");
print SAVEME "\n";
print SAVEME "Provisioning Errors found on the following Tails in the last $Days days.\n";
print SAVEME "\n";
print SAVEME "** Check Service Activation/Suspended First **\n";
print SAVEME "\n";
print SAVEME "\n";
foreach $Loop (@FinalErrors) {
print SAVEME " $Loop\n";
}
print SAVEME "\n";
close(SAVEME);
}
}
close(MAILME);