X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=contrib%2Fcussh.pl;h=ee4c89396b98d0ecaa9ae2e1769b26876a4cc787;hb=d3fc6d0831a63af2e96300f488a9f8f5fc3183fb;hp=6da2856d0d8b307387788da48aff2da58cf6353d;hpb=d22aee658210cbfa44caa39f302aa9331d4eab82;p=collectd.git diff --git a/contrib/cussh.pl b/contrib/cussh.pl index 6da2856d..ee4c8939 100755 --- a/contrib/cussh.pl +++ b/contrib/cussh.pl @@ -57,10 +57,12 @@ use Collectd::Unixsock(); my $sock = Collectd::Unixsock->new($path); my $cmds = { + HELP => \&cmd_help, PUTVAL => \&putval, GETVAL => \&getval, FLUSH => \&flush, LISTVAL => \&listval, + PUTNOTIF => \&putnotif, }; if (! $sock) { @@ -113,7 +115,7 @@ sub getid { print $$string . $/; my ($h, $p, $pi, $t, $ti) = - $$string =~ m/^(\w+)\/(\w+)(?:-(\w+))?\/(\w+)(?:-(\w+))?\s*/; + $$string =~ m#^([^/]+)/([^/-]+)(?:-([^/]+))?/([^/-]+)(?:-([^/]+))?\s*#; $$string = $'; return if ((! $h) || (! $p) || (! $t)); @@ -122,8 +124,8 @@ sub getid { ($id{'host'}, $id{'plugin'}, $id{'type'}) = ($h, $p, $t); - $id{'plugin_instance'} = $pi if ($pi); - $id{'type_instance'} = $ti if ($ti); + $id{'plugin_instance'} = $pi if defined ($pi); + $id{'type_instance'} = $ti if defined ($ti); return \%id; } @@ -150,6 +152,26 @@ sub putid { =over 4 +=item B + +=cut + +sub cmd_help { + print < I =cut @@ -223,6 +245,15 @@ sub flush { elsif ($option eq "timeout") { $args{"timeout"} = $value; } + elsif ($option eq "identifier") { + my $id = getid (\$value); + if (!$id) + { + print STDERR "Not a valid identifier: \"$value\"\n"; + next; + } + push @{$args{"identifier"}}, $id; + } else { print STDERR "Invalid option \"$option\".\n"; return; @@ -261,6 +292,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