Next:
spong-status
Previous:
spong-server
 [Table of Contents][Index]

spong-server-mod-template



NAME

spong-server-mod-template - how to build a spong-server data modules

DESCRIPTION

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.

Message Formats

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.

Status Message

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
The field contains the first line of a status message. If consists the cmd, host, color (aka status), time, and summary fields.
message
This is the detailed status message field. It generally consists of multiple lines of text. This field can be quite large. Upwards of a few K is nor unusual.
cmd
This is command field from the header. It will a contain a string with the value of 'status'.
host
This is hostname from the status message header field. It will contain the name of the reporting host. if will contain a strings that will typically be the fully qualified domain name of the host. It is the same of the hostname given in the the spong.conf manpage configuation file.
service
This is the service name from the message header field. It will contain a string. It it the name of the service or resource that was tested. The service names are the column names on the Web Status screens.
color
This is the status color of the test being reported. It will contain a string consisting of one of these values: 'red', 'yellow', 'green', 'purple', 'clear'. The have a meaning of: red=critical, yellow=warning, green=normal, purple=old/stale data, clear=status unknown.
time
This is the timestamp of the status as given by the rporting host. If will consist of system time in epoch format (i.e. as reported by time() ). Epoch date format is the number of seconds since a given epoch. Jan 1, 1970 12:00 AM for UNIX based systems.
duration
The field contains the current duration that the service has been in it's current status (color). The time is given in seconds.
summary
This is summary fields from the status message. It is a short summary of the current status of the services being reported. It will be one line of test. Generally less then 40 characters (not guaranteed).

Acknowledge Message

Acknowledge messages are generate when an acknowledgement is created. This message is fairly rare.

header
The field contains the first line of a status message. If consists the cmd, host, service, start_time, end_time, and user fields.
message
This is an information/note field. It's typically used to give the reason for the acknoloedgement. It generally consists of multiple lines of text. This field can be quite large.
cmd
This is command field from the header. It will a contain a string with the value of 'ack'.
host
This is hostname the acknoledgement that is being created. It will contain a strings that will typically be the fully qualified domain name of the host. It is the same of the hostname given in the the spong.conf manpage configuation file.
service
This field is the service(s) the acknowledgement is being created for. It will contain a string. It wll be a command seperated list of service names or the strings 'all' to represent all services. The service names are the column names on the Web Status screens.
start_time
This is the date/time of the start of the acknowledgement period. It will consist of system time in epoch format (i.e. as reported by time() ). Epoch date format is the number of seconds since a given epoch. Jan 1, 1970 12:00 AM for UNIX based systems.
end_time
This is the date/time of the end of the acknowledgement period. It will consist of system time in epoch format (i.e. as reported by time() ). Epoch date format is the number of seconds since a given epoch. Jan 1, 1970 12:00 AM for UNIX based systems.
user
This field gives and indication of the user who is creating the acknowledgment. This is just an informational field. It will consist of a string that contains an e-mail address (username@hostname). This is not a hard and fast requirement. =back

Delete Acknowledge Message

Delete Acknowledge messages are sent to delete an existing acknowledgement. This message is fairly rare.

header
The field contains the first line of a status message. If consists the cmd, host, service, and end_time fields.
cmd
This is command field from the header. It will a contain a string with the value of 'ack'.
host
This is hostname of the acknoledgement that was created. It will contain a strings that will typically be the fully qualified domain name of the host. It is the same of the hostname given in the the spong.conf manpage configuation file.
service
This field is the service(s) the acknowledgement is being created for. It will contain a string. It wll be a command seperated list of service names or the strings 'all' to represent all services. The service names are the column names on the Web Status screens.
end_time
This is the date/time of the end of the acknowledgement period. It will consist of system time in epoch format (i.e. as reported by time() ). Epoch date format is the number of seconds since a given epoch. Jan 1, 1970 12:00 AM for UNIX based systems.

Special Fields

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 field can be added to the passed messge field hash. If must be added with a none zero (0) value. See the example module below for it usage.

Example Module

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.

SEE ALSO

the developer-guide manpage, the spong-server manpage, the spong.conf manpage

AUTHOR

Stephen L Johnson <sjohnson@monsters.org>

HISTORY

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.


[Top] Generated by Pod::HTML 0.44 on Thu Jun 6 17:59:05 2002