Bug #1450 » mentat.storage.mongo.pl
1 |
#!/usr/bin/perl -T
|
---|---|
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
use Time::HiRes qw( time ); |
7 |
use Value::Convertor; |
8 |
use Mentat::Storage::Mongo; |
9 |
|
10 |
my ($min, $max) = Value::Convertor->ipv4cidr_to_bins("158.196.158.0", 24); |
11 |
$min = MongoDB::BSON::Binary->new(data => $min, subtype => 0); |
12 |
$max = MongoDB::BSON::Binary->new(data => $max, subtype => 0); |
13 |
|
14 |
my $filter = { |
15 |
'Alert.Source.Node.Address.ipv4.min' => { |
16 |
'$gte' => $min, |
17 |
},
|
18 |
'Alert.Source.Node.Address.ipv4.max' => { |
19 |
'$lte' => $max, |
20 |
},
|
21 |
'Alert.Classification.@text' => 'Webattack', |
22 |
};
|
23 |
|
24 |
my $storage = Mentat::Storage::Mongo->new(database => 'mentat', collection => 'alerts'); |
25 |
my ($results, $count); |
26 |
|
27 |
my $start = time; |
28 |
|
29 |
################################################################################
|
30 |
# OPTION A
|
31 |
################################################################################
|
32 |
|
33 |
($results, $count) = $storage->find($filter); |
34 |
|
35 |
################################################################################
|
36 |
# OPTION B
|
37 |
################################################################################
|
38 |
|
39 |
#my ($cursor, $cnta) = $storage->find_i($filter);
|
40 |
#while (my $doc = $cursor->next) {
|
41 |
# push(@$results, $doc); $count++;;
|
42 |
#}
|
43 |
|
44 |
################################################################################
|
45 |
my $end = time; |
46 |
print STDERR "DURATION: ".($end-$start).", COUNT: $count\n"; |
47 |
|