my $sock = Collectd::Unixsock->new($path);
my $cmds = {
+ HELP => \&cmd_help,
PUTVAL => \&putval,
GETVAL => \&getval,
FLUSH => \&flush,
LISTVAL => \&listval,
+ PUTNOTIF => \&putnotif,
};
if (! $sock) {
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));
($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;
}
=over 4
+=item B<HELP>
+
+=cut
+
+sub cmd_help {
+ print <<HELP;
+Available commands:
+ HELP
+ PUTVAL
+ GETVAL
+ FLUSH
+ LISTVAL
+ PUTNOTIF
+
+See the embedded Perldoc documentation for details. To do that, run:
+ perldoc $0
+HELP
+ return 1;
+} # cmd_help
+
=item B<GETVAL> I<Identifier>
=cut
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;
return 1;
}
+=item B<PUTNOTIF> [[B<severity>=I<$severity>] [B<message>=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