projects
/
pxelator
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
move query generation into httpd code
[pxelator]
/
lib
/
PXElator
/
store.pm
diff --git
a/lib/PXElator/store.pm
b/lib/PXElator/store.pm
index
30b14da
..
0f691eb
100644
(file)
--- a/
lib/PXElator/store.pm
+++ b/
lib/PXElator/store.pm
@@
-7,13
+7,16
@@
use POSIX;
use Time::HiRes qw/time/;
use Data::Dump qw(dump);
use Time::HiRes qw/time/;
use Data::Dump qw(dump);
-#use CouchDB;
-
use MongoDB;
use MongoDB;
-my $conn = MongoDB::Connection->new;
-our $db = $conn->get_database( 'pxelator' );
-our $audit = $db->get_collection( 'audit' );
+our $audit;
+
+eval {
+ my $conn = MongoDB::Connection->new;
+ my $db = $conn->get_database( 'pxelator' );
+ $audit = $db->get_collection( 'audit' );
+};
+warn "ERROR: no store for audit: $@" if $@;
sub audit {
sub audit {
@@
-57,18
+60,19
@@
sub audit {
# CouchDB::_store_audit( "$time.$package.$url" => $data );
# $data->{_id} = "$time.$package.$url";
# CouchDB::_store_audit( "$time.$package.$url" => $data );
# $data->{_id} = "$time.$package.$url";
- $audit->insert( $data );
+#
+ if ( $audit ) {
+ $audit->insert( $data );
+ } else {
+ warn "AUDIT ",dump($data);
+ }
}
sub query {
}
sub query {
- my ( $from_t, $callback ) = @_;
- my $q;
- $q->{'package.time'} = { '$lt' => $from_t * 1 } if $from_t;
-# $q->{'package.name'} = { '$ne' => 'syslogd' };
- $q->{'tag'} = { '$ne' => 'CRON' };
+ my ( $q, $callback ) = @_;
warn "# query ", dump($q);
warn "# query ", dump($q);
- $audit->ensure_index({
'package.name' => 1 })
;
+ $audit->ensure_index({
$_ => 1 }) foreach keys %$q
;
my $cursor = $audit->query($q)->sort({ 'package.time' => -1 })->limit( 100 );
while( my $o = $cursor->next ) {
$callback->( $o );
my $cursor = $audit->query($q)->sort({ 'package.time' => -1 })->limit( 100 );
while( my $o = $cursor->next ) {
$callback->( $o );