3 # collectd - contrib/cussh.pl
4 # Copyright (C) 2007 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);
60 print STDERR "Unable to connect to $path!\n";
64 print "cussh version 0.1, Copyright (C) 2007 Sebastian Harl\n"
65 . "cussh comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
66 . "and you are welcome to redistribute it under certain conditions.\n"
67 . "See the GNU General Public License 2 for more details.\n\n";
73 last if ((! $line) || ($line =~ m/^quit$/i));
75 my ($cmd) = $line =~ m/^(\w+)\s+/;
82 if ($cmd eq "PUTVAL") {
85 elsif ($cmd eq "GETVAL") {
89 print STDERR "ERROR: Unknown command $cmd!\n";
93 if (! $f->($sock, $line)) {
94 print STDERR "ERROR: Command failed!\n";
104 my $string = shift || return;
107 my ($h, $p, $pi, $t, $ti) =
108 $$string =~ m#^([^/]+)/([^/-]+)(?:-([^/]+))?/([^/-]+)(?:-([^/]+))?\s*#;
111 return if ((! $h) || (! $p) || (! $t));
115 ($id{'host'}, $id{'plugin'}, $id{'type'}) = ($h, $p, $t);
117 $id{'plugin_instance'} = $pi if defined ($pi);
118 $id{'type_instance'} = $ti if defined ($ti);
126 =item B<GETVAL> I<Identifier>
128 =item B<PUTVAL> I<Identifier> I<Valuelist>
130 These commands follow the exact same syntax as described in
131 L<collectd-unixsock(5)>.
136 my $sock = shift || return;
137 my $line = shift || return;
139 my $id = getid(\$line);
143 my ($time, @values) = split m/:/, $line;
144 return $sock->putval(%$id, $time, \@values);
148 my $sock = shift || return;
149 my $line = shift || return;
151 my $id = getid(\$line);
155 my $vals = $sock->getval(%$id);
159 foreach my $key (keys %$vals) {
160 print "\t$key: $vals->{$key}\n";
167 L<collectd(1)>, L<collectd-unisock(5)>
171 Written by Sebastian Harl E<lt>sh@tokkee.orgE<gt>.
173 B<collectd> has been written by Florian Forster and others.
177 Copyright (C) 2007 Sebastian Harl.
179 This program is free software; you can redistribute it and/or modify it under
180 the terms of the GNU General Public License as published by the Free Software
181 Foundation; only version 2 of the License is applicable.
185 # vim: set sw=4 ts=4 tw=78 noexpandtab :