On Wed, 21 Nov 2001 03:12:39 -0500, Aaron Johnson wrote:
> 
> Can you please give a more detailed example of how one would setup
> Stem to do a simple email when a system fails for example?

I saw POE mentioned in other threads, and I thought the list might be
interested in a mock-up of your example in POE.

This example uses components that don't exist yet, so it won't
actually work.  It also uses direct component-to-component messages,
and they don't work yet.  They're discussed here, though:

  http://poe.perl.org/?POE_Design/codeless_callbacks

P5EE and POE have other design goals in common.  Please see:

  http://poe.perl.org/?POE_Design/standard_interfaces
  http://poe.perl.org/?POE_Design/a_class_to_encapsulate_messages
  http://poe.perl.org/?POE_Design/POE::Object
  http://poe.perl.org/?POE_development_tools

The code follows.  Thanks!

-- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sourceforge.net

#!/usr/bin/perl

use warnings;
use strict;

use POE;
use POE::Component::Sendmail;
use POE::Component::HostWatcher;

# Start a Sendmail component.  It's job is to send mail when it
# receives a "send_mail" message.  The e-mail's headers and body are
# part of the send_mail message.  Several Sendmail components can
# exist in the same program; their aliases identify them.

POE::Component::Sendmail->spawn
  ( Alias    => "mail_sender",
    MxHosts  => qw( mail.somewhere.com
                    mail2.somewhere.com
                    mail.sa-home.com
                  ),
  );

# Start a component that pings hosts and emits messages when they
# disappear from the network or become reachable again.  Host status
# is determined by a consecutive number of ping failures or successes.
# Each emitted status message is accompanied by a host name.

POE::Component::HostWatcher->spawn
  ( Alias => "host_watcher",
    Hosts => { "www1.somewhere.com", 10,  # ping every 10s
               "www2.somewhere.com", 15,  # ping every 15s
               "www3.somewhere.com", 20,  # ping every 20s
             },

    ConsecutiveFailures  => 3,
    ConsecutiveSuccesses => 3,

    # Pass HostDown and HostUp messages to a Sendmail component.  Use
    # custom code to turn HostWatcher's host names into e-mail.
    # See: http://poe.perl.org/?POE_Design/codeless_callbacks

    HostDown => [ mail_sender => send_mail => \&build_host_down_message ],
    HostUp   => [ mail_sender => send_mail => \&build_host_up_message   ],
  );

# Translate HostWatcher messages into Sendmail messages.  The function
# for building host-up messages is omitted.

sub build_host_down_message {
  my $host = shift;

  return
    { To      => "admin\@somewhere.com",
      From    => "hostwatcher\@somewhere.com",
      Subject => "$host is down",
      Body    => [ "Sorry to disturb you, but this host is down:",
                   "",
                   "\t", $host,
                   "",
                   "-- HostWatcher",
                 ],
    };
}

# Run the main loop.  This step can be hidden in an initialization
# routine.

$poe_kernel->run();
exit 0;

__END__

Reply via email to