If you use poing and have a WAP / WML capable phone, you might
be interested in this.  This patch enables a `log_wml' directive in
your ~/.poingrc file that specifies the output filename that should be
created (e.g. /var/www/htdocs/poing.wml; make sure that you've told
your web server that .wml files should be served with a content type
of `text/vnd.wap.wml').


        Every update a WML file is created which contains a single
page that looks something like:


    Poing Status
    2002-01-31 01:15:51 EST
    + beast.phydeaux.org
    + rtr-atl-0
    + rtr-atl-1
    3 rtr-dfw-0
    + rtr-hou-0
    + rtr-slc-0
    ! zoidberg


        The legend is '+' for host is up, 1-9 for host has been down
that many of the past 10 update intervals, and ! if it's been down for
the past 10 update intervals.


---->8 Cut here 8<----
Index: poing.perl
--- poing.perl  Thu Jan 31 01:14:20 2002
+++ poing.wml   Thu Jan 31 01:14:00 2002
@@ -24,6 +24,8 @@
 # You may write ups and downs to a log file.  It's off by default.
 my $log_filename = '';
 
+my $wml_fh;
+
 #------------------------------------------------------------------------------
 # Helpful functions for displaying fractions.
 
@@ -401,6 +403,10 @@
     }
   }
 
+  if( defined $wml_fh ) {
+    wml_log( $wml_fh, $heap->{host_rec} );
+  }
+
   # Hack to specify the maximum run time, in hours.
   if (@ARGV and ($ARGV[0] =~ /^\d*\.?\d+$/)) {
     if ((time - $^T) < ($ARGV[0] * 3600)) {
@@ -436,6 +442,87 @@
   $heap->{host_rec}->{$address}->[HOST_RESPONSE] = $time;
 }
 
+sub wml_down {
+  my $fh = shift;
+
+  my $downtime = strftime "%Y-%m-%d %H:%M:%S %Z", localtime;
+
+  seek( $fh, 0, 0 );
+  truncate( $fh, 0 );
+
+  print $fh <<EOT;
+<?xml version="1.0"?>
+<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
+ "http://www.wapforum.org/DTD/wml_1.1.xml";>
+
+<wml>
+  <head>
+    <meta http-equiv="Cache-Control" content="no-cache" />
+  </head>
+
+  <card id="main" title="Poing Status">
+    <p mode="nowrap">
+      Poing shutdown at<br />
+      $downtime
+    </p>
+
+  </card>
+
+</wml>
+
+EOT
+
+  return
+}
+
+sub wml_log {
+  my $fh = shift;
+  my %hosts = %{ shift() };
+
+  seek( $fh, 0, 0 );
+  truncate( $fh, 0 );
+
+  my $timestamp = strftime "%Y-%m-%d %H:%M:%S %Z", localtime;
+
+  print $fh <<EOT;
+<?xml version="1.0"?>
+<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
+ "http://www.wapforum.org/DTD/wml_1.1.xml";>
+
+<wml>
+  <head>
+    <meta http-equiv="Cache-Control" content="no-cache" />
+  </head>
+
+  <card id="main" title="Poing Status">
+    <p mode="nowrap">
+      Poing Status<br />
+      $timestamp<br />
+EOT
+
+  foreach( sort
+          { $hosts{$a}->[HOST_NAME] cmp $hosts{$b}->[HOST_NAME] }
+          keys %hosts )
+  {
+    my $is_dead = $hosts{$_}->[HOST_DEAD];
+    my $status;
+    unless( $is_dead ) {
+      $status = '+ ';
+    } else {
+      my $ticker_tail = substr( $hosts{$_}->[HOST_TICKER], -10 );
+      my $how_dead = ( $ticker_tail =~ y/-/-/ );
+      $status = ( $how_dead < 10 ? $how_dead : '!' );
+      $status .= ' ';
+    }
+    print $fh "      $status",
+             $hosts{$_}->[HOST_NAME], "<br />\n"
+  }
+
+  print $fh "    </p>\n  </card>\n</wml>\n";
+
+  return;
+}
+
 #------------------------------------------------------------------------------
 # Load new stuff from a configuration file.
 
@@ -476,6 +563,16 @@
     next;
   }
 
+  if( /^log_wml\s+(.+?)$/ ) {
+    open( $wml_fh, ">$1" )
+      or die "Can't open wml log `$1' for writing: $!\n";
+    truncate( $wml_fh, 0 );
+
+    select( (select($wml_fh), $| = 1 )[0] );
+
+    next;
+  }
+
   # host address
   if (/^host (\d+\.\d+\.\d+\.\d+)$/) {
     my $address = inet_aton($1);

---->8 Cut here 8<----

-- 
Fletch                | "If you find my answers frightening,       __`'/|
[EMAIL PROTECTED]   |  Vincent, you should cease askin'          \ o.O'
770 933-0600 x211(w)  |  scary questions." -- Jules                =(___)=
                      |                                               U

Reply via email to