From: Sebastian Harl Date: Tue, 25 Mar 2008 14:59:40 +0000 (+0100) Subject: contrib/cussh.pl: Added support for LISTVAL. X-Git-Tag: collectd-4.4.0~70 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=738e046e5ed131f0ba84cf0c87a2f0818da8bb44;p=collectd.git contrib/cussh.pl: Added support for LISTVAL. Also fixed the following minor problems: * the arguments passed to Collectd::Unixsock::putval() have been updated to the current version of the Perl module * remove newlines from the end of the input line - the unixsock plugin currently seems to be buggy when receiving two newlines in a row Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- diff --git a/contrib/cussh.pl b/contrib/cussh.pl index c19c3f30..df3df344 100755 --- a/contrib/cussh.pl +++ b/contrib/cussh.pl @@ -57,9 +57,10 @@ use Collectd::Unixsock(); my $sock = Collectd::Unixsock->new($path); my $cmds = { - PUTVAL => \&putval, - GETVAL => \&getval, - FLUSH => \&flush, + PUTVAL => \&putval, + GETVAL => \&getval, + FLUSH => \&flush, + LISTVAL => \&listval, }; if (! $sock) { @@ -67,7 +68,7 @@ use Collectd::Unixsock(); exit 1; } - print "cussh version 0.2, Copyright (C) 2007 Sebastian Harl\n" + print "cussh version 0.2, Copyright (C) 2007-2008 Sebastian Harl\n" . "cussh comes with ABSOLUTELY NO WARRANTY. This is free software,\n" . "and you are welcome to redistribute it under certain conditions.\n" . "See the GNU General Public License 2 for more details.\n\n"; @@ -76,7 +77,11 @@ use Collectd::Unixsock(); print "cussh> "; my $line = ; - last if ((! $line) || ($line =~ m/^quit$/i)); + last if (! $line); + + chomp $line; + + last if ($line =~ m/^quit$/i); my ($cmd) = $line =~ m/^(\w+)\s+/; $line = $'; @@ -122,17 +127,31 @@ sub getid { return \%id; } +sub putid { + my $ident = shift || return; + + my $string; + + $string = $ident->{'host'} . "/" . $ident->{'plugin'}; + + if (defined $ident->{'plugin_instance'}) { + $string .= "-" . $ident->{'plugin_instance'}; + } + + $string .= "/" . $ident->{'type'}; + + if (defined $ident->{'type_instance'}) { + $string .= "-" . $ident->{'type_instance'}; + } + return $string; +} + =head1 COMMANDS =over 4 =item B I -=item B I I - -These commands follow the exact same syntax as described in -L. - =cut sub putval { @@ -147,9 +166,13 @@ sub putval { } my ($time, @values) = split m/:/, $line; - return $sock->putval(%$id, $time, \@values); + return $sock->putval(%$id, time => $time, values => \@values); } +=item B I I + +=cut + sub getval { my $sock = shift || return; my $line = shift || return; @@ -163,7 +186,10 @@ sub getval { my $vals = $sock->getval(%$id); - return if (! $vals); + if (! $vals) { + print STDERR $sock->{'error'} . $/; + return; + } foreach my $key (keys %$vals) { print "\t$key: $vals->{$key}\n"; @@ -171,6 +197,10 @@ sub getval { return 1; } +=item B [B=I<$timeout>] [B=I<$plugin>[ ...]] + +=cut + sub flush { my $sock = shift || return; my $line = shift; @@ -209,6 +239,33 @@ sub flush { return 1; } +=item B + +=cut + +sub listval { + my $sock = shift || return; + + my @res; + + @res = $sock->listval(); + + if (! @res) { + print STDERR $sock->{'error'} . $/; + return; + } + + foreach my $ident (@res) { + print $ident->{'time'} . " " . putid($ident) . $/; + } + return 1; +} + +=back + +These commands follow the exact same syntax as described in +L. + =head1 SEE ALSO L, L