summaryrefslogtreecommitdiffstats
path: root/lib/Smokeping/probes/skel.pm
blob: ba60a4772ee1c9927cb152328d813090e4a69ff0 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package Smokeping::probes::skel;

=head1 301 Moved Permanently

This is a Smokeping probe module. Please use the command 

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

to view the documentation or the command

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

to generate the POD document.

=cut

use strict;
use base qw(Smokeping::probes::basefork); 
# or, alternatively
# use base qw(Smokeping::probes::base);
use Carp;

sub pod_hash {
	return {
		name => <<DOC,
Smokeping::probes::skel - a skeleton for Smokeping Probes
DOC
		description => <<DOC,
This is a non-functional module that is intended to act as a
basis for creation of new probes. See the L<smokeping_extend>
document for more information.
DOC
		authors => <<'DOC',
 Niko Tyni <ntyni@iki.fi>,
DOC
		see_also => <<DOC
L<smokeping_extend>
DOC
	};
}

sub new($$$)
{
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self = $class->SUPER::new(@_);

    # no need for this if we run as a cgi
    unless ( $ENV{SERVER_SOFTWARE} ) {
    	# if you have to test the program output
	# or something like that, do it here
	# and bail out if necessary
    };

    return $self;
}

# This is where you should declare your probe-specific variables.
# The example shows the common case of checking the availability of
# the specified binary.

sub probevars {
	my $class = shift;
	return $class->_makevars($class->SUPER::probevars, {
		#_mandatory => [ 'binary' ],
		#binary => { 
		#	_doc => "The location of your pingpong binary.",
		#	_example => '/usr/bin/pingpong',
		#	_sub => sub { 
		#		my $val = shift;
        	#		return "ERROR: pingpong 'binary' does not point to an executable"
            	#			unless -f $val and -x _;
		#		return undef;
		#	},
		#},
	});
}

# Here's the place for target-specific variables

sub targetvars {
	my $class = shift;
	return $class->_makevars($class->SUPER::targetvars, {
		#weight => { _doc => "The weight of the pingpong ball in grams",
		#	       _example => 15
		#},
	});
}

sub ProbeDesc($){
    my $self = shift;
    return "pingpong points";
}

# this is where the actual stuff happens
# you can access the probe-specific variables
# via the $self->{properties} hash and the
# target-specific variables via $target->{vars}

# If you based your class on 'Smokeping::probes::base',
# you'd have to provide a "ping" method instead
# of "pingone"

sub pingone ($){
    my $self = shift;
    my $target = shift;

    # my $binary = $self->{properties}{binary};
    # my $weight = $target->{vars}{weight}
    # my $count = $self->pings($target); # the number of pings for this targets

    # ping one target

    # execute a command and parse its output
    # you should return a sorted array of the measured latency times
    # it could go something like this:

    my @times;

    #for (1..$count) {
    #        open(P, "$cmd 2>&1 |") or croak("fork: $!");
    #        while (<P>) {
    #                /time: (\d+\.\d+)/ and push @times, $1;
    #        }
    #        close P;
    #}


    return @times;
}

# That's all, folks!

1;