Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

symgryph's scratchpad

by symgryph (Sexton)
on Jun 06, 2007 at 19:45 UTC ( #619662=scratchpad: print w/replies, xml ) Need Help??

I am trying to get some data from my logs into a postgres database. Included in the program is the 'data' I am slurping, under 'data'. I know that the way it is written it won't work, but it works fine from standard in. I get the following error message when running the program: DBI::st=HASH(0x8757070)->_prepare(...): attribute parameter '' is not a hash ref at /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/DBD/ line 190, <> line 1. The database table looks like this:
---------------+-----------------------------+------------------------ +------------------------------------ date_combined | timestamp without time zone | origin | integer | action | text | if_name | text | if_dir | text | src | inet | dst | inet | proto | text | rule | integer | service | integer | s_port | integer | icmp | text | icmp_type | text | primary_key | bigint | not null default nextva +l('logs_primary_key_seq'::regclass) When I try the following code: #!/usr/bin/perl -w use DBI; my $dbname = 'logs'; my $dbh = DBI->connect("dbi:Pg:dbname=$dbname"); if (!$dbh) { die "Err Couldn't open connection: ".$DBI::errstr."\n"; } my $insert_query = "INSERT INTO logs (origin, action, if_name, if_dir, + src, dst, proto, rule, service,s_port, icmp_type, icmp_code) values +(?,?,?,?,?,?,?,?,?,?,?,?,?)"; $datematch = qr/(\d{1,2})([a-z]{3})(\d{4})/io; %months = ( Jan => "January", Feb => "February", Mar => "March", Apr => "April", May => "May", Jun => "June", Jul => "July", Aug => "August", Sep => "September", Oct => "October", Nov => "November", Dec => "December" ); while (<>) { my @fields = split (/\|/); $i++; # remove the leading space padding and reformat the date field $fields[1] =~ s/^\ //; $fields[1] =~ s/$datematch/$months{$2}\ $1\,$3/; my $date = "$fields[1] $fields[2]"; my $date = "$fields[1] $fields[2]"; foreach $field (3, 11, 12) { if ($fields[$field] eq "") { $fields[$field] = ""; } } for ($i = 1; $i < $#fields; $i++) { $fields[$i] =~ s/\'//g; } my $numrows = $dbh->do($insert_query,$date,$fields[3],$fields[5],$fiel +ds[7],$fields[8],$fields[11],$fields[12],$fields[13],$fields[14],$fie +lds[15],$fields[16],$fields[17],$fields[18]); if (!$numrows) { die "Failed to insert entry number $i:".$dbh->errstr."\n"; } @fields=""; } _DATA 2|9Oct2007|23:59:00||log|accept||eth-s1/s2p1c0|inbound|VPN- +1 & FireWall-1||||tcp|21|80|1326||||||||||||||||| +||||
"Two Wheels good, Four wheels bad."
Log In?

What's my password?
Create A New User
[marioroy]: Naming things can be difficult, sometimes more so that the actual code :)
[karlgoethebier]: Lady_Aleena: You need to jump to some conclusion
[Lady_Aleena]: And what would I rename RolePlaying/Random .pm to if I move all the RolePlaying/Random modules to just Random? Random/ Random/, maybe lowercase the file name to indicate it is a bit different? I don't know yet.
[marioroy]: What does Random do?
[karlgoethebier]: https://www. v=42WNHGr1jGI
[Lady_Aleena]: karlgoethebeir, I finished another project tonight, making a module which printed stop printing. It was a headache and a half.
[karlgoethebier]: Lady_Aleena: Try it!
[Lady_Aleena]: marioroy, it has 3 subroutines which can be fed data to generate random things. See here.

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2017-05-29 08:58 GMT
Find Nodes?
    Voting Booth?