This file is indexed.

/usr/share/munin/plugins/proxy_plugin is in munin-node 1.4.6-3ubuntu3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/perl -w
# -*- perl -*-

=head1 NAME

proxy_plugin - Plugin to proxy connections to another process speaking the
               munin-node protocol.

The typical use-case for this is to proxy requests to for example a JBoss
application server, without giving up the ability to run local plugins from
munin-node as well.

=head1 CONFIGURATION

The following environment settings are the default configuration.

  [<pluginname>]
     env.proxyto localhost
     env.proxyport 4950
     env.proxyservice <pluginname>

=head1 MAGIC MARKERS

  #%# family=manual

=head1 VERSION

  $Id$

=head1 BUGS

The plugin is currently hardcoded to require multigraph. There may be usecases
in the future where a non-multigraph version is useful.

There is no detection of loops - if the plugin is pointed back at itself,
infinite recursion is assured.

There is no timeout for sending and receiving data. The plugin relies on
munin-node to properly kill it if it runs too long.

=head1 AUTHOR

  Magnus Hagander <magnus.hagander@redpill-linpro.com>, Redpill Linpro AB

=head1 LICENSE

GPLv2

=cut

use strict;
use Munin::Plugin;
use IO::Socket;
use File::Basename;

# We are only going to support multigraph...
need_multigraph();

my $pluginname = basename($0);

if($ARGV[0] and $ARGV[0] eq "autoconf") {
	print "no\n"; # Might want to probe in the future?
	exit 0;
}

my $what = '';
if ($ARGV[0]) {
	if ($ARGV[0] eq "config") {
	   $what = "config";
	}
	else {
		die "Unknown command $ARGV[0]\n";
	}
}
else {
	$what = "fetch";
}

# Get the configured parameters
my $server  = $ENV{proxyto}      || "localhost";
my $port    = $ENV{proxyport}    || 4950;
my $service = $ENV{proxyservice} || $pluginname;

# Make the connection
my $sock = new IO::Socket::INET (
	PeerAddr => $server,
	PeerPort => $port,
	Proto => 'tcp',
	Timeout => 10, # only for connection it seems
) or die "Could not connect to server $server on port $port\n";
$sock->autoflush();

my $hdr = $sock->getline();
if ($hdr !~ /^# /) {
   $sock->close();
   die "Got invalid header from plugin: $hdr\n";
}

# Attempt to negotiate multigraph
$sock->print("cap multigraph\n");
my $r = $sock->getline();
if ($r !~ /^cap.*multigraph/) {
   $sock->close();
   die "Remote does not speak multigraph: $r\n";
}

# Check if the plugin config is compatible
$sock->print("list\n");
$r = $sock->getline();
unless (grep(/^$service$/, split(/ /, $r))) {
   $sock->close();
   die "Remote does know know of plugin $service (remote plugin list: $r)\n";
}

# Pass along the command and send back the results
$sock->print("$what $service\n");
while ($r = $sock->getline()) {
	last if $r =~ /^\.\n$/;
	print $r;
}

$sock->close();