5 # This script will log headers and other data to a database
6 # for further analysis by parsing a feed from INN.
8 # It is part of the NewsStats package.
10 # Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
12 # It can be redistributed and/or modified under the same terms under
13 # which Perl itself is published.
16 our $VERSION = "0.01";
18 push(@INC, dirname($0));
24 use Sys::Syslog qw(:standard :macros);
29 ################################# Main program #################################
31 ### read commandline options
32 my %Options = &ReadOptions('qd');
34 ### read configuration
35 my %Conf = %{ReadConfig('newsstats.conf')};
38 openlog($MySelf, 'nofatal,pid', LOG_NEWS);
39 syslog(LOG_NOTICE, "$MyVersion starting up.") if !$Options{'q'};
42 my $DBHandle = InitDB(\%Conf,0);
44 syslog(LOG_CRIT, 'Database connection failed: %s', $DBI::errstr);
45 while (1) {}; # go into endless loop to suppress further errors and respawning
47 my $DBQuery = $DBHandle->prepare(sprintf("INSERT INTO %s.%s (day,date,mid,timestamp,token,size,peer,path,newsgroups,headers) VALUES (?,?,?,?,?,?,?,?,?,?)",$Conf{'DBDatabase'},$Conf{'DBTableRaw'}));
52 # catch empty lines trailing or leading
56 # first line contains: mid, timestamp, token, size, peer, Path, Newsgroups
57 my ($Mid, $Timestamp, $Token, $Size, $Peer, $Path, $Newsgroups) = split;
58 # remaining lines contain headers
62 # empty line terminates this article
70 # parse timestamp to day (YYYY-MM-DD) and to MySQL timestamp
71 my $Day = time2str("%Y-%m-%d", $Timestamp);
72 my $Date = time2str("%Y-%m-%d %H:%M:%S", $Timestamp);
75 if (!$DBQuery->execute($Day, $Date, $Mid, $Timestamp, $Token, $Size, $Peer, $Path, $Newsgroups, $Headers)) {
76 syslog(LOG_ERR, 'Database error: %s', $DBI::errstr);
80 warn sprintf("-----\nDay: %s\nDate: %s\nMID: %s\nTS: %s\nToken: %s\nSize: %s\nPeer: %s\nPath: %s\nNewsgroups: %s\nHeaders: %s\n",$Day, $Date, $Mid, $Timestamp, $Token, $Size, $Peer, $Path, $Newsgroups, $Headers) if $Options{'d'};
84 $DBHandle->disconnect;
85 syslog(LOG_NOTICE, "$MySelf closing down.") if !$Options{'q'};
90 ################################ Documentation #################################
94 feedlog - log data from an INN feed to a database
102 See doc/README: Perl 5.8.x itself and the following modules from CPAN:
122 This script will log overview data and complete headers to a database
123 table for further examination by parsing a feed from INN. It will
124 parse that information and write it to a mysql database table in real
127 All reporting is done to I<syslog> via I<news> facility. If B<feedlog>
128 fails to initiate a database connection at startup, it will log to
129 I<syslog> with I<CRIT> priority and go in an endless loop, as
130 terminating would only result in a rapid respawn.
134 F<feedlog.pl> will read its configuration from F<newsstats.conf> which
135 should be present in the same directory via Config::Auto.
137 See doc/INSTALL for an overview of possible configuration options.
143 =item B<-V> (version)
145 Print out version and copyright information on B<yapfaq> and exit.
149 Print this man page and exit.
153 Output debugging information to STDERR while parsing STDIN. You'll
154 find that information most probably in your B<INN> F<errlog> file.
158 Suppress logging to syslog.
168 Set up a feed like that in your B<INN> F<newsfeeds> file:
170 ## gather statistics for NewsStats
173 :Tc,WmtfbsPNH,Ac:/path/to/feedlog.pl
175 See doc/INSTALL for further information.
185 =item F<NewsStats.pm>
187 Library functions for the NewsStats package.
189 =item F<newsstats.conf>
191 Runtime configuration file for B<yapfaq>.
197 Please report any bugs or feature requests to the author or use the
198 bug tracker at L<http://bugs.th-h.de/>!
214 This script is part of the B<NewsStats> package.
218 Thomas Hochstein <thh@inter.net>
220 =head1 COPYRIGHT AND LICENSE
222 Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
224 This program is free software; you may redistribute it and/or modify it
225 under the same terms as Perl itself.