nicely format latest entries in MongoDB
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 25 Jan 2010 18:30:47 +0000 (18:30 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 25 Jan 2010 18:30:47 +0000 (18:30 +0000)
lib/PXElator/httpd.pm

index 3bca985..99ae21a 100644 (file)
@@ -18,6 +18,7 @@ use File::Slurp;
 #use JSON;
 use IO::Socket::INET;
 use Regexp::Common qw/net/;
+use POSIX qw(strftime);
 
 our $title;
 
@@ -76,8 +77,8 @@ qq{
 <a target=server href=/brctl >brctl</a>
 <a target=server href=/ip >ip</a>
 |
-<a target=store href=$store_url >store</a>
-<a target=store href=/store/query >query</a>
+<a target=store href=$store_url >MongoDB</a>
+<a target=store href=/store/latest >latest</a>
 |
 <a target=client href=/nmap >nmap</a>
 <a target=client href=/client >client</a>
@@ -269,7 +270,7 @@ warn "XXX pids = ", dump( $daemons::pids );
                        |
                        ;
 
-       } elsif ( $path =~ m{^/store/query} ) {
+       } elsif ( $path =~ m{^/store/latest} ) {
                print $client ok
                        , qq|
 <style type=text/css>
@@ -298,7 +299,8 @@ warn "XXX pids = ", dump( $daemons::pids );
                        delete( $o->{_id} );
 
                        if ( ! @cols ) {
-                               @cols = keys %$p;
+                               #@cols = keys %$p;
+                               @cols = qw( time name );
                                print $client qq|<tr><th>|
                                        , join(qq|</th><th>|, @cols)
                                        , qq|</th><th></th></tr>|
@@ -306,13 +308,12 @@ warn "XXX pids = ", dump( $daemons::pids );
                        }
 
                        # XXX sigh, dump dies if we don't do this
-                       delete $o->{$_} foreach ( grep { ! defined $o->{$_} } keys %$o );
+#                      delete $o->{$_} foreach ( grep { ! defined $o->{$_} } keys %$o );
 
-                       print $client qq|<tr$s1><td>|
-                               , join(qq|</td><td>|, map { $p->{$_} } @cols )
-                               , qq|</td><td><pre>|
-                               , dump( $o )
-                               , qq|</pre></td></tr>\n|
+                       print $client qq|<tr$s1>|
+                               , strftime( qq|<td title="%Y-%m-%d">%H:%M:%S</td>|, localtime($p->{time}) )
+                               , map { qq|<td>$_<td>| } ( $p->{name} , html::pre_dump($o) )
+                               , qq|</tr>\n|
                        ;
                        ( $s1, $s2 ) = ( $s2, $s1 );
                });