root/honeyclient/tags/exp/PRE-kindlund-filesystem/bin/StartAgent.pl

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

sc: merging branch using tags svn+ssh://kindlund@www.honeyclient.org/home/svn/honeyclient/honeyclient/tags/bug/PRE-42 and svn+ssh://kindlund@www.honeyclient.org/home/svn/honeyclient/honeyclient/tags/bug/POST-42

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