5 use POSIX qw(strftime);
8 use Data::Dump qw(dump);
11 my $path = '/home/nodelogs/c405f97667784094bca5cfa52af0bcf1/';
13 # select _id,json->'received',time,to_timestamp((json->>'received')::int8/1000) - interval '1 hour' from nodelog ;
15 my $dbh = DBI->connect("dbi:Pg:dbname=eg5120", "dpavlin", "", { RaiseError => 1 });
16 warn "# truncate table nodelog";
17 $dbh->do( qq{ truncate table nodelog } ); # FIXME
18 my $sth = $dbh->prepare(qq{insert into nodelog (time,json) values (?,?)});
20 foreach my $filename (
21 sort(glob("$path/node-red-out__2023-07-*")),
22 "$path/node-red-out.log"
25 open(my $log, '<', $filename);
28 my $year = $1 if $filename =~ m/__(20\d\d)-/;
29 $year ||= (localtime)[5] + 1900;
33 #warn "## $in_json -->$_<--\n";
34 ## XXX debug 1 in node-red with logging to system console
35 if ( m/(\d+ \w+)\s+(\d\d:\d\d:\d\d) - \Q[info] [debug:debug 1]\E/ ) {
36 $time = $1 . ' ' . $year . ' ' . $2;
37 #warn "# time $time\n";
38 } elsif ( $_ eq '{' ) {
42 } elsif ( $in_json ) {
44 s/\s(\S+):\s/"$1":/g; # fix names quoting
45 s/'/"/g; # replace ' with "
51 warn ">>> $time [[[[ $json ]]]]";
52 write_file '/dev/shm/json', $json;
53 $sth->execute( $time, $json );