log2sql: added UPDATE support to exec_query
This commit is contained in:
parent
55e9664824
commit
63701ca65f
15
log/log2sql
15
log/log2sql
@ -120,8 +120,7 @@ sub create_message {
|
||||
my ( $fid, $ts, $pid, $message ) = @_;
|
||||
|
||||
my ($host, $ip) = split /\s/, $message;
|
||||
$ip = substr $ip, 1, -1; # remote brackets
|
||||
#print "new from $ip\n";
|
||||
$ip = substr $ip, 1, -1; # remove brackets
|
||||
|
||||
my $id = exec_query(
|
||||
"INSERT INTO message SET file_id=?, connect_start=FROM_UNIXTIME(?), qp_pid=?, ip=INET_ATON(?)",
|
||||
@ -131,6 +130,7 @@ sub create_message {
|
||||
if ( $host && $host ne 'Unknown' ) {
|
||||
exec_query( "UPDATE message SET hostname=? WHERE id=?", [ $host, $id ] );
|
||||
};
|
||||
#warn "host updated: $host\n";
|
||||
};
|
||||
|
||||
sub insert_plugin {
|
||||
@ -200,6 +200,7 @@ sub parse_logfile {
|
||||
next;
|
||||
};
|
||||
|
||||
#warn "type: $type\n";
|
||||
if ( $type eq 'plugin' ) {
|
||||
next if $plugin eq 'naughty'; # housekeeping only
|
||||
insert_plugin( $msg_id, $plugin, $message );
|
||||
@ -255,7 +256,7 @@ sub check_logfile {
|
||||
my $size = stat($path)->size or die "unable to get size for $path\n";
|
||||
my $exists;
|
||||
|
||||
# check if this tai file is in the DB as 'current'
|
||||
#warn "check if file $file is in the DB as 'current'\n";
|
||||
if ( $file =~ /^\@/ ) {
|
||||
$exists = exec_query(
|
||||
'SELECT * FROM log WHERE inode=? AND name=?',
|
||||
@ -277,7 +278,7 @@ sub check_logfile {
|
||||
[ $inode, $file ]
|
||||
);
|
||||
if ( @$exists ) {
|
||||
$exists = exec_query(
|
||||
exec_query(
|
||||
'UPDATE log SET size=? WHERE inode=? AND name=?',
|
||||
[ $size, $inode, 'current' ]
|
||||
);
|
||||
@ -522,6 +523,7 @@ sub exec_query {
|
||||
$err .= join(',', @params);
|
||||
};
|
||||
|
||||
#warn "err: $err\n";
|
||||
if ( $query =~ /INSERT INTO/ ) {
|
||||
my ( $table ) = $query =~ /INSERT INTO (\w+)\s/;
|
||||
$db->query( $query, @params );
|
||||
@ -529,8 +531,11 @@ sub exec_query {
|
||||
my $id = $db->last_insert_id(undef,undef,$table,undef) or die $err;
|
||||
return $id;
|
||||
}
|
||||
elsif ( $query =~ /^UPDATE/i ) {
|
||||
return $db->query( $query, @params );
|
||||
}
|
||||
elsif ( $query =~ /DELETE/ ) {
|
||||
$db->query( $query, @params )->hashes or die $err;
|
||||
$db->query( $query, @params ) or die $err;
|
||||
return $db->query("SELECT ROW_COUNT()")->list;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user