How do I log into a database at startup/reload, and pass the database
handle, or expose it to subsequent rules? I have successfully logged
into a database and select suitable information. Unfortunately, if I
comment out the 'use DBI' and 'DBI->connect', and insert a rule (rule 1)
that is caught on a startup internal event, the same lookup fails when
dereferencing the database handle. Since the database is defined in a
previous rule, it is unitialized at the time of the call in rule 2.
How do I pass the database handle from one rule to another?
Please advise,
Tim
--
Tim Peiffer
Network Support Engineer
Office of Information Technology
University of Minnesota/NorthernLights GigaPOP
+1 612 626-7884 (desk)
# Rule 1 log into the database
type=Single
desc=Module load and range setup
continue=TakeNext
ptype=SubStr
pattern=SEC_STARTUP
context=[SEC_INTERNAL_EVENT]
action=eval %dbh ( \
use DBI; \
my $dbh =
DBI->connect("DBI:mysql:database=sedb;host=localhost", \
"sec", "correlator"); \
$dbh->{RaiseError} = 1; \
$dbh->{AutoCommit} = 1; \
);
# Rule 2, Log into the database, select a matching type, contact and
description.
# Since $type, $contact, and $descr are exposed, assign in subsequent
eval statements.
type=Single
desc=Peer Lookup
continue=TakeNext
ptype=RegExp
pattern=Peer (.*)
action= \
eval %type ( \
use DBI; \
my $dbh =
DBI->connect("DBI:mysql:database=sedb;host=localhost", \
"sec", "correlator"); \
$dbh->{RaiseError} = 1; \
$dbh->{AutoCommit} = 1; \
my $sth = $dbh->prepare( "SELECT type,contact,descr FROM
peering where ip='$1'" ); \
my $rv = $sth->execute; \
($type,$contact,$descr) = $sth->fetchrow ; \
return "$type"; \
); \
eval %contact ( return "$contact" ; ); \
eval %descr ( return "$descr" ; ); \
logonly %s ip=$1 type='%type' contact='%contact' descr='%descr' ;
x-128-101-232-110:database peiffer$ ../sec.pl -conf=./sec.cfg -input=-
-log=- -debug=4 -intevents
[...]
Peer 1.1.1.1
Error evaluating code 'my $sth = $dbh->prepare( "SELECT
type,contact,descr FROM peering where ip='1.1.1.1'" ); my $rv
= $sth->execute; ($type,$contact,$descr) = $sth->fetchrow
; return "$type"; ': Can't call method "prepare" on an
undefined value at (eval 14) line 1.
Fri Dec 10 19:58:17 2010: Error evaluating code 'my $sth =
$dbh->prepare( "SELECT type,contact,descr FROM peering where
ip='1.1.1.1'" ); my $rv = $sth->execute;
($type,$contact,$descr) = $sth->fetchrow ; return "$type";
': Can't call method "prepare" on an undefined value at (eval 14) line 1.
Use of uninitialized value $main::SEC::contact in string at (eval 15)
line 1.
Use of uninitialized value $main::SEC::descr in string at (eval 16) line 1.
Peer Lookup ip=1.1.1.1 type='%type' contact='' descr=''
Fri Dec 10 19:58:17 2010: Peer Lookup ip=1.1.1.1 type='%type' contact=''
descr=''
# sec db table peering..
DROP TABLE peering;
CREATE TABLE peering (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
ip varchar(15),
type varchar(15),
contact varchar(15),
descr varchar(80)
);
INSERT INTO peering (ip,type,contact,descr)
VALUES ('1.1.1.1', 'connector', 'me', 'mypeer with you');
mysql> select * from peering;
+----+---------+-----------+---------+-----------------+
| id | ip | type | contact | descr |
+----+---------+-----------+---------+-----------------+
| 1 | 1.1.1.1 | connector | me | mypeer with you |
+----+---------+-----------+---------+-----------------+
------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages,
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev
_______________________________________________
Simple-evcorr-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/simple-evcorr-users