3 # collectd - contrib/cussh.pl
4 # Copyright (C) 2007-2008 Sebastian Harl
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; only version 2 of the License is applicable.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # Sebastian Harl <sh at tokkee.org>
25 cussh - collectd UNIX socket shell
29 B<cussh> [I<E<lt>pathE<gt>>]
33 B<collectd>'s unixsock plugin allows external programs to access the values it
34 has collected or received and to submit own values. This is a little
35 interactive frontend for this plugin.
41 =item I<E<lt>pathE<gt>>
43 The path to the UNIX socket provided by collectd's unixsock plugin. (Default:
44 F</var/run/collectd-unixsock>)
53 use Collectd::Unixsock();
56 my $path = $ARGV[0] || "/var/run/collectd-unixsock";
57 my $sock = Collectd::Unixsock->new($path);
67 print STDERR "Unable to connect to $path!\n";
71 print "cussh version 0.2, Copyright (C) 2007-2008 Sebastian Harl\n"
72 . "cussh comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
73 . "and you are welcome to redistribute it under certain conditions.\n"
74 . "See the GNU General Public License 2 for more details.\n\n";
84 last if ($line =~ m/^quit$/i);
86 my ($cmd) = $line =~ m/^(\w+)\s*/;
93 if (defined $cmds->{$cmd}) {
97 print STDERR "ERROR: Unknown command $cmd!\n";
101 if (! $f->($sock, $line)) {
102 print STDERR "ERROR: Command failed!\n";
112 my $string = shift || return;
115 my ($h, $p, $pi, $t, $ti) =
116 $$string =~ m/^(\w+)\/(\w+)(?:-(\w+))?\/(\w+)(?:-(\w+))?\s*/;
119 return if ((! $h) || (! $p) || (! $t));
123 ($id{'host'}, $id{'plugin'}, $id{'type'}) = ($h, $p, $t);
125 $id{'plugin_instance'} = $pi if ($pi);
126 $id{'type_instance'} = $ti if ($ti);
131 my $ident = shift || return;
135 $string = $ident->{'host'} . "/" . $ident->{'plugin'};
137 if (defined $ident->{'plugin_instance'}) {
138 $string .= "-" . $ident->{'plugin_instance'};
141 $string .= "/" . $ident->{'type'};
143 if (defined $ident->{'type_instance'}) {
144 $string .= "-" . $ident->{'type_instance'};
153 =item B<GETVAL> I<Identifier>
158 my $sock = shift || return;
159 my $line = shift || return;
161 my $id = getid(\$line);
164 print STDERR $sock->{'error'} . $/;
168 my ($time, @values) = split m/:/, $line;
169 return $sock->putval(%$id, time => $time, values => \@values);
172 =item B<PUTVAL> I<Identifier> I<Valuelist>
177 my $sock = shift || return;
178 my $line = shift || return;
180 my $id = getid(\$line);
183 print STDERR $sock->{'error'} . $/;
187 my $vals = $sock->getval(%$id);
190 print STDERR $sock->{'error'} . $/;
194 foreach my $key (keys %$vals) {
195 print "\t$key: $vals->{$key}\n";
200 =item B<FLUSH> [B<timeout>=I<$timeout>] [B<plugin>=I<$plugin>[ ...]]
205 my $sock = shift || return;
211 $res = $sock->flush();
216 foreach my $i (split m/ /, $line) {
217 my ($option, $value) = $i =~ m/^([^=]+)=(.+)$/;
218 next if (! ($option && $value));
220 if ($option eq "plugin") {
221 push @{$args{"plugins"}}, $value;
223 elsif ($option eq "timeout") {
224 $args{"timeout"} = $value;
227 print STDERR "Invalid option \"$option\".\n";
232 $res = $sock->flush(%args);
236 print STDERR $sock->{'error'} . $/;
247 my $sock = shift || return;
251 @res = $sock->listval();
254 print STDERR $sock->{'error'} . $/;
258 foreach my $ident (@res) {
259 print $ident->{'time'} . " " . putid($ident) . $/;
266 These commands follow the exact same syntax as described in
267 L<collectd-unixsock(5)>.
271 L<collectd(1)>, L<collectd-unisock(5)>
275 Written by Sebastian Harl E<lt>sh@tokkee.orgE<gt>.
277 B<collectd> has been written by Florian Forster and others.
281 Copyright (C) 2007 Sebastian Harl.
283 This program is free software; you can redistribute it and/or modify it under
284 the terms of the GNU General Public License as published by the Free Software
285 Foundation; only version 2 of the License is applicable.
289 # vim: set sw=4 ts=4 tw=78 noexpandtab :