-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_fc.pl
More file actions
187 lines (179 loc) · 5.84 KB
/
check_fc.pl
File metadata and controls
187 lines (179 loc) · 5.84 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
#!/usr/bin/perl -w
$logDir = "/usr/local/nagios/libexec/log";
$port = shift;
chomp($port);
@status = &portStat($port);
if ($status[0] eq '0')
{
print "OK - no new errors\n";
exit 0;
}
elsif($status[0] eq '1')
{
print "Warning - ";
printPort(@status);
udpateLog(@status);
exit 1;
}
else
{
print "Critical - ";
printPort(@status);
udpateLog(@status);
exit 2;
}
sub udpateLog
{
@output = @_;
if("$port.old.log")
{
@time = &getDate();
open(LOG, ">$logDir/$port.@time.log") or die "Cant open log file $port.@time.log for write: $!\n";
}
else
{
system("cp $logDir/$port.log $logDir/$port.old.log");
open(LOG, ">$logDir/$port.log") or die "Cant open log file $port.log for write: $!\n";
}
foreach (@output)
{
print LOG "$_\n";
}
}
sub printPort
{
@output = @_;
foreach (@output)
{
s/^\s+//g;
print "$_\n";
}
}
sub matchLog
{
$port = shift;
$row = shift;
open(ROWS, "$logDir/$port.log") or die "Cant open log file $port.log for read: $!\n";
while(<ROWS>)
{
if ($_ =~ $row)
{
@line = split;
close(ROWS);
return $line[-1];
}
}
}
sub compare
{
$newValue = shift;
$logValue = shift;
if($logValue ne $newValue)
{
return 1;
}
return 0;
}
sub portStat
{
$error = 0;
$port = shift;
open(FCSTAT, "/usr/sbin/fcinfo hba-port -l $port|") or die "fcinfo on port: $port isnt running\n";
while (<FCSTAT>)
{
chomp;
if ($_ =~ /State/)
{
$state = $_;
$logValue = matchLog($port, 'State');
@line = split(/\s+/, $state);
$error += &compare($line[-1], $logValue);
if($error > 0)
{
return 2;
}
}
elsif ($_ =~ /Link Failure Count/)
{
$LinkFailureCount = $_;
$logValue = matchLog($port, 'Link Failure Count');
@line = split(/\s+/, $LinkFailureCount);
$error += &compare($line[-1], $logValue);
}
elsif ($_ =~ /Loss of Sync Count/)
{
$LossOfSyncCount = $_;
$logValue = matchLog($port, 'Loss of Sync Count');
@line = split(/\s+/, $LossOfSyncCount);
$error += &compare($line[-1], $logValue);
}
elsif ($_ =~ /Loss of Signal Count/)
{
$LossOfSignalCount = $_;
$logValue = matchLog($port, 'Loss of Signal Count');
@line = split(/\s+/, $LossOfSignalCount);
$error += &compare($line[-1], $logValue);
}
elsif ($_ =~ /Primitive Seq/)
{
$PrimitiveSeqProtocolErrorCount = $_;
$logValue = matchLog($port, 'Primitive Seq');
@line = split(/\s+/, $PrimitiveSeqProtocolErrorCount);
$error += &compare($line[-1], $logValue);
}
elsif ($_ =~ /Invalid Tx Word Count/)
{
$InvalidTxWordCount = $_;
$logValue = matchLog($port, 'Invalid Tx Word Count');
@line = split(/\s+/,$InvalidTxWordCount);
$error += &compare($line[-1], $logValue);
}
elsif ($_ =~ /Invalid CRC Count/)
{
$InvalidCRCCount = $_;
$logValue = matchLog($port, 'Invalid CRC Count');
@line = split(/\s+/,$InvalidCRCCount);
$error += &compare($line[-1], $logValue);
}
}
close(FCSTAT);
if($error > 0)
{
return ($state, $LinkFailureCount, $LossOfSyncCount, $LossOfSignalCount, $PrimitiveSeqProtocolErrorCount, $InvalidTxWordCount, $InvalidCRCCount);
}
return 0;
}
sub getDate
{
return getTime('year') . "." . getTime('dom') . "." . getTime('month') . "." . getTime('hour') . "." . getTime('minute');
}
sub getTime
{
$timeRequest = shift;
@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
#($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
@localtime = localtime();
$year = 1900 + $localtime[5];
if ($timeRequest eq 'hour') {
return $localtime[2];
}
elsif ($timeRequest eq 'minute') {
return $localtime[1];
}
elsif ($timeRequest eq 'second') {
return $localtime[0];
}
elsif ($timeRequest eq 'dow') {
return $weekDays[$localtime[6]];
}
elsif ($timeRequest eq 'month') {
return $months[$localtime[4]];
}
elsif ($timeRequest eq 'dom') {
return $localtime[3];
}
elsif ($timeRequest eq 'year') {
return $year;
}
}