/[pxelator]/lib/PXElator/store.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/store.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 497 - (show annotations)
Sun Jan 31 18:28:38 2010 UTC (14 years, 5 months ago) by dpavlin
File size: 1526 byte(s)
remove messages from CRON

1 package store;
2
3 use warnings;
4 use strict;
5
6 use POSIX;
7 use Time::HiRes qw/time/;
8 use Data::Dump qw(dump);
9
10 #use CouchDB;
11
12 use MongoDB;
13
14 my $conn = MongoDB::Connection->new;
15 our $db = $conn->get_database( 'pxelator' );
16 our $audit = $db->get_collection( 'audit' );
17
18
19 sub audit {
20 my $data = pop @_;
21
22 my $url = join(' ', @_);
23 $url =~ s/\s+-\S+//g; # remove command line options
24 $url =~ s/\W+/-/g;
25
26 my $time = time();
27
28 my @caller = caller(0);
29 $caller[3] = (caller(1))[3];
30 $caller[3] =~ s{^.+::}{}; # stip package name from sub
31 $data->{package} = {
32 time => $time,
33 name => $caller[0],
34 line => $caller[2],
35 caller => $caller[3],
36 };
37
38 if ( $ENV{DEBUG} ) {
39
40 my $caller;
41 my $depth = 0;
42 while ( my @c = caller($depth) ) {
43 push @$caller, [ @c ];
44 $depth++;
45 }
46
47 $data->{caller} = $caller;
48
49 }
50
51 # carp 'audit ', dump($data);
52
53 # $time = int($time); # reduce granularity for url
54 $time = strftime("%Y-%m-%d.%H:%M:%S", localtime $time);
55 my $package = $caller[0];
56
57 # CouchDB::_store_audit( "$time.$package.$url" => $data );
58
59 # $data->{_id} = "$time.$package.$url";
60 $audit->insert( $data );
61 }
62
63
64 sub query {
65 my ( $from_t, $callback ) = @_;
66 my $q;
67 $q->{'package.time'} = { '$lt' => $from_t * 1 } if $from_t;
68 # $q->{'package.name'} = { '$ne' => 'syslogd' };
69 $q->{'tag'} = { '$ne' => 'CRON' };
70 warn "# query ", dump($q);
71 $audit->ensure_index({ 'package.name' => 1 });
72 my $cursor = $audit->query($q)->sort({ 'package.time' => -1 })->limit( 100 );
73 while( my $o = $cursor->next ) {
74 $callback->( $o );
75 }
76 }
77
78 1;

  ViewVC Help
Powered by ViewVC 1.1.26