[collectd] register_plugin for a "personalized" read callback

Andreas Schuldei andreas at schuldei.org
Sun May 21 00:45:43 CEST 2017


I am simplifying my perl plugin code (a lot). Of course i still run several
different instances of the code, still, because i monitor several devices.

The somewhat magic code for creating a unique read callback stopped
working. This is the current code, that give me the error
Collectd::Plugins::OneWireCtlr::my_read_192_168_178_117 error: Undefined
subroutine &Collectd::Plugins::OneWireCtlr::HASH called at (eval 16) line 1.


sub my_config {
    #
    # get stuff from the config file
    #
    my ( undef, $config_href ) = recurse_config($_[0]);
    my_die("What host to monitor? i need an IP!")
unless $config_href->{'host'};
    my $host = $config_href->{'host'};

    my ($string) = map tr/a-zA-Z0-9_/_/csr, $host;

    # register "personalized" callback
    eval "sub Collectd::Plugins::OneWireCtlr::my_read_$string
{my_read($config_href);}";
    plugin_register (TYPE_READ, "$plugin_name/$string", "my_read_$string");

    init_controller( $config_href,
[   'set,sys,datatime,0',
   'set,sys,kalsend,0',
   'set,sys,dataprint,0',
   'set,owb,owdid,1',
   'set,sys,kalrec,0',
   'SET,OWB,POLLTIME,10'
] );

    1;
}


This is the old code that used to work:

sub my_config {
    #
    # get stuff from the config file
    #
    my ( undef, $config_href ) = recurse_config($_[0]);
    my_die("What host to monitor? i need an IP!")
unless $config_href->{'host'};
    my $host = $config_href->{'host'};


    my $glue = substr( crypt ( (scalar reverse $host), $host), -4); # get
reproducable 4 bytes

    my ($string) = map tr/a-zA-Z0-9_/_/csr, $host;
#    print "string $string  host $host glue $glue\n";

    my %options = (
create    => 1,
exclusive => 0,
mode      => 0644,
destroy   => 1,
);
    my %values;
    my $handle = tie %values, 'IPC::Shareable', $glue, { %options } or
my_log("shared memory: tie failed");

    #
    # configure the controller
    #

    my @c = ($config_href, \%values);
    # register "personalized" callback
    eval "sub Collectd::Plugins::OneWireCtlr::my_read_$string
{my_read(\@c);}";
    plugin_register (TYPE_READ, "$plugin_name/$string", "my_read_$string");

    unless ($child = fork) {
my_die( "cant fork: $!") unless defined $child;
# this is the part communicating with the controller
communicate(\@c);
# Not reached
exit;
    }
    1;
}



how do i fix this? what is the actual problem?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20170520/46ad0e86/attachment.html>


More information about the collectd mailing list