added a test to spectre at startup to make sure it can connect to each webgui site

added a spectre ping function which will be useful for monitoring services like nagios and the wremonitor
removed references to the old theme systemm
This commit is contained in:
JT Smith 2006-04-28 15:23:34 +00:00
parent 363404b598
commit 5635534b4c
7 changed files with 151 additions and 23 deletions

View file

@ -502,7 +502,7 @@ sub addPrototypes {
collaborationTemplateId=>"PBtmpl0000000000000208",
threadTemplateId=>"PBtmpl0000000000000209",
postFormTemplateId=>"PBtmpl0000000000000210"
},"pbproto000000000000001");
},"pbproto000000000000002");
}

View file

@ -15,6 +15,8 @@ package Spectre::Admin;
=cut
use strict;
use HTTP::Request;
use LWP::UserAgent;
use POE;
use POE::Component::IKC::Server;
use POE::Component::IKC::Specifier;
@ -86,6 +88,23 @@ sub debug {
#-------------------------------------------------------------------
=head2 error ( output )
Prints out error information.
=head3
=cut
sub error {
my $self = shift;
my $output = shift;
print "ADMIN: ".$output."\n";
$self->getLogger->error("ADMIN: ".$output);
}
#-------------------------------------------------------------------
=head3 getLogger ( )
Returns a reference to the logger.
@ -122,19 +141,70 @@ sub new {
my $logger = Log::Log4perl->get_logger($config->getFilename);
my $self = {_debug=>$debug, _config=>$config, _logger=>$logger};
bless $self, $class;
$self->runTests();
create_ikc_server(
port => $config->get("port"),
name => 'Spectre',
);
POE::Session->create(
object_states => [ $self => {_start=>"_start", _stop=>"_stop", "shutdown"=>"_stop"} ],
args=>[["shutdown"]]
object_states => [ $self => {_start=>"_start", _stop=>"_stop", "shutdown"=>"_stop", "ping"=>"ping"} ],
args=>[["shutdown","ping"]]
);
$self->{_workflow} = Spectre::Workflow->new($config, $logger, $debug);
$self->{_cron} = Spectre::Cron->new($config, $logger, $self->{_workflow}, $debug);
POE::Kernel->run();
}
#-------------------------------------------------------------------
=head2 ping ( )
Check to see if Spectre is alive. Returns "pong".
=cut
sub ping {
my ($kernel, $request) = @_[KERNEL,ARG0];
my ($data, $rsvp) = @$request;
$kernel->call(IKC=>post=>$rsvp,"pong");
}
#-------------------------------------------------------------------
=head2 runTests ( )
Executes a test to see if Spectre can establish a connection to WebGUI and get back a valid response.
=cut
sub runTests {
my $self = shift;
my $config = shift;
$self->debug("Running connectivity tests.");
my $configs = WebGUI::Config->readAllConfigs($self->config->getWebguiRoot);
foreach my $config (keys %{$configs}) {
$self->debug("Testing $config");
my $userAgent = new LWP::UserAgent;
$userAgent->agent("Spectre");
$userAgent->timeout(30);
my $url = "http://".$configs->{$config}->get("sitename")->[0].":".$self->config->get("webguiPort")."/?op=spectreTest";
my $request = new HTTP::Request (GET => $url);
my $response = $userAgent->request($request);
if ($response->is_error) {
$self->error("Couldn't connect to WebGUI site $config");
} else {
my $response = $response->content;
if ($response eq "subnet") {
$self->error("Spectre cannot communicate with WebGUI for $config, perhaps you need to adjust thhe spectreSubnets setting in this config file.");
} elsif ($response eq "spectre") {
$self->error("WebGUI connot communicate with Spectre for $config, perhaps you need to adjust the spectreIp or spectrePort setting the this config file.");
} elsif ($response ne "success") {
$self->error("Spectre received an invalid response from WebGUI while testing $config");
}
}
}
$self->debug("Tests completed.");
}
1;

View file

@ -219,6 +219,8 @@ sub getOperations {
'editSettings' => 'WebGUI::Operation::Settings',
'saveSettings' => 'WebGUI::Operation::Settings',
'spectreTest' => 'WebGUI::Operation::Spectre',
'viewStatistics' => 'WebGUI::Operation::Statistics',
'makePrintable' => 'WebGUI::Operation::Style',
@ -238,21 +240,6 @@ sub getOperations {
'purchaseSubscription' => 'WebGUI::Operation::Subscription',
'redeemSubscriptionCode' => 'WebGUI::Operation::Subscription',
'addThemeComponent' => 'WebGUI::Operation::Theme',
'addThemeComponentSave' => 'WebGUI::Operation::Theme',
'deleteTheme' => 'WebGUI::Operation::Theme',
'deleteThemeConfirm' => 'WebGUI::Operation::Theme',
'deleteThemeComponent' => 'WebGUI::Operation::Theme',
'deleteThemeComponentConfirm' => 'WebGUI::Operation::Theme',
'editTheme' => 'WebGUI::Operation::Theme',
'editThemeSave' => 'WebGUI::Operation::Theme',
'exportTheme' => 'WebGUI::Operation::Theme',
'importTheme' => 'WebGUI::Operation::Theme',
'importThemeSave' => 'WebGUI::Operation::Theme',
'importThemeValidate' => 'WebGUI::Operation::Theme',
'listThemes' => 'WebGUI::Operation::Theme',
'viewTheme' => 'WebGUI::Operation::Theme',
'cancelRecurringTransaction' => 'WebGUI::Operation::TransactionLog',
'deleteTransaction' => 'WebGUI::Operation::TransactionLog',
'deleteTransactionItem' => 'WebGUI::Operation::TransactionLog',

View file

@ -255,8 +255,7 @@ sub www_runCronJob {
$session->http->setMimeType("text/plain");
$session->http->setCacheControl("none");
unless (isInSubnet($session->env->get("REMOTE_ADDR"), $session->config->get("spectreSubnets"))) {
$session->errorHandler->security("make a Spectre cron job runner request, but we're only allowed to
accept requests from ".join(",",@{$session->config->get("spectreSubnets")}).".");
$session->errorHandler->security("make a Spectre cron job runner request, but we're only allowed to accept requests from ".join(",",@{$session->config->get("spectreSubnets")}).".");
return "error";
}
my $taskId = $session->form->param("taskId");

View file

@ -0,0 +1,57 @@
package WebGUI::Operation::Spectre;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::Utility;
use POE::Component::IKC::ClientLite;
=head1 NAME
Package WebGUI::Operation::Spectre
=head1 DESCRIPTION
Operations for Spectre.
=cut
#-------------------------------------------------------------------
=head2 www_spectreTest ( )
Spectre executes this function to see if WebGUI connectivity is working.
=cut
sub www_spectreTest {
my $session = shift;
$session->http->setMimeType("text/plain");
$session->http->setCacheControl("none");
unless (isInSubnet($session->env->get("REMOTE_ADDR"), $session->config->get("spectreSubnets"))) {
$session->errorHandler->security("make a Spectre workflow runner request, but we're only allowed to accept requests from ".join(",",@{$session->config->get("spectreSubnets")}).".");
return "subnet";
}
my $remote = create_ikc_client(
port=>$session->config->get("spectrePort"),
ip=>$session->config->get("spectreIp"),
name=>rand(100000),
timeout=>10
);
# Can't perform this test until I get smarter. =)
#return "spectre" unless $remote;
#my $result = $remote->post_respond('admin/ping');
#return "spectre" unless defined $result;
return "success";
}
1;

View file

@ -367,8 +367,7 @@ sub www_runWorkflow {
$session->http->setMimeType("text/plain");
$session->http->setCacheControl("none");
unless (isInSubnet($session->env->get("REMOTE_ADDR"), $session->config->get("spectreSubnets"))) {
$session->errorHandler->security("make a Spectre workflow runner request, but we're only allowed to
accept requests from ".join(",",@{$session->config->get("spectreSubnets")}).".");
$session->errorHandler->security("make a Spectre workflow runner request, but we're only allowed to accept requests from ".join(",",@{$session->config->get("spectreSubnets")}).".");
return "error";
}
my $instanceId = $session->form->param("instanceId");

View file

@ -19,19 +19,21 @@ use WebGUI::Config;
$|=1; # disable output buffering
my $help;
my $shutdown;
my $ping;
my $daemon;
my $run;
my $debug;
GetOptions(
'help'=>\$help,
'ping'=>\$ping,
'shutdown'=>\$shutdown,
'daemon'=>\$daemon,
'debug' =>\$debug,
'run' => \$run
);
if ($help || !($shutdown||$daemon||$run)) {
if ($help || !($ping||$shutdown||$daemon||$run)) {
print <<STOP;
S.P.E.C.T.R.E. is the Supervisor of Perplexing Event-handling Contraptions for
@ -49,6 +51,8 @@ if ($help || !($shutdown||$daemon||$run)) {
debug to standard out so that you can see exactly what
it's doing.
--ping Checks to see if Spectre is alive.
--run Starts Spectre without forking it as a daemon.
--shutdown Stops the running Spectre server.
@ -81,6 +85,18 @@ if ($shutdown) {
my $result = $remote->post('admin/shutdown');
die $POE::Component::IKC::ClientLite::error unless defined $result;
undef $remote;
} elsif ($ping) {
my $remote = create_ikc_client(
port=>$config->get("port"),
ip=>'127.0.0.1',
name=>rand(100000),
timeout=>10
);
die $POE::Component::IKC::ClientLite::error unless $remote;
my $result = $remote->post_respond('admin/ping');
die $POE::Component::IKC::ClientLite::error unless defined $result;
print "Spectre is Alive!\n" if ($result eq "pong");
undef $remote;
} elsif ($run) {
Spectre::Admin->new($config, $debug);
} elsif ($daemon) {