X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=bindings%2Fperl%2FCollectd%2FUnixsock.pm;h=eb6e389e34b823d1df792f61f854c3ae183688eb;hb=ac51a394f0e90205fa140769bdeae83fba6b8388;hp=f21ebfe9f285dc83060ba114c94f70996f4a3980;hpb=81aaa5aa1ff8d0af76fd809db25277f157d56c73;p=collectd.git diff --git a/bindings/perl/Collectd/Unixsock.pm b/bindings/perl/Collectd/Unixsock.pm index f21ebfe9..eb6e389e 100644 --- a/bindings/perl/Collectd/Unixsock.pm +++ b/bindings/perl/Collectd/Unixsock.pm @@ -57,8 +57,19 @@ use Carp (qw(cluck confess)); use IO::Socket::UNIX; use Regexp::Common (qw(number)); +our $Debug = 0; + return (1); +sub _debug +{ + if (!$Debug) + { + return; + } + print @_; +} + sub _create_socket { my $path = shift; @@ -71,7 +82,7 @@ sub _create_socket return ($sock); } # _create_socket -=head1 VALUE IDENTIFIER +=head1 VALUE IDENTIFIERS The values in the collectd are identified using an five-tuple (host, plugin, plugin-instance, type, type-instance) where only plugin-instance and @@ -134,6 +145,22 @@ sub _parse_identifier return ($ident); } # _parse_identifier +sub _escape_argument +{ + my $string = shift; + + if ($string =~ m/^\w+$/) + { + return ("$string"); + } + + $string =~ s#\\#\\\\#g; + $string =~ s#"#\\"#g; + $string = "\"$string\""; + + return ($string); +} + =head1 PUBLIC METHODS =over 4 @@ -175,7 +202,7 @@ sub getval my %args = @_; my $status; - my $fh = $obj->{'sock'} or confess; + my $fh = $obj->{'sock'} or confess ('object has no filehandle'); my $msg; my $identifier; @@ -183,13 +210,13 @@ sub getval $identifier = _create_identifier (\%args) or return; - $msg = "GETVAL $identifier\n"; - #print "-> $msg"; - send ($fh, $msg, 0) or confess ("send: $!"); + $msg = 'GETVAL ' . _escape_argument ($identifier) . "\n"; + _debug "-> $msg"; + print $fh $msg; - $msg = undef; - recv ($fh, $msg, 1024, 0) or confess ("recv: $!"); - #print "<- $msg"; + $msg = <$fh>; + chomp ($msg); + _debug "<- $msg\n"; ($status, $msg) = split (' ', $msg, 2); if ($status <= 0) @@ -198,9 +225,12 @@ sub getval return; } - for (split (' ', $msg)) + for (my $i = 0; $i < $status; $i++) { - my $entry = $_; + my $entry = <$fh>; + chomp ($entry); + _debug "<- $entry\n"; + if ($entry =~ m/^(\w+)=NaN$/) { $ret->{$1} = undef; @@ -219,8 +249,8 @@ sub getval Submits a value-list to the daemon. If the B