summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobi Oetiker <tobi@oetiker.ch>2007-08-13 11:49:27 +0200
committerTobi Oetiker <tobi@oetiker.ch>2007-08-13 11:49:27 +0200
commitc98e512bc9dd3f93eed5cad53476cc8b4fd803fd (patch)
tree2f0c01d7fdfc829a06d11c9e12b53f6920ff3cc8
parent546c89ee565a0cd905053f5e7edb6d50655a486f (diff)
downloadsmokeping-c98e512bc9dd3f93eed5cad53476cc8b4fd803fd.tar.gz
smokeping-c98e512bc9dd3f93eed5cad53476cc8b4fd803fd.tar.xz
master slave code drop to start debugging
-rw-r--r--CHANGES2
-rwxr-xr-xbin/smokeping.dist6
-rw-r--r--lib/Smokeping.pm55
-rw-r--r--lib/Smokeping/Slave.pm1
4 files changed, 48 insertions, 16 deletions
diff --git a/CHANGES b/CHANGES
index f9bad63..7bb8005 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+* first drop of the master/slave code added. now the debugging beginns. -- tobi
+
* fix uses of uninitialized value in the loss_background code
-- niko, reported by yilmaz.atag *abs.gov.au
diff --git a/bin/smokeping.dist b/bin/smokeping.dist
index 8314102..3fbb7cf 100755
--- a/bin/smokeping.dist
+++ b/bin/smokeping.dist
@@ -56,6 +56,12 @@ B<smokeping> [ B<--email> | B<--makepod> | B<--version> | B<--restart> ]
(to be used while building inside the smokeping distribution)
With --check : check the syntax of the generated examples.
+ --master-url=s Run smokeping in slave mode. Attach to master for config.
+
+ --shared-secret=s File containing the shared secret for talking to the server.
+
+ --cache-dir=s Directory for temporary data storage when running in slave mode.
+
=head1 DESCRIPTION
The B<smokeping> tool is the commandline part of the SmokePing system. Its
diff --git a/lib/Smokeping.pm b/lib/Smokeping.pm
index a5f47ec..7c79695 100644
--- a/lib/Smokeping.pm
+++ b/lib/Smokeping.pm
@@ -3263,7 +3263,9 @@ sub cgi ($) {
load_cfg shift;
my $q=new CGI;
initialize_cgilog();
- if ($q->param(-name=>'secret') && $q->param(-name=>'target') ) {
+ if ($q->param(-name=>'slave')) { # a slave is calling in
+ Smokeping::Master::answer_slave($cfg,$q);
+ } elsif ($q->param(-name=>'secret') && $q->param(-name=>'target') ) {
my $ret = update_dynaddr $cfg,$q;
if (defined $ret and $ret ne "") {
print $q->header(-status => "404 Not Found");
@@ -3467,7 +3469,8 @@ sub main (;$) {
$opt{filter}=[];
GetOptions(\%opt, 'version', 'email', 'man:s','help','logfile=s','static-pages:s', 'debug-daemon',
'nosleep', 'makepod:s','debug','restart', 'filter=s', 'nodaemon|nodemon',
- 'config=s', 'check', 'gen-examples', 'reload') or pod2usage(2);
+ 'config=s', 'check', 'gen-examples', 'reload',
+ 'master-url=s','cache-dir=s','shared-secret=s') or pod2usage(2);
if($opt{version}) { print "$VERSION\n"; exit(0) };
if(exists $opt{man}) {
if ($opt{man}) {
@@ -3495,20 +3498,36 @@ sub main (;$) {
exit 0;
}
initialize_debuglog if $opt{debug} or $opt{'debug-daemon'};
- my $cfgfile = $opt{config} || $defaultcfg;
- if(defined $opt{'check'}) { verify_cfg($cfgfile); exit 0; }
- if($opt{reload}) {
- load_cfg $cfgfile, 'noinit'; # we need just the piddir
- kill_smoke $cfg->{General}{piddir}."/smokeping.pid", SIGHUP;
- print "HUP signal sent to the running SmokePing process, exiting.\n";
- exit 0;
- };
- load_cfg $cfgfile;
+ my $slave_cfg;
+ if (exists $opt{'master-url'}){ # ok we go slave-mode
+ open my $fd, "<$secret" or die "ERROR: opening $secret: $!\n";
+ chomp(my $secret = <$fd>);
+ close $fd;
+ $slave_cfg = {
+ master_url => $opt{'master-url'},
+ cache_dir => $opt{'cache-dir'},
+ shared_secret => $secret,
+ };
+ # this should get us a config set from the server
+ Smokeping::Slave::submit_results($slave_cfg,\$::cfg);
+ } else {
+ my $cfgfile = $opt{config} || $defaultcfg;
+ if(defined $opt{'check'}) { verify_cfg($cfgfile); exit 0; }
+ if($opt{reload}) {
+ load_cfg $cfgfile, 'noinit'; # we need just the piddir
+ kill_smoke $cfg->{General}{piddir}."/smokeping.pid", SIGHUP;
+ print "HUP signal sent to the running SmokePing process, exiting.\n";
+ exit 0;
+ };
+ load_cfg $cfgfile;
- if(defined $opt{'static-pages'}) { makestaticpages $cfg, $opt{'static-pages'}; exit 0 };
- if($opt{email}) { enable_dynamic $cfg, $cfg->{Targets},"",""; exit 0 };
+ if(defined $opt{'static-pages'}) { makestaticpages $cfg, $opt{'static-pages'}; exit 0 };
+ if($opt{email}) { enable_dynamic $cfg, $cfg->{Targets},"",""; exit 0 };
+ }
if($opt{restart}) { kill_smoke $cfg->{General}{piddir}."/smokeping.pid", SIGINT;};
+
if($opt{logfile}) { initialize_filelog($opt{logfile}) };
+
if (not keys %$probes) {
do_log("No probes defined, exiting.");
exit 1;
@@ -3684,11 +3703,15 @@ KID:
sleep $sleeptime;
last if checkhup($multiprocessmode, $gothup) && reload_cfg($cfgfile);
}
- my $now = time;
+ my $now = time;
run_probes $probes, $myprobe; # $myprobe is undef if running without 'concurrentprobes'
my %sortercache;
- update_rrds $cfg, $probes, $cfg->{Targets}, $cfg->{General}{datadir}, $myprobe, \%sortercache;
- save_sortercache($cfg,\%sortercache,$myprobe);
+ if ($opt{'master-url'}){
+ Smokeping::Slave::get_results $slave_cfg,$cfg,$probes,$cfg->{Targets},"",$myprobe;
+ } else {
+ update_rrds $cfg, $probes, $cfg->{Targets}, $cfg->{General}{datadir}, $myprobe, \%sortercache;
+ save_sortercache($cfg,\%sortercache,$myprobe);
+ }
exit 0 if $opt{debug};
my $runtime = time - $now;
if ($runtime > $step) {
diff --git a/lib/Smokeping/Slave.pm b/lib/Smokeping/Slave.pm
index c5aa3d3..a80eae3 100644
--- a/lib/Smokeping/Slave.pm
+++ b/lib/Smokeping/Slave.pm
@@ -38,6 +38,7 @@ sub get_results {
my $justthisprobe = shift; # if defined, update only the targets probed by this probe
my $probe = $tree->{probe};
my $results = [];
+ return [] unless $cfg;
foreach my $prop (keys %{$tree}) {
if (ref $tree->{$prop} eq 'HASH'){
my $subres = get_results $slave_cfg, $cfg, $probes, $tree->{$prop}, $name."/$prop", $justthisprobe;