X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=bindings%2Fperl%2Flib%2FCollectd%2FUnixsock.pm;h=5e79d2682ecbb723ff094f1d12add49b15b72a76;hb=22651d8d4dc49e24bbac2cd34e0642dcf3639c97;hp=f2e4fb0790c4e453ea325f4f4225637d4ac68600;hpb=04c92d78fd2077b812f1b757a2744b83bdec75d8;p=collectd.git diff --git a/bindings/perl/lib/Collectd/Unixsock.pm b/bindings/perl/lib/Collectd/Unixsock.pm index f2e4fb07..5e79d268 100644 --- a/bindings/perl/lib/Collectd/Unixsock.pm +++ b/bindings/perl/lib/Collectd/Unixsock.pm @@ -262,10 +262,11 @@ sub getthreshold # {{{ $self->_socket_chat($msg, sub { local $_ = shift; my $ret = shift; - /^\s*([^:]+):\s*(.*)/ and do { - $1 =~ s/\s*$//; - $ret->{$1} = $2; - }; + my ( $key, $val ); + ( $key, $val ) = /^\s*([^:]+):\s*(.*)/ and do { + $key =~ s/\s*$//; + $ret->{$key} = $val; + }; }, $ret ); return $ret; @@ -343,6 +344,58 @@ sub putval return; } # putval +=item I<$res> = I<$self>-EB ( C<%identifier> ) + +Queries a list of values from the daemon while restricting the results to +certain hosts, plugins etc. The argument may be anything that passes for an +identifier (cf. L), although all fields are optional. +The returned data is in the same format as from C. + +=cut + +sub listval_filter +{ + my $self = shift; + my %args = @_; + my @ret; + my $nresults; + my $fh = $self->{sock} or confess; + + my $pattern = + (exists $args{host} ? "$args{host}" : '[^/]+') . + (exists $args{plugin} ? "/$args{plugin}" : '/[^/-]+') . + (exists $args{plugin_instance} ? "-$args{plugin_instance}" : '(?:-[^/]+)?') . + (exists $args{type} ? "/$args{type}" : '/[^/-]+') . + (exists $args{type_instance} ? "-$args{type_instance}" : '(?:-[^/]+)?'); + $pattern = qr/^\d+ $pattern$/; + + my $msg = $self->_socket_command('LISTVAL') or return; + ($nresults, $msg) = split / /, $msg, 2; + + # This could use _socket_chat() but doesn't for speed reasons + if ($nresults < 0) + { + $self->{error} = $msg; + return; + } + + for (1 .. $nresults) + { + $msg = <$fh>; + chomp $msg; + _debug "<- $msg\n"; + next unless $msg =~ $pattern; + my ($time, $ident) = split / /, $msg, 2; + + $ident = _parse_identifier ($ident); + $ident->{time} = int $time; + + push (@ret, $ident); + } # for (i = 0 .. $status) + + return @ret; +} # listval + =item I<$res> = I<$self>-EB () Queries a list of values from the daemon. The list is returned as an array of