Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > d97b4c58d8763adc61a7b020afdfd868 > files > 199

smokeping-2.4.2-9mdv2010.0.noarch.rpm

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>smokeping_extend</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>

<body style="background-color: white">

<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<!--

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#overview">OVERVIEW</a></li>
	<li><a href="#choosing_a_base_class">CHOOSING A BASE CLASS</a></li>
	<li><a href="#skeleton_file">SKELETON FILE</a></li>
	<li><a href="#probe_documentation">PROBE DOCUMENTATION</a></li>
	<li><a href="#probe_description">PROBE DESCRIPTION</a></li>
	<li><a href="#variables">VARIABLES</a></li>
	<li><a href="#initialization">INITIALIZATION</a></li>
	<li><a href="#pinging">PINGING</a></li>
	<li><a href="#example_configurations">EXAMPLE CONFIGURATIONS</a></li>
	<li><a href="#timeout_handling">TIMEOUT HANDLING</a></li>
	<li><a href="#copyright">COPYRIGHT</a></li>
	<li><a href="#license">LICENSE</a></li>
	<li><a href="#author">AUTHOR</a></li>
	<li><a href="#bugs">BUGS</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
</ul>
-->
<!-- INDEX END -->

<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>smokeping_extend - Notes on extending Smokeping</p>
<p>
</p>
<hr />
<h1><a name="overview">OVERVIEW</a></h1>
<p>This document is intended to guide prospective authors in writing new
Smokeping probes.  It mostly describes the interface between Smokeping
and its probe modules. If it seems too complicated to understand, look
at the existing modules for examples.</p>
<p>Comments and proposed changes or additions are welcome.  Please send
them to the smokeping-users mailing list. Patches against the POD
source of this document are most appreciated.</p>
<p>
</p>
<hr />
<h1><a name="choosing_a_base_class">CHOOSING A BASE CLASS</a></h1>
<p>The first thing you should decide is which base class you should
use for your probe. For most (if not all) uses it's a choice between
<a href="././Smokeping/probes/base.html">Smokeping::probes::base</a> and <a href="././Smokeping/probes/basefork.html">Smokeping::probes::basefork</a>. The former is intended for probes
that can measure their targets all in one go, while the latter is for
probing them one at a time, possibly in several concurrent subprocesses.</p>
<p>At the moment, the only probes that use <code>Smokeping::probes::base</code> are the FPing
derivatives. All the others use <code>Smokeping::probes::basefork</code>, and chances are
you should too. This document will thus concentrate on the latter case.</p>
<p>
</p>
<hr />
<h1><a name="skeleton_file">SKELETON FILE</a></h1>
<p>The <a href="././Smokeping/probes/skel.html">Smokeping::probes::skel</a> module is a non-functional probe that is intended
to make a good basis for a new probe module. Copy the file, 
<code>lib/probes/skel.pm</code>, to a new name and just fill out the blanks :)
Note that the names of real probe modules must start with a capital letter.</p>
<p>
</p>
<hr />
<h1><a name="probe_documentation">PROBE DOCUMENTATION</a></h1>
<p>The probe documentation is generated from the source code with the
<a href="././smokeping.html">smokeping</a> arguments <code>--man</code> or <code>--makepod</code>. The embedded
POD documentation should point to this real documentation, so
that curious users of the <code>perldoc</code> command see what's going on.
All the current probes do this.</p>
<p>You should provide the method <code>pod_hash</code> that returns a reference to
a hash with keys corresponding to the section names you want in the
manpage. The supported section names are
<code>name</code>, <code>overview</code>, <code>description</code>, <code>authors</code>, <code>notes</code>, <code>bugs</code>, and
<code>see_also</code>. If you don't need a particular section, just leave it out.</p>
<p>The special sections <code>synopsis</code> and <code>variables</code> are automatically
generated from the description of your variables. See below.</p>
<p>Note that if you use 'here documents' ('&lt;&lt;') that have POD markup inside,
you should escape the markup so that it doesn't show up in the embedded
POD documentation. Most probes do it like this:</p>
<pre>
 my $e = &quot;=&quot;;
 my $doc = &lt;&lt;DOC;
 ${e}head1 SECTION TITLE
 DOC</pre>
<p>
</p>
<hr />
<h1><a name="probe_description">PROBE DESCRIPTION</a></h1>
<p>The probe should offer the <code>ProbeDesc</code> method that returns a short
description of what it does. This will be used in the graphs produced
by the web frontend.</p>
<p>
</p>
<hr />
<h1><a name="variables">VARIABLES</a></h1>
<p>All Smokeping probes must define their variables by implementing a
<code>probevars</code> method for probe-specific variables and a <code>targetvars</code>
method for target-specific variables. If you don't know the difference
between these yet, see <a href="././smokeping_examples.html">the smokeping_examples manpage</a>.</p>
<p>(The probes that are derived from <code>Smokeping::probes::base</code> don't support
target-specific variables, so they only use the <code>probevars</code> method.)</p>
<p>The base classes offer these methods too to provide the variables that
are common to all the probes (eg. the probe-specific <code>step</code> variable
and the target-specific <code>pings</code> variable. If you don't want to add
anything to the base class variables (perhaps because all your variables
are of a target-specific nature, so you don't need new probe-specific
variables at all), you can leave the corresponding method out and it
will be inherited from the base class.</p>
<p>When you do supply your own <code>probevars</code> or <code>targetvars</code> method, you should
combine your variables with those coming from the superclass. There is a
convenience method called <code>_makevars</code> that does this, and the common idiom is</p>
<pre>
 sub probevars {
        my $class = shift;
        return $class-&gt;_makevars($class-&gt;SUPER::probevars, {
                # your variables go here
        }
 }</pre>
<p>The variables are declared in a syntax that comes from the module used
for parsing the configuration file, <code>Config::Grammar</code>. Each variable
should be a hash that uses the ``special variable keys'' documented in
<a href="./Config/Grammar.html">the Config::Grammar manpage</a>. See <code>Smokeping::probes::skel</code> and the other
probes for examples.</p>
<p>For reference, here are the keys the hash should have. Much of this
is taken straight from the <code>Config::Grammar</code> manual.</p>
<dl>
<dt><strong><a name="item_keys_you_must_provide">Keys you <strong>must</strong> provide</a></strong>

</dt><dd><dl>
<dt><strong><a name="item__doc">_doc</a></strong>

</dt><dd>
<p>Description of the variable.</p>

</dd><dt><strong><a name="item__example">_example</a></strong>

</dt><dd>
<p>An example value. This will be used in the SYNOPSIS section in the
probe manual.</p>

</dd></dl>

</dd><dt><strong><a name="item_optional_keys">Optional keys</a></strong>

</dt><dd><dl>
<dt><strong><a name="item__default">_default</a></strong>

</dt><dd>
<p>A default value that will be assigned to the variable if none is specified or inherited.</p>

</dd><dt><strong><a name="item__re">_re</a></strong>

</dt><dd>
<p>Regular expression upon which the value will be checked.</p>

</dd><dt><strong><a name="item__re_error">_re_error</a></strong>

</dt><dd>
<p>String containing the returned error in case the regular expression
doesn't match (if not specified, a generic 'syntax error' message will
be returned).</p>

</dd><dt><strong><a name="item__sub">_sub</a></strong>

</dt><dd>
<p>A function pointer. It is called for every value, with the value passed
as its first argument. If the function returns a defined value it is
assumed that the test was not successful and an error is generated with
the returned string as content.</p>

</dd></dl>

</dd></dl>
<p>The <code>probevars</code> and <code>targetvars</code> methods should return hash references
that contain the variable names as keys and the hashes described above
as values. In addition the <code>Config::Grammar</code> special section key
<code>_mandatory</code> is supported and should contain a reference to a list of
mandatory variables. The <code>_makevars</code> method is aware of this special
key and merges the mandatory lists in its arguments. Note that no other
<code>Config::Grammar</code> special section keys are supported.</p>
<p>
</p>
<hr />
<h1><a name="initialization">INITIALIZATION</a></h1>
<p>If you must do something at probe initialization time, like check that
the external program you're going to use behaves as you expect, you should
do it in the <code>new</code> method. You should probably also take care that
you don't run the tests needlessly while in CGI mode. The usual way to 
do this is to test for $ENV{SERVER_SOFTWARE}. See the <code>Smokeping::probes::skel</code>
module for an example.</p>
<p>
</p>
<hr />
<h1><a name="pinging">PINGING</a></h1>
<p>All the real action happens in the <code>pingone</code> method (or, for
<code>Smokeping::probes::base</code>-derived probes, in the <code>ping</code> method.) The arguments
for <code>pingone</code> are <code>$self</code>, the module instance (since this is a method)
and <code>$target</code>, the target to be probed.</p>
<p>You can access the probe-specific variables here via the
<code>$self-&gt;{properties}</code> hash and the target-specific ones via the
<code>$target-&gt;{vars}</code> hash. You get the number of pings needed for
the target via the <code>pings</code> method: <code>my $count = $self-&gt;pings($target)</code>.</p>
<p>You should return a sorted array of the latency times measured. If a ping
fails, don't put anything in the array.</p>
<p>That's it, you're done!</p>
<p>
</p>
<hr />
<h1><a name="example_configurations">EXAMPLE CONFIGURATIONS</a></h1>
<p>If you would like to provide a documented example configuration for your
probe (in addition to the automatically generated SYNOPSIS section in
the probe manual), you can do so by adding it to the <a href="./Smokeping/Examples.html">Smokeping::Examples</a>
module.  Look for the 'examples' subroutine and add your example there.</p>
<p>Future versions of Smokeping might provide a way to embed examples in
the probe modules too. The author's motivation for implementing this
would be greatly increased by even a single demand for it, so please
speak up if you think you'd use it.</p>
<p>
</p>
<hr />
<h1><a name="timeout_handling">TIMEOUT HANDLING</a></h1>
<p>If you deal with timeouts (for example because your program offers a parameter
for specifying the timeout for the pings), you should know a few things.</p>
<p>First, there's timeout logic in <code>Smokeping::probes::basefork</code> that kills the probe
when the timeout is reached. By default the timeout is (# of pings *
5 seconds) + 1 second. If you expect that your pings can take longer,
you should modify the default value of the probe-specific variable <code>timeout</code>.
This would be done like this:</p>
<pre>
 sub probevars {
        my $class = shift;
        my $h = $class-&gt;SUPER::probevars;
        $h-&gt;{timeout}{_default} = 10; # override the superclass default
        return $class-&gt;_makevars($h, {
                # your variables go here
        }
 }</pre>
<p>If you want to provide a target-specific <code>timeout</code> setting, you should
delete the probe-specific variable and be sure to provide a default for
your target-specific one. See eg. <code>Smokeping::probes::AnotherDNS</code> for an example of
how this is done.</p>
<p>Providing a target-specific <code>timeout</code> will make the timeout in
<code>Smokeping::probes::basefork</code> be (# of pings * the maximum timeout of all targets)
+ 1 second. The 1 second is added so that the own timeout logic of the
probe has time to kick in even in the worst case (ie. all pings are lost)
before <code>Smokeping::probes::basefork</code> starts killing the processes.</p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright 2005 by Niko Tyni.</p>
<p>
</p>
<hr />
<h1><a name="license">LICENSE</a></h1>
<p>This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.</p>
<p>This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the GNU General Public License for more
details.</p>
<p>You should have received a copy of the GNU General Public
License along with this program; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
02139, USA.</p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Niko Tyni &lt;<a href="mailto:ntyni@iki.fi">ntyni@iki.fi</a>&gt;</p>
<p>
</p>
<hr />
<h1><a name="bugs">BUGS</a></h1>
<p>This document makes writing new probes look much harder than it really is.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p>The other Smokeping documents, especially <a href="././smokeping_config.html">the smokeping_config manpage</a>.</p>

</body>

</html>