Merge branch 'collectd-4.3' into collectd-4.4
[collectd.git] / contrib / cussh.pl
index 6da2856..f95d54d 100755 (executable)
@@ -57,6 +57,7 @@ use Collectd::Unixsock();
        my $sock = Collectd::Unixsock->new($path);
 
        my $cmds = {
+               HELP    => \&cmd_help,
                PUTVAL  => \&putval,
                GETVAL  => \&getval,
                FLUSH   => \&flush,
@@ -113,7 +114,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 +123,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 +151,25 @@ sub putid {
 
 =over 4
 
+=item B<HELP>
+
+=cut
+
+sub cmd_help {
+       print <<HELP;
+Available commands:
+  HELP
+  PUTVAL
+  GETVAL
+  FLUSH
+  LISTVAL
+
+See the embedded Perldoc documentation for details. To do that, run:
+  perldoc $0
+HELP
+       return 1;
+} # cmd_help
+
 =item B<GETVAL> I<Identifier>
 
 =cut