#!/usr/bin/perl # # netacct-savelog-mysql.pl # # Developed by Lubomir Host 'rajo' # Copyright (c) 2005 Platon SDG, http://platon.sk/ # Licensed under terms of GNU General Public License. # All rights reserved. # # Changelog: # 2005-01-23 - created # # $Platon$ use strict; use DBI qw(:sql_types); use Time::HiRes qw(gettimeofday sleep usleep); use POSIX qw(strftime); # declaration: {{{ use vars qw ( $database $dbh $sql_insert $update_interval ); # functions sub PrepareSQL(); # }}} $update_interval = 10; # seconds $database = "DBI:mysql:database=system;host=localhost;user=syswatcher;password=;compression=0"; while (! ($dbh = DBI->connect($database))) { print_info("Database connection failed, reconnecting in $update_interval seconds...($DBI::errstr)"); sleep $update_interval; } PrepareSQL(); while (my $line = ) { chomp $line; my ($created, $ip_proto, $source_ip, $source_port, $dest_ip, $dest_port, $packet_count, $data_size, $interface, $ppp_user) = split(/\s+/, $line); $sql_insert->execute( strftime("%Y-%m-%d %X", localtime($created)), $ip_proto, $source_ip, $source_port, $dest_ip, $dest_port, $packet_count, $data_size, $interface, $ppp_user); } $dbh->disconnect(); sub PrepareSQL() { # {{{ $sql_insert = $dbh->prepare(" INSERT INTO net_acct (created, ip_proto, source_ip, source_port, dest_ip, dest_port, packet_count, data_size, interface, ppp_user) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "); } # }}} # vim: ts=4 # vim600: fdm=marker fdl=0 fdc=3