summaryrefslogtreecommitdiffstats
path: root/lib/Smokeping/probes/EchoPingPlugin.pm
blob: 0762f4576cad263c7ffad68c5af1c5dc32c299b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package Smokeping::probes::EchoPingPlugin;

=head1 301 Moved Permanently

This is a Smokeping probe module. Please use the command 

C<smokeping -man Smokeping::probes::EchoPingPlugin>

to view the documentation or the command

C<smokeping -makepod Smokeping::probes::EchoPingPlugin>

to generate the POD document.

=cut

sub pod_hash {
	return {
		name => <<DOC,
Smokeping::probes::EchoPingPlugin - a basis for using echoping(1) plugins as probes for SmokePing
DOC
		overview => <<DOC,
Measures roundtrip times for SmokePing with an echoping(1) plugin. The plugins
currently shipped with echoping are implemented as separate probes based
on this class, but the class can also be used directly.
DOC
		authors => <<'DOC',
Niko Tyni <ntyni@iki.fi>
DOC
        notes => <<'DOC',
The I<fill>, I<size> and I<udp> EchoPing variables are not valid by default for EchoPingPlugin -derived probes.

Plugins are available starting with echoping version 6.
DOC
		see_also => <<DOC,
L<Smokeping::probes::EchoPing>,
L<Smokeping::probes::EchoPingLDAP>,
L<Smokeping::probes::EchoPingDNS>,
L<Smokeping::probes::EchoPingWhois>
DOC
	}
}

use strict;
use base qw(Smokeping::probes::EchoPing);
use Carp;

sub _init {
    my $self = shift;
    # plugins don't generally fit with filling, size or udp.
    my $arghashref = $self->features;
    delete $arghashref->{size};
    delete $arghashref->{fill};
    delete $arghashref->{udp};
}

sub post_args {
    my $self = shift;
    my $target = shift;
    return $self->plugin_args($target);
}

# derived classes should override this
sub plugin_args {
    my $self = shift;
    my $target = shift;
    return ();
}

sub proto_args {
	my $self = shift;
	my $target = shift;
	my $plugin = $target->{vars}{plugin};
	return ("-m", $plugin);
}

sub test_usage {
	my $self = shift;
	my $bin = $self->{properties}{binary};
    # is there anything smarter to do?
	croak("Your echoping binary doesn't support plugins. At least version 6 is required.")
		if `$bin -m improbable_plugin_name 0.0.0.1 2>&1` =~ /invalid option/i;
	$self->SUPER::test_usage;
	return;
}

sub ProbeDesc($) {
	return "Pings using an echoping(1) plugin";
}

sub targetvars {
	my $class = shift;
	my $h = $class->SUPER::targetvars;
	delete $h->{udp};
	delete $h->{fill};
	delete $h->{size};
    return $class->_makevars($h, {
        _mandatory => [ 'plugin' ],
        plugin => {
            _doc => <<DOC,
The echoping plugin that will be used. See echoping(1) for details.
This can either be the name of the plugin or a full path to the
plugin shared object.
DOC
            _example => "random",
        },
        pluginargs => {
            _doc => <<DOC,
Any extra arguments needed by the echoping plugin specified with the 
I<pluginname> variable. These are generally provided by the subclass probe.
DOC
            _example => "-p plugin_specific_arg",
        },
    },
    );
}

1;