X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=bindings%2Fperl%2FCollectd%2FUnixsock.pm;h=c13622127cc431a64209df253bdd147769934b04;hb=a94f533;hp=3b8a91cfc3e206d745d49d7ab71e0afe9e5dbf99;hpb=cb72a2216def7a5935e28644684df73e68a83425;p=collectd.git diff --git a/bindings/perl/Collectd/Unixsock.pm b/bindings/perl/Collectd/Unixsock.pm index 3b8a91cf..c1362212 100644 --- a/bindings/perl/Collectd/Unixsock.pm +++ b/bindings/perl/Collectd/Unixsock.pm @@ -1,8 +1,30 @@ +# +# collectd - Collectd::Unixsock +# Copyright (C) 2007,2008 Florian octo Forster +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; only version 2 of the License is applicable. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# Author: +# Florian octo Forster +# + package Collectd::Unixsock; =head1 NAME -Collectd::Unixsock - Abstraction layer for accessing the functionality by collectd's unixsock plugin. +Collectd::Unixsock - Abstraction layer for accessing the functionality by +collectd's unixsock plugin. =head1 SYNOPSIS @@ -29,6 +51,8 @@ programmers to interact with the daemon. use strict; use warnings; +#use constant { NOTIF_FAILURE => 1, NOTIF_WARNING => 2, NOTIF_OKAY => 4 }; + use Carp (qw(cluck confess)); use IO::Socket::UNIX; use Regexp::Common (qw(number)); @@ -47,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 @@ -110,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 @@ -151,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; @@ -159,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: $!"); @@ -190,13 +230,13 @@ sub getval return ($ret); } # getval -=item I<$obj>-EB (I<%identifier>, B