From 4ea2b254df41984c589b695b67e5063901408a0f Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 20 Jan 2009 10:27:10 +0100 Subject: [PATCH] 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 --- contrib/cussh.pl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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 -- 2.11.0