From 170e81a5bbb801a148245bd55f9fc59f7b30c63f Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 6 Sep 2009 10:57:41 +0200 Subject: [PATCH] =?utf8?q?Collectd::Unixsock:=20Add=20support=20for=20the?= =?utf8?q?=20=E2=80=9CGETTHRESHOLD=E2=80=9D=20command.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- bindings/perl/Collectd/Unixsock.pm | 63 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/bindings/perl/Collectd/Unixsock.pm b/bindings/perl/Collectd/Unixsock.pm index 44031784..199a47c5 100644 --- a/bindings/perl/Collectd/Unixsock.pm +++ b/bindings/perl/Collectd/Unixsock.pm @@ -196,7 +196,7 @@ value. On error false is returned. =cut -sub getval +sub getval # {{{ { my $obj = shift; my %args = @_; @@ -242,7 +242,64 @@ sub getval } return ($ret); -} # getval +} # }}} sub getval + +=item I<$res> = I<$obj>-EB (I<%identifier>); + +Requests a threshold from the daemon. On success a hash-ref is returned with +the threshold data. On error false is returned. + +=cut + +sub getthreshold # {{{ +{ + my $obj = shift; + my %args = @_; + + my $status; + my $fh = $obj->{'sock'} or confess ('object has no filehandle'); + my $msg; + my $identifier; + + my $ret = {}; + + $identifier = _create_identifier (\%args) or return; + + $msg = 'GETTHRESHOLD ' . _escape_argument ($identifier) . "\n"; + _debug "-> $msg"; + print $fh $msg; + + $msg = <$fh>; + chomp ($msg); + _debug "<- $msg\n"; + + ($status, $msg) = split (' ', $msg, 2); + if ($status <= 0) + { + $obj->{'error'} = $msg; + return; + } + + for (my $i = 0; $i < $status; $i++) + { + my $entry = <$fh>; + chomp ($entry); + _debug "<- $entry\n"; + + if ($entry =~ m/^([^:]+):\s*(\S.*)$/) + { + my $key = $1; + my $value = $2; + + $key =~ s/^\s+//; + $key =~ s/\s+$//; + + $ret->{$key} = $value; + } + } + + return ($ret); +} # }}} sub getthreshold =item I<$obj>-EB (I<%identifier>, B