From: Doug MacEachern Date: Tue, 20 Jan 2009 09:27:10 +0000 (+0100) Subject: contrib/cussh.pl: Add the PUTNOTIF command. X-Git-Tag: collectd-4.6.0~19^2~2^2~3 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4ea2b254df41984c589b695b67e5063901408a0f;p=collectd.git contrib/cussh.pl: Add the PUTNOTIF command. I was using this to test notifications for jcollectd like so: echo "PUTNOTIF host=foo severity=warning message=my perl is rusty" | perl -Mblib=bindings/perl contrib/cussh.pl Signed-off-by: Doug MacEachern Signed-off-by: Florian Forster --- diff --git a/contrib/cussh.pl b/contrib/cussh.pl index f95d54d2..9b578e63 100755 --- a/contrib/cussh.pl +++ b/contrib/cussh.pl @@ -62,6 +62,7 @@ use Collectd::Unixsock(); GETVAL => \&getval, FLUSH => \&flush, LISTVAL => \&listval, + PUTNOTIF => \&putnotif, }; if (! $sock) { @@ -163,6 +164,7 @@ Available commands: GETVAL FLUSH LISTVAL + PUTNOTIF See the embedded Perldoc documentation for details. To do that, run: perldoc $0 @@ -281,6 +283,29 @@ sub listval { return 1; } +=item B [[B=I<$severity>] [B=I<$message>] [ ...]] + +=cut + +sub putnotif { + my $sock = shift || return; + my $line = shift || return; + + my (%values) = (); + foreach my $i (split m/ /, $line) { + my($key,$val) = split m/=/, $i, 2; + if ($key && $val) { + $values{$key} = $val; + } + else { + $values{'message'} .= ' '.$key; + } + } + $values{'time'} ||= time(); + my(@tmp) = %values; + return $sock->putnotif(%values); +} + =back These commands follow the exact same syntax as described in