jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [Documentation/] [module-howto/] [howto-default.pm] - Rev 3 Go to most recent revision

Compare with Previous - Blame - Download


The "default.pm" file in the "platform" directory does the data-acquisition and storage.
It is there as a fallback in case a OS-dependent library could not be found.

This library must match the following skeleton:

---------- BEGIN CODE ----------
package HotSaNICmod::OSdep;

sub version { return "version string"; }

sub sample {
  my %args=@_;

  # for each datasource do this:
  #  - query datasource(s)
  #  - update database(s)
  
  }

1;
---------- END CODE ----------




---------- The "version" funciton ----------

This function just has to return some identifier string including the library name. If the file is going to be checked into some CVS repository, it is wise to use the CVS keyword "Revision" to automatically include the version number in the version string:


Example:
  sub version {
    ($VERSION = '$Revision: 1.1 $') =~ s/.*(\d+\.\d+).*/$1/;
    return "default.pm $VERSION";
    }   

  This will return the string "default.pm 1.1".



---------- The "sample" funciton ----------

This function will be called regularly by the rrdtimer script using a "USR1" signal that is sent to the running module.
The function has to parse all datasources and store all results in the corrosponding databases.

The hash %args contains the module's confguration hash including some global configuration items as well.
Global items that are put into the hash are:

  DEBUGLEVEL   the maximum of the debuglevels configured in the module's and the global settings.
  MODNAME      name of the module in upprecase
  SNMPGET      path to "snmpget" (as far as configured)
  SNMPWALK     path to "snmpwalk" (as far as configured)
  VARDIR       path to the "var" directory for this module (i.e. globally configured vardir plus "/modules/<module name>")

All other items from the module's "settings" file will be added as defined in the module's "commpn.pm" library.



As an example, let's assume the following situation:

settings contain some lines of the format:
TARGET="<script_to_call>"
TARGET="<another_one>"
TARGET="<yet_another_one>"


the common.pm should contain an initialization of the "TARGET" items as array type


The "default.pm" code may for example look like this:


---------- BEGIN CODE ----------
package HotSaNICmod::OSdep;

sub version {
  ($VERSION = '$Revision: 1.1 $') =~ s/.*(\d+\.\d+).*/$1/;
  return "default.pm $VERSION";
  }   

sub sample {
  %args=@_;

  foreach $script (@{$args{TARGET}}) {
    $result=system "$script";
    HotSaNICmod::do_rrd($script,"U",time,$result);
    }

  return %MODARGS
  }

1;

---------- END CODE ----------


This will cause the "TARGET" array to be traversed. All array entries will be taken as scripts that have to be called, and the result of these scripts are assumed to be single values that can be fed directly into a .rrd database using the "do_rrd" function from the "HotSaNICmod.pm" library.

The parameters for "do_rrd" are:

    HotSaNICmod::do_rrd(<RRD name>,<max. expected value>,<time>,<array of results>);

    this will update the given database with the contents of the corrosponding array.
    If the DB doesn't exist, it will be created using the given maximum.



Powered by WebSVN 2.2.1