-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharc_fill_db.pl
executable file
·371 lines (302 loc) · 8.82 KB
/
arc_fill_db.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
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/usr/bin/perl
# Script: arc_dump_ms.pl
# By: jvossler
# Dated: 28 Jan 2009
# Purpose: tool to populate an sqlite3 db at /tmp/arc.cust.data.db
# The databases has been created as follows.
# sqlite3 /tmp/arc.cust.data.db "create table seq (key INTEGER PRIMARY KEY,snum INTEGER, cid INTEGER, timestamp DATE);"
# sqlite3 /tmp/arc.cust.data.db "create table backlog (server_id INTEGER PRIMARY KEY, cid INTEGER, timestamp DATE,
# total INTEGER, five INTEGER, ten INTEGER, fifteen INTEGER, twenty INTEGER, twentyfive INTEGER);"
our $author = 'jvossler';
our $author_email = 'John_Vossler\@McAfee.com';
our $last_update = '01-28-2009';
our $script_name = 'arc_fill_db.pl';
our $script_version = '0.1';
use strict;
use warnings;
#use diagnostics;
use lib '/usr/local/bin/opsadmin/perl/';
use DBI;
use Data::Dumper;
use Getopt::Long qw(:config no_ignore_case bundling);
use MXL::Arch;
use MXL::MXL;
use XML::Simple;
# Globals.
our %flags;
# Subroutine prototypes
sub banner();
sub options();
sub usage();
&main();
### Begin MAIN ###
sub main() {
%flags = &options();
my %args = ();
my @cids = Arch::cids_from_mail_source();
foreach my $cid (@cids) {
my $snum = `/mxl/sbin/mas seq cust=$cid`;
chomp($snum);
if($snum eq '') { next; }
my $insert = "sqlite3 /tmp/arc.cust.data.db \"insert into seq (cid,snum,timestamp) values ($cid,$snum,DATETIME('NOW'));\"";
system("$insert");
if(($flags{'debug'}) || ($flags{'verbose'})) {
print "Customer: $cid\n";
print "Sequence Number: $snum\n";
print "Insert: $insert\n";
}
}
}
### End MAIN ###
### Subroutines ###
#
# Subroutine: banner
# Args: <void>
# Return Value: <void>
# Purpose: Print the script's basic info to STDOUT.
sub banner()
{
print "$script_name by: $author\n";
print "Version: $script_version\n";
print "Last Update: $last_update\n";
}
#
# Subroutine: get_filesystems.
# Args: none
# Return Value: indexing filesytems
# Purpose: Parse /mxl/etc/mxl_message_archiving.xml and get the designated filesystems
sub get_filesystems()
{
my $config = '/mxl/etc/mod_message_archive.xml';
my $ref = XMLin("$config");
#my $xp = XML::XPath->new(filename => $config)
# || die "Can't read $config as XML: $!\n";
print Dumper($ref);
my $queue = $ref->{'config'}->{'IndexQueue'}->{'local'};
my $rqueue = $ref->{'config'}->{'IndexQueue'}->{'remote'};
my $saved = $ref->{'config'}->{'IndexQueue'}->{'local_save_dir'};
my $reject = $ref->{'config'}->{'IndexQueue'}->{'local_reject_dir'};
#print "$queue $rqueue $saved $reject\n";
return ($queue,$rqueue,$saved,$reject);
}
#
# Subroutine: options
# Args: <void>
# Return Value: <void>
# Purpose: Process Command Line Options.
sub options()
{
#Getopt::Long::Configure ("bundling");
# Global Flags
my %hash = (
'debug' => 0,
'help' => 0,
'verbose' => 0,
'version' => 0,
);
my $result = GetOptions (
"d+" => \$hash{'debug'}, # incremental
"debug+" => \$hash{'debug'}, # incremental
"h" => \$hash{'help'}, # binary
"help" => \$hash{'help'}, # binary
"host=s" => \$hash{'host'}, # string
'n=i', => \$hash{'num'}, # integer
"port=s" => \$hash{'port'}, # string
"user=s" => \$hash{'user'}, # string
"v" => \$hash{'verbose'}, # binary
"verbose" => \$hash{'verbose'}, # binary
"V" => \$hash{'version'}, # binary
);
if($flags{'version'}) { &banner; die; }
unless($result) {
&usage();
die "There was an issue interperting the options you've set. Please check your usage.\n";
}
unless(defined($hash{'num'})) { $hash{'num'} = 5; }
if($hash{'debug'}) {
print "Options Selected:\n";
print Dumper(\%hash);
}
return %hash;
}
#
# Subroutine: usage
# Args: <void>
# Return Value: <void>
# Purpose: Write the appropriate usage to STDOUT.
sub usage()
{
# Please forgive this formating
# ... usage() is my exception to otherwise clean code these days.
my $usage = <<EOF;
Usage: $0 -p 1 [OPTIONS]
To be written ...
EOF
print $usage;
}
#
# Subroutine: summarize_imap
# Args: %server hash
# Return Value: Prints summary for and returns 0 for success, 1 for error.
# Purpose: Print the script's basic info to STDOUT.
sub summarize_imap()
{
my (%server) = @_;
my %samples;
my %stats;
my $server_str = "Checking mailbox: $server{user}\@$server{'host'}:$server{'port'}";
#if(($flags{'debug'}) || ($flags{'verbose'})) {
print "Checking mailbox: $server{user}\@$server{'host'}:$server{'port'}\n";
#}
my $imap;
my $socket;
if($server{'port'} == 993) {
#print "SSL\n";
$socket = IO::Socket::SSL->new(
Proto => 'tcp',
PeerAddr => $server{'host'},
PeerPort => $server{'port'},
) || die "Could not create socket on $server_str\n";
$imap = Mail::IMAPClient->new(
Password => $server{'pass'},
Peek => 1,
Socket => $socket,
User => $server{'user'},
) or die "Could connect to \n$!\n";
} else {
#print "No SSL\n";
$imap = Mail::IMAPClient->new(
Server => $server{'host'},
Password => $server{'pass'},
Peek => 1,
User => $server{'user'},
) or die "Could connect to \n$!\n";
}
#my @folders = $imap->folders();
#foreach my $folder (@folders) {
# if($folder eq 'INBOX') {
# print "Folder: $folder exists!\n";
# }
#}
$stats{'count'} = 0;
$stats{'1M'} = 0;
$stats{'5M'} = 0;
$stats{'10M'} = 0;
$stats{'15M'} = 0;
$stats{'20M'} = 0;
$stats{'25M'} = 0;
$stats{'total'} = 0;
$imap->select('INBOX') || die "Could not select INBOX.\n";
#$imap->select('Journal') || die "Could not select Journal.\n";
my @msgs = $imap->messages() or warn "Could not list messages: $@\n";
foreach my $message (@msgs) {
my $size = $imap->size($message);
if($stats{'count'} < $flags{'num'}) {
;
}
$stats{'total'} += $size;
if($size <= 1000000) { $stats{'1M'}++; }
elsif($size <= 5000000) { $stats{'5M'}++; }
elsif($size <= 10000000) { $stats{'10M'}++; }
elsif($size <= 15000000) { $stats{'15M'}++; }
elsif($size <= 20000000) { $stats{'20M'}++; }
elsif($size <= 25000000) { $stats{'25M'}++; }
else { ; }
$stats{'count'}++;
}
if($stats{'count'} == 0) {
$stats{'avg'} = 0;
} else {
$stats{'avg'} = $stats{'total'}/$stats{'count'};
}
return (%stats, %samples);
}
#
# Subroutine: summarize_pop3
# Args: %server hash
# Return Value: Prints summary for and returns 0 for success, 1 for error.
# Purpose: Print the script's basic info to STDOUT.
sub summarize_pop3()
{
my (%server) = @_;
my %samples;
my %stats;
my $server_str = "$server{user}\@$server{'host'}:$server{'port'}";
#if(($flags{'debug'}) || ($flags{'verbose'})) {
print "Checking mailbox: $server_str\n";
#}
my $socket;
my $pop3;
if($server{'port'} == 995) {
$socket = IO::Socket::SSL->new(
Proto => 'tcp',
PeerAddr => $server{'host'},
PeerPort => $server{'port'},
) || die "Could not create socket on $server_str\n";
$pop3 = new Mail::POP3Client(
USER => $server{'user'},
PASSWORD => $server{'pass'},
HOST => $server{'host'},
SOCKET => $socket,
PEEK => 1,
) || die "Could not open connection to $server_str\n";
} else {
$pop3 = new Mail::POP3Client(
USER => $server{'user'},
PASSWORD => $server{'pass'},
HOST => $server{'host'},
PEEK => 1,
) || die "Could not open connection to $server_str\n";
}
$stats{'1M'} = 0;
$stats{'5M'} = 0;
$stats{'10M'} = 0;
$stats{'15M'} = 0;
$stats{'20M'} = 0;
$stats{'25M'} = 0;
$stats{'count'} = 0;
$stats{'total'} = 0;
my @msgs = $pop3->List() or die "Could not list messages: $@\n";
#print "Here are the first $flags{'num'} messages:\n";
foreach my $message (@msgs) {
my ($msg_num, $msg_size) = split(/\s+/, $message);
if($stats{'count'} < $flags{'num'}) {
#print "Message: $msg_num ",
##$pop3->date($message), " ",
#"$msg_size \n",
##$pop3->subject($message), "\n";
#$pop3->Head($msg_num), "\n";
}
$stats{'total'} += $msg_size;
if($msg_size <= 1000000) { $stats{'1M'}++; }
elsif($msg_size <= 5000000) { $stats{'5M'}++; }
elsif($msg_size <= 10000000) { $stats{'10M'}++; }
elsif($msg_size <= 15000000) { $stats{'15M'}++; }
elsif($msg_size <= 20000000) { $stats{'20M'}++; }
elsif($msg_size <= 25000000) { $stats{'25M'}++; }
else { ; }
$stats{'count'}++;
}
$stats{'avg'} = $stats{'total'}/$stats{'count'};
return (%stats, %samples);
}
#
# Subroutine: write_summary
# Args: %stats hash
# Return Value: Prints summary for and returns 0 for success, 1 for error.
# Purpose: Print the script's basic info to STDOUT.
sub write_summary()
{
my (%stats) = @_;
print "1M -\t$stats{'1M'}\n";
print "5M -\t$stats{'5M'}\n";
print "10M -\t$stats{'10M'}\n";
print "15M -\t$stats{'15M'}\n";
print "20M -\t$stats{'20M'}\n";
print "25M -\t$stats{'25M'}\n";
print "total messages:\t$stats{'count'}\n";
print "total size:\t$stats{'total'}\n";
printf ("average size:\t%.2fM\n", $stats{'avg'}/1000000);
}
#
### EOF ###