#!/bin/perl
#
# Example script for using VBTK::Server.  This will be your most complicated
# script, but just follow the comments and it should make sense.

use VBTK::Server;

# Set some host-specific defaults.  This allows us to use the same script
# on both vbserver machines and just vary the things which need to be different.
#
# The prefix is a string which will be appended as the first segment of all
# object names reported to the VBServer which start with '.'.  

my ($prefix,$remoteURI);
if($HOST eq 'sfoServer') {
    ($prefix,$remoteURI) = ('sfo',"http://nycServer:$VBPORT");
} elsif ($HOST eq 'nycServer') {
    ($prefix,$remoteURI) = ('nyc',"http://sfoServer:$VBPORT");
} else {
    die("Not supposed to run vbserver on this machine");
};

# Setup email and paging actions for your sysadmins
new VBTK::Actions::Email (
    Name  => 'emailSA',
    Email => 'sa1@mydomain.com,sa2@mydomain.com' );

#new VBTK::Actions::Page (
#    Name  => 'pageSA',
#    Email => 'page.sa1@mydomain.com,page.sa2@mydomain.com' );

#new VBTK::Actions::Email (
#    Name  => 'emailDBA',
#    Email => 'dba1@mydomain.com,dba2@mydomain.com' );

#new VBTK::Actions::Page (
#    Name  => 'pageDBA',
#    Email => 'page.dba1@mydomain.com,page.dba2@mydomain.com' );

# Initialize a server object.
$server = new VBTK::Server (
     ObjectPrefix	  => $prefix,
     HousekeepingInterval => 60 );

# Setup heartbeat connections to the other VB server    
$server->addRemoteServer (
    RemoteURI  => $remoteURI );
    
# Create templates to match up status change actions with objects

# DBA-related objects
#$server->addTemplate (
#    Pattern             => 'db\.dbspace|db\.logins',
#    StatusChangeActions => {
#    	Failed  => 'pageDBA,emailDBA',
#    	Expired => 'pageDBA,emailDBA',
#    	Warning => 'emailDBA' } );

# Critical objects, page and email
#$server->addTemplate (
#    Pattern 		=> 'nyc.*http|mainserver.*ping',
#    StatusChangeActions => { 
#        Failed  => 'emailSA',
#        Expired => 'emailSA' } );

# Everything else, just email
$server->addTemplate (
    Pattern 		=> '.*',
    StatusChangeActions => { 
        Failed  => 'emailSA',
        Expired => 'emailSA',
    	Warning => 'emailSA' } );

# Start the server listening and handling requests.
$server->run;
