X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=contrib%2Fcussh.pl;h=ae758d17b14e1600188f57386572a339c6e338f0;hp=c143aea319cd23de7555cc3ea3e1e01ca60d4f14;hb=de407dd4e036f73e9bd4658af9d71f504fc11109;hpb=937fc4f2d1721b29b1ad4321ac623bbc9699fd2f diff --git a/contrib/cussh.pl b/contrib/cussh.pl index c143aea3..ae758d17 100755 --- a/contrib/cussh.pl +++ b/contrib/cussh.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # # collectd - contrib/cussh.pl -# Copyright (C) 2007-2008 Sebastian Harl +# Copyright (C) 2007-2009 Sebastian Harl # # 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 @@ -60,6 +60,7 @@ use Collectd::Unixsock(); HELP => \&cmd_help, PUTVAL => \&putval, GETVAL => \&getval, + GETTHRESHOLD => \&getthreshold, FLUSH => \&flush, LISTVAL => \&listval, PUTNOTIF => \&putnotif, @@ -186,11 +187,19 @@ sub putid { =cut sub cmd_help { - print < < < [ ...] + +Submits a value to the daemon. +HELP + getval => < + +Retrieves the current value or values from the daemon. +HELP + flush => <] [timeout=] [identifier=] [...] + +Sends a FLUSH command to the daemon. +HELP + listval => < < [...] message= + +Sends a notifications message to the daemon. +HELP + ); + + if (!$cmd) + { + $cmd = 'help'; + } + if (!exists ($text{$cmd})) + { + print STDOUT "Unknown command: " . uc ($cmd) . "\n\n"; + $cmd = 'help'; + } + + print STDOUT $text{$cmd}; + return 1; } # cmd_help @@ -281,6 +329,48 @@ sub getval { return 1; } +=item B I + +=cut + +sub getthreshold { + my $sock = shift || return; + my $line = shift || return; + + my @line = tokenize($line); + + my $id; + my $vals; + + if (! @line) { + return; + } + + if (scalar(@line) < 1) { + print STDERR "Synopsis: GETTHRESHOLD " . $/; + return; + } + + $id = getid($line[0]); + + if (! $id) { + print STDERR "Invalid id \"$line[0]\"." . $/; + return; + } + + $vals = $sock->getthreshold(%$id); + + if (! $vals) { + print STDERR "socket error: " . $sock->{'error'} . $/; + return; + } + + foreach my $key (keys %$vals) { + print "\t$key: $vals->{$key}\n"; + } + return 1; +} + =item B [B=I<$timeout>] [B=I<$plugin>[ ...]] =cut @@ -310,7 +400,7 @@ sub flush { $args{"timeout"} = $value; } elsif ($option eq "identifier") { - my $id = getid (\$value); + my $id = getid ($value); if (!$id) { print STDERR "Not a valid identifier: \"$value\"\n";