Next: spong-status | Previous: spong-server | [Table of Contents] | [Index] |
spong-server-mod-template - how to build a spong-server data modules
The old data spong-server plugin modules are now deprecited in favor of predata and postdata modules. Spong Server data modules will continue to be supported for the future. But you are encouraged to convert any custom modules to the new format, and update any old data plugin to their new pre- or post-data equivalent.
The file name of the module must begin with 'predata_' or 'postdata_'. 'predata_' is for a predata module. The module will be called immediately after an incoming message is received, but before normal processing. 'postdata_' is for a postdata module. The module is called after the normal processing is done for the message.
Modules are called in the order of their registry key in alphabetical order. The registry key can be anything, but it should be consistent with the module's name. And the registry must be unique among the other loaded modules; otherwise, one module will overlay the other.
The line that has the assignment to $DATAFUNCS{'registry-name'}
is the
key to the registry mechanism. It's what ties the registry name to the
your data module.
The fields of messages are passed to the module in the form of a Perl hash. This hash is the only parameter passed to the module when it is called.
This is the most common type of message received by the Spong Server. A status message reports the current status of Spong Client and Spong Network checks and tests.
header
cmd
,
host
, color
(aka status), time
, and summary
fields.
message
cmd
header
. It will a contain a string with the
value of 'status'.
host
service
color
time
duration
color
). The time is given in seconds.
summary
Acknowledge messages are generate when an acknowledgement is created. This message is fairly rare.
header
cmd
,
host
, service
, start_time
, end_time
, and user
fields.
message
cmd
header
. It will a contain a string with the
value of 'ack'.
host
service
start_time
end_time
user
Delete Acknowledge messages are sent to delete an existing acknowledgement. This message is fairly rare.
header
cmd
,
host
, service
, and end_time
fields.
cmd
header
. It will a contain a string with the
value of 'ack'.
host
service
end_time
Predata modules add a special field/flag to the message hash before returning. The presence of this flag field will tell Spong Server to drop the message. The messge will be dropped and forgotten. Normal processing will not be done, and postdata modules will not be called.
drop_msg
This template will be a simple example that will redirect disk status updates to an alternate Spong Server for processing. We only want the Database Server hosts dbserv*.example.com. And we will tell the Spong Server to drop the message to let the alternate Spong Server to handle it.
predata_redirect: # Register the routine with the plugin registry $DATAFUNCS{'redirect'} = \&predata_redirect; use Spong::Status; # We'll being this module to send the message $ALTSERVER = 'spong-disk.example.com:19980'; sub predata_redirect { my( $msg ) = @_;
# Return is not status message for disk for dbserv* return if ( $msg->{'cmd'} ne 'status' || $msg->{'service'} ne 'disk' || $msg->{'host'} !~ m/dbserv.*\.example\.com/ );
# Send the message to the alternate Spong Disk server Spong::Status($ALTSERV, 1998, $msg->{'header'} . "\n" $msg->{'message'} );
# And tell the server to drop the message and don't process it $msg->{'drop_msg'} = 1; return; } # I'm included perl code, I need this line. 1;
-----
Please note the final line. It is always required for a module file.
You should use the &main::error()
function to log any error encountered
in your module. The &main::error()
function is used to write output
whenever something interesting happens in your module.
Any configuration variables needed for your data modules can be put into the
Global section of your module as shown above. Of it can be added into the
spong.conf
or spong.conf.<host>
configuration files.
Configuration variables for your module should be named to match them up
with the name of your customized check.
the developer-guide manpage, the spong-server manpage, the spong.conf manpage
Stephen L Johnson <sjohnson@monsters.org
>
Based on code/ideas from Sean MacGuire (BB), and Helen Harrison (Pong). Ed Hill original converted Big Brother (http://www.bb4.com) into Perl which diverged from Big Brother to become Spong. Ed Hill continued Spong development until version 2.1. Stephen L Johnson took over development in October, 1999 with his changes which became Spong 2.5.