root/honeyclient/tags/exp/PRE-mbriggs-db/bin/StartAgent.pl

Revision 13, 2.0 kB (checked in by kindlund, 2 years ago)

Initialized public repository with 0.9 release.

  • Property svn:executable set to *
Line 
1 #!perl -w
2
3 use strict;
4 use warnings;
5 use Carp ();
6
7 use HoneyClient::Agent;
8 use HoneyClient::Util::SOAP qw(getClientHandle);
9 use Data::Dumper;
10 use MIME::Base64 qw(decode_base64 encode_base64);
11 use Storable qw(thaw nfreeze);
12
13 our ($stub, $som);
14 our $URL = HoneyClient::Agent->init();
15
16 our $agentState = undef;
17 my $tempState = undef;
18
19 print "URL: " . $URL. "\n";
20
21 sub _watchdogFaultHandler {
22
23     # Extract arguments.
24     my ($class, $res) = @_;
25
26     # Construct error message.
27     # Figure out if the error occurred in transport or over
28     # on the other side.
29     my $errMsg = $class->transport->status; # Assume transport error.
30
31     if (ref $res) {
32         $errMsg = $res->faultcode . ": ".  $res->faultstring . "\n";
33     }
34
35     print "Watchdog fault detected, recovering Agent daemon.\n";
36     # XXX: Reenable this, eventually.
37 #    Carp::carp __PACKAGE__ . "->_watchdogFaultHandler(): Error occurred during processing.\n" . $errMsg;
38
39
40     # Regardless of the error, destroy the Agent process and reinitialize it.
41     # XXX: Sanity check this, eventually.
42     HoneyClient::Agent->destroy();
43
44     $URL = HoneyClient::Agent->init();
45
46     # Restore state information.
47     $som = $stub->updateState(encode_base64(nfreeze($agentState)));
48 }
49
50 $stub = getClientHandle(address   => 'localhost',
51                         namespace => 'HoneyClient::Agent',
52                         fault_handler => \&_watchdogFaultHandler);
53                
54 for (;;) {
55     # TODO: Make this a programmatic value.
56     sleep (5);
57     $som = $stub->getState();
58     if (defined($som) and (ref($som) eq "SOAP::SOM")) {
59         $tempState = $som->result();
60         if (defined($tempState)) {
61             # Make sure the new state is parsable, before saving it.
62             eval {
63                 $tempState = thaw(decode_base64($tempState));
64             };
65             if (!$@) {
66                 $agentState = $tempState;
67             }
68         }
69     }
70 }
71
72 HoneyClient::Agent->destroy();
Note: See TracBrowser for help on using the browser.