line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BBPerl; |
2
|
5
|
|
|
5
|
|
178245
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
193
|
|
3
|
5
|
|
|
5
|
|
30
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
208
|
|
4
|
5
|
|
|
5
|
|
29
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
2980
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%03d", q$Revision: 1.55 $ =~ /: (\d+)\.(\d+)/; |
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
5992
|
use Net::Domain; |
|
5
|
|
|
|
|
119046
|
|
|
5
|
|
|
|
|
18750
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
4
|
|
|
4
|
0
|
117
|
my $class = shift; |
15
|
4
|
|
|
|
|
10
|
my $tname = shift; |
16
|
4
|
|
|
|
|
58
|
my $self = |
17
|
|
|
|
|
|
|
{ |
18
|
|
|
|
|
|
|
_debug => 0, |
19
|
|
|
|
|
|
|
_testName => "My_Test", |
20
|
|
|
|
|
|
|
_status => "green", |
21
|
|
|
|
|
|
|
_bbmsgs => "", |
22
|
|
|
|
|
|
|
_bbhome => $ENV{BBHOME}, |
23
|
|
|
|
|
|
|
_bbtmp => $ENV{BBTMP}, |
24
|
|
|
|
|
|
|
_bbcmd => $ENV{BB}, |
25
|
|
|
|
|
|
|
_bbdisp => $ENV{BBDISP}, |
26
|
|
|
|
|
|
|
_msgsnum=> 0, |
27
|
|
|
|
|
|
|
_hostname => Net::Domain->hostname(), |
28
|
|
|
|
|
|
|
_usefqdn=>0 |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
4
|
50
|
|
|
|
4003
|
if ($tname) { |
32
|
0
|
|
|
|
|
0
|
$tname =~ s/ /_/g; |
33
|
0
|
|
|
|
|
0
|
$self->{_testName} = $tname; |
34
|
|
|
|
|
|
|
} |
35
|
4
|
50
|
|
|
|
20
|
die "BBHOME is not set.... Exiting\n" if ! $ENV{BBHOME}; |
36
|
4
|
50
|
|
|
|
31
|
die "BBTMP is not set... Make sure to run \". \$BBHOME/etc/bbdef.sh\"\n" if ! $ENV{BBTMP}; |
37
|
4
|
|
|
|
|
13
|
bless $self,$class; |
38
|
4
|
|
|
|
|
18
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub useFQDN { |
42
|
3
|
|
|
3
|
1
|
1430
|
my $self = shift; |
43
|
3
|
100
|
|
|
|
10
|
if (@_) { |
44
|
1
|
|
|
|
|
3
|
$self->{_usefqdn} = shift; |
45
|
1
|
50
|
|
|
|
4
|
if ($self->{_usefqdn}) { |
46
|
1
|
|
|
|
|
9
|
$self->{_hostname} = Net::Domain->hostfqdn(); |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
0
|
$self->{_hostname} = Net::Domain->hostname(); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
3
|
|
|
|
|
17
|
return $self->{_usefqdn}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub debugLevel { |
56
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
57
|
0
|
0
|
|
|
|
0
|
if (@_) |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
|
|
0
|
$self->{_debug} = shift; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
0
|
return $self->{_debug}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub testName { |
65
|
0
|
|
|
0
|
1
|
0
|
my ($self,$tname) = @_; |
66
|
0
|
0
|
|
|
|
0
|
if ($tname) |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
|
|
0
|
$tname =~ s/ /_/g; |
69
|
0
|
|
|
|
|
0
|
$self->{_testName} = $tname; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
0
|
return $self->{_testName}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub status { |
75
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
76
|
0
|
0
|
|
|
|
0
|
if (@_) |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
|
|
0
|
my $stat=shift; |
79
|
0
|
|
|
|
|
0
|
$stat =~ tr/A-Z/a-z/; |
80
|
0
|
0
|
|
|
|
0
|
$self->{_status} = $stat if $stat =~ /red|yellow|green|purple|blue/; |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
0
|
return $self->{_status}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub addMsg { |
86
|
79
|
|
|
79
|
1
|
84924
|
my ($self,$msg) = @_; |
87
|
79
|
100
|
|
|
|
289
|
return $self->{_bbmsgs} if $self->{_msgsnum} >= 75; |
88
|
75
|
50
|
|
|
|
257
|
$self->{_bbmsgs} .= "\n".$msg if defined($msg); |
89
|
75
|
|
|
|
|
112
|
$self->{_msgsnum}++; |
90
|
75
|
|
|
|
|
171
|
return $self->{_bbmsgs}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub getMsgCount { |
94
|
77
|
|
|
77
|
1
|
1095
|
my $self = shift; |
95
|
77
|
|
|
|
|
2519
|
return $self->{_msgsnum}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub bbdisp { |
99
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
100
|
0
|
0
|
|
|
|
0
|
if (@_) { |
101
|
0
|
|
|
|
|
0
|
$self->{_bbdisp} = shift; |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
0
|
return $self->{_bbdisp}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Deprecated beyond 1.3 |
107
|
|
|
|
|
|
|
sub localhost { |
108
|
3
|
|
|
3
|
0
|
978
|
my $self = shift; |
109
|
3
|
100
|
|
|
|
11
|
if (@_) { |
110
|
1
|
|
|
|
|
4
|
$self->hostname(shift); |
111
|
|
|
|
|
|
|
} |
112
|
3
|
|
|
|
|
9
|
return $self->hostname(); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub hostname { |
116
|
11
|
|
|
11
|
1
|
3922
|
my $self = shift; |
117
|
11
|
100
|
|
|
|
35
|
if (@_) { |
118
|
3
|
|
|
|
|
11
|
$self->{_hostname} = shift; |
119
|
3
|
|
|
|
|
9
|
$self->{_usefqdn} = 0; |
120
|
|
|
|
|
|
|
} |
121
|
11
|
|
|
|
|
58
|
return $self->{_hostname}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub bbhome { |
125
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
126
|
0
|
0
|
|
|
|
|
if (@_) { |
127
|
0
|
|
|
|
|
|
$self->{_bbhome} = shift; |
128
|
|
|
|
|
|
|
} |
129
|
0
|
|
|
|
|
|
return $self->{_bbhome}; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub bbcmd { |
133
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
134
|
0
|
0
|
|
|
|
|
if (@_) { |
135
|
0
|
|
|
|
|
|
$self->{_bbcmd} = shift; |
136
|
|
|
|
|
|
|
} |
137
|
0
|
|
|
|
|
|
return $self->{_bbcmd}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub bbtmp { |
141
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
142
|
0
|
0
|
|
|
|
|
if (@_) { |
143
|
0
|
|
|
|
|
|
$self->{_bbtmp} = shift; |
144
|
|
|
|
|
|
|
} |
145
|
0
|
|
|
|
|
|
return $self->{_bbtmp}; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub send { |
152
|
|
|
|
|
|
|
sub _date() { |
153
|
5
|
|
|
5
|
|
5548
|
use POSIX qw(strftime); |
|
5
|
|
|
|
|
87428
|
|
|
5
|
|
|
|
|
39
|
|
154
|
0
|
|
|
0
|
|
|
my @monstr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); |
155
|
0
|
|
|
|
|
|
my @daystr = qw(Sun Mon Tue Wed Thr Fri Sat); |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); |
158
|
0
|
|
|
|
|
|
my $year_long = 1900 + $year; |
159
|
0
|
|
|
|
|
|
my $tz = strftime('%Z', localtime); |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
return sprintf '%3s %3s %2s %02s:%02s:%02s %3s %4s', $daystr[$wday], $monstr[$mon], $mday, $hour, $min, $sec, $tz, $year_long; |
162
|
|
|
|
|
|
|
} |
163
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
164
|
0
|
|
|
|
|
|
my $debug = $self->{_debug}; |
165
|
0
|
|
|
|
|
|
my $cmdline = $self->{_bbcmd}." ".$self->{_bbdisp}; |
166
|
0
|
|
|
|
|
|
my $localhostname = $self->{_hostname}; |
167
|
0
|
|
|
|
|
|
$localhostname =~ s/\./,/g; |
168
|
0
|
|
|
|
|
|
my $statusline = "status ".$localhostname.".".$self->{_testName}." ".$self->{_status}." "._date(); |
169
|
0
|
|
|
|
|
|
chomp ($statusline); |
170
|
0
|
0
|
|
|
|
|
if ($debug > 0) { |
171
|
0
|
|
|
|
|
|
print "The following will be sent using command:\n"; |
172
|
0
|
|
|
|
|
|
print $cmdline; |
173
|
0
|
|
|
|
|
|
print "\n---------------------------------------------------------\n"; |
174
|
0
|
|
|
|
|
|
print $statusline; |
175
|
0
|
|
|
|
|
|
print $self->{_bbmsgs}; |
176
|
0
|
|
|
|
|
|
print "---------------------------------------------------------\n"; |
177
|
|
|
|
|
|
|
} |
178
|
0
|
0
|
|
|
|
|
if ($debug < 2) { |
179
|
0
|
|
|
|
|
|
my $bbmsgs=$self->{_bbmsgs}; |
180
|
0
|
|
|
|
|
|
$bbmsgs =~ s/"/\\"/g; |
181
|
|
|
|
|
|
|
# Like this would ever work. |
182
|
|
|
|
|
|
|
# open (BBPIPE,"| ${cmdline} -") or die "Cannot open STDOUT to report\n"; |
183
|
|
|
|
|
|
|
# print BBPIPE "$statusline $bbmsgs"; |
184
|
|
|
|
|
|
|
# print BBPIPE $self->{_bbmsgs}; |
185
|
|
|
|
|
|
|
# close (BBPIPE); |
186
|
|
|
|
|
|
|
# system("$self->{_bbhome}/bin/bb-combo.sh","add","\"$statusline\n$bbmsgs\n\""); |
187
|
0
|
|
|
|
|
|
my $bsvar=`${cmdline} "${statusline} |
188
|
|
|
|
|
|
|
${bbmsgs} |
189
|
|
|
|
|
|
|
"`; |
190
|
|
|
|
|
|
|
} else { |
191
|
0
|
|
|
|
|
|
print "Debug level $debug prevents me from sending to the Big Brother Server.\n"; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
__END__ |