X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=bindings%2Fperl%2FCollectd%2FUnixsock.pm;h=c13622127cc431a64209df253bdd147769934b04;hb=a94f533;hp=3b6fa5d13d96c58634cac3fe8c8f263d15229b51;hpb=ba758727dfd90eda6ff504e2abe9d9261d38d9e7;p=collectd.git diff --git a/bindings/perl/Collectd/Unixsock.pm b/bindings/perl/Collectd/Unixsock.pm index 3b6fa5d1..c1362212 100644 --- a/bindings/perl/Collectd/Unixsock.pm +++ b/bindings/perl/Collectd/Unixsock.pm @@ -71,9 +71,9 @@ sub _create_socket return ($sock); } # _create_socket -=head1 VALUE IDENTIFIER +=head1 VALUE IDENTIFIERS -The values in the collectd are identified using an five-tupel (host, plugin, +The values in the collectd are identified using an five-tuple (host, plugin, plugin-instance, type, type-instance) where only plugin-instance and type-instance may be NULL (or undefined). Many functions expect an I<%identifier> hash that has at least the members B, B, and @@ -134,6 +134,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 +191,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,7 +199,7 @@ sub getval $identifier = _create_identifier (\%args) or return; - $msg = "GETVAL $identifier\n"; + $msg = 'GETVAL ' . _escape_argument ($identifier) . "\n"; #print "-> $msg"; send ($fh, $msg, 0) or confess ("send: $!"); @@ -217,10 +233,10 @@ sub getval =item I<$obj>-EB (I<%identifier>, B