This file is indexed.

/usr/share/doc/libsnmp-session-perl/examples/mrtg-ipmcast is in libsnmp-session-perl 1.14~git20130523.186a005-2.

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

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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/usr/bin/perl -w
##############################################################################
### File Name:	  mrtg-ipmcast
### Description:  Generate MRTG configuration for multicast statistics
### Author:	  Simon Leinen  <simon@switch.ch>
### Date Created: 20-Jun-2000
### RCS $Header: /home/leinen/CVS/SNMP_Session/test/mrtg-ipmcast,v 1.6 2001-03-07 15:38:11 leinen Exp $
##############################################################################
### This script can be used to generate a piece of MRTG[1]
### configuration file for plotting per-interface multicast traffic
### statistics using IPMROUTE-MIB[2].
###
### Usage: mrtg-ipmcast [-d DIR] [-w WORKDIR] [-i ICONDIR]
###          [-c COMMUNITY] [-v ( 1 | 2c )] [-p port] ROUTER1 ROUTER2 ...
###
### This will contact all ROUTERs under the specified COMMUNITY and
### look at some columns of the ipMRouteInterfaceTable.  For each rows
### for which those columns have defined values, an MRTG target
### definition will be written.  Such a target definition might look
### like this:
###
###     Target[swice1-multicast-atm4-0-0.6]: 1.3.6.1.3.60.1.1.4.1.5.66&1.3.6.1.3.60.1.1.4.1.6.66:secret@swiCE1.switch.ch
###     MaxBytes[swice1-multicast-atm4-0-0.6]: 19375000
###     AbsMax[swice1-multicast-atm4-0-0.6]: 19375000
###     Options[swice1-multicast-atm4-0-0.6]: growright,bits
###     Title[swice1-multicast-atm4-0-0.6]: Multicast Traffic on swiCE1.switch.ch:ATM4/0/0.6-aal5 layer (ATM PVC to swiZHX)
###     PageTop[swice1-multicast-atm4-0-0.6]: <hr><H3>Multicast Traffic on swiCE1.switch.ch:ATM4/0/0.6-aal5 layer (ATM PVC to swiZHX)</H3>
###     Directory[swice1-multicast-atm4-0-0.6]: multicast
###
### The OIDs are ipMRouteInterfaceInMcastOctets and
### ipMRouteInterfaceOutMcastOctets indexed for the interface.  In the
### example, the interface has index 66, and the ifName is
### "ATM4/0/0.6".
###
### "AbsMax" is taken from the ifSpeed value for the interface.
###
### "MaxBytes" is set to the multicast rate limit as per
### ipMRouteInterfaceRateLimit.  If no rate-limit is specified, the
### same value as for AbsMax will be used.
###
### "Directory" is only defined if the "-d DIR" option has been passed
### to the script.  In the example, the script has been called with
### "-d multicast".
###
### The "-w" and "-i" options can be used to cause WorkDir and IconDir
### definitions to be generated, respectively.
##############################################################################

use strict;
use SNMP_Session "0.58";
use BER;
use Socket;

## Forward declarations
sub usage ($ );

### If set, a Directory[] attribute pointing to this directory will be
### included for every target in the generated configuration.
my $directory;

## Define this if you want WorkDir set in the generated configuration
## file.
##
my $work_dir;

## Define this if you want IconDir set in the generated configuration
## file.
##
my $icon_dir;

## An absolute maximum for traffic rates over tunnels, in Bytes per
## second.  You probably don't need to change this.
##
my $abs_max = '100000000';

my $mrouters = [];

my $version = '1';

my $community = 'public';

my $port = 161;

while (@ARGV) {
    if ($ARGV[0] =~ /^-h/) {
	usage (0);
	exit (0);
    } elsif ($ARGV[0] =~ /^-p/) {
	if ($ARGV[0] eq '-p') {
	    shift @ARGV;
	    usage (1) unless defined $ARGV[0];
	} else {
	    $ARGV[0] = substr($ARGV[0], 2);
	}
	if ($ARGV[0] =~ /^[0-9]+$/) {
	    $port = $ARGV[0];
	} else {
	    usage (1);
	}
    } elsif ($ARGV[0] =~ /^-v/) {
	if ($ARGV[0] eq '-v') {
	    shift @ARGV;
	    usage (1) unless defined $ARGV[0];
	} else {
	    $ARGV[0] = substr($ARGV[0], 2);
	    $version = '2c' if ($ARGV[0] eq '2');
	}
	if ($ARGV[0] eq '1') {
	    $version = '1';
	} elsif ($ARGV[0] eq '2c') {
	    $version = '2c';
	} elsif ($ARGV[0] eq '2') {
	    $version = '2c';
	} else {
	    usage (1);
	}
    } elsif ($ARGV[0] eq '-c') {
	shift @ARGV;
	usage (1) unless @ARGV;
	$community = $ARGV[0];
    } elsif ($ARGV[0] eq '-d') {
	shift @ARGV;
	usage (1) unless @ARGV;
	$directory = $ARGV[0];
    } elsif ($ARGV[0] eq '-w') {
	shift @ARGV;
	usage (1) unless @ARGV;
	$work_dir = $ARGV[0];
    } elsif ($ARGV[0] eq '-i') {
	shift @ARGV;
	usage (1) unless @ARGV;
	$icon_dir = $ARGV[0];
    } else {
	push @{$mrouters}, "$community\@$ARGV[0]:$port";
    }
    shift @ARGV;
}

my %pretty_protocol_name =
(
  1 => "other",
  2 => "local",
  3 => "netmgmt",
  4 => "dvmrp",
  5 => "mospf",
  6 => "pimSparseDense",
  7 => "cbt",
  8 => "pimSparseMode",
  9 => "pimDenseMode",
  10 => "igmpOnly",
  11 => "bgmp",
  12 => "msdp",
);

my $ipMRouteInterfaceTtl = [1,3,6,1,3,60,1,1,4,1,2];
my $ipMRouteInterfaceProtocol = [1,3,6,1,3,60,1,1,4,1,3];
my $ipMRouteInterfaceRateLimit = [1,3,6,1,3,60,1,1,4,1,4];
my $ipMRouteInterfaceInMcastOctets = [1,3,6,1,3,60,1,1,4,1,5];
my $ipMRouteInterfaceOutMcastOctets = [1,3,6,1,3,60,1,1,4,1,6];

## Print head of configuration file
print "WorkDir: $work_dir\n" if defined $work_dir;
print "IconDir: $icon_dir\n" if defined $icon_dir;
print "WriteExpires: Yes\nWeekformat[^]: V\nWithPeak[_]: wmy\n";

foreach my $target (@{$mrouters}) {
    my $session;
    my ($community, $mrouter, $port);

    if ($target =~ /^(.*)@(.*):([0-9]+)$/) {
	$community = $1; $mrouter = $2; $port = $3;
    } elsif ($target =~ /^(.*)@(.*)$/) {
	$community = $1; $mrouter = $2; $port = 161;
    } else {
	warn "Malformed target $target\n";
	next;
    }
    $session =
	($version eq '1' ? SNMPv1_Session->open ($mrouter, $community, $port)
	 : $version eq '2c' ? SNMPv2c_Session->open ($mrouter, $community, $port)
	 : die "Unknown SNMP version $version")
	    || die "Opening SNMP_Session to router $mrouter";

    my $if_table = $session->get_if_table;

    my $snmp_target = $community.'@'.$mrouter;
    $snmp_target .= ":".$port
	unless $port == 161;
## eval
    {
	$session->map_table
	([$ipMRouteInterfaceTtl,
	  $ipMRouteInterfaceProtocol,
	  $ipMRouteInterfaceRateLimit], sub
	 { 
	     my ($index, $ttl, $protocol, $rate_limit) = @_;
	     grep (defined $_ && ($_=pretty_print $_),
		   ($protocol, $ttl, $rate_limit));
	     my ($if_entry, $abs_max_bytes, $rate_limit_bytes,
		 $interface, $mr, $graph_name);
	     die unless defined ($if_entry = $if_table->{$index});
	     if (defined $if_entry->{ifSpeed}) {
		 if ($rate_limit == 0 || $if_entry->{ifSpeed} < $rate_limit) {
		     $rate_limit = $if_entry->{ifSpeed} / 1000;
		 }
		 $abs_max_bytes = $if_entry->{ifSpeed} >> 3
		     if defined $if_entry->{ifSpeed};
	     } else {
	     }
	     $abs_max_bytes = $abs_max >> 3
		 unless defined $abs_max_bytes;
	     $rate_limit_bytes = $rate_limit * 1000 >> 3;

	     $protocol = $pretty_protocol_name{$protocol}
	     if exists $pretty_protocol_name{$protocol};
##	       my $peer_name = gethostbyaddr(pack ("C4",split ('\.',$peer_addr)),
##					     AF_INET)
##		   || $peer_addr;
	     my $peer_name = "?";
	     $interface = $index;
	     if (defined ($if_entry->{ifDescr})) {
		 $interface = $if_entry->{ifDescr};
	     }
	     print STDERR "IF $interface TTL $ttl $protocol\n";
	     $mr = $mrouter;
	     $mr =~ s/\..*//;
	     $graph_name = lc ($mr.'-multicast-'.cleanup ($interface));
	      if (defined ($if_entry->{ifAlias}) && $if_entry->{ifAlias} ne '') {
		  $interface .= " (".$if_entry->{ifAlias}.")";
	      } elsif (defined ($if_entry->{locIfDescr}) && $if_entry->{locIfDescr} ne '') {
		  $interface .= " (".$if_entry->{locIfDescr}.")";
	      }
		 print <<EOM;

Target[$graph_name]: 1.3.6.1.3.60.1.1.4.1.5.$index&1.3.6.1.3.60.1.1.4.1.6.$index:$snmp_target
MaxBytes[$graph_name]: $rate_limit_bytes
AbsMax[$graph_name]: $abs_max_bytes
Options[$graph_name]: growright,bits
Title[$graph_name]: Multicast Traffic on $mrouter:$interface
PageTop[$graph_name]: <hr><H3>Multicast Traffic on $mrouter:$interface</H3>
EOM
    print "Directory[$graph_name]: $directory\n"
	if $directory;
	 })
};
    $session->close ();
}

sub cleanup ($ ) {
    local ($_) = @_;
    s@/@-@g;
    s@-(aal5|cef) layer$@@;
    $_;
}

sub usage ($) {
    warn <<EOM;
Usage: $0 [-w workdir] [-i icondir] [-v (1|2c)] [-p port] [-c community] hostname...
       $0 -h

  -h           print this usage message and exit.

  -w workdir   specifies the WorkDir parameter for the generated MRTG
               configuration file.

  -i icondir   specifies the IconDir parameter for the generated MRTG
               configuration file.

  -v version   can be used to select the SNMP version.  The default
   	       is SNMPv1, which is what most devices support.  If your box
   	       supports SNMPv2c, you should enable this by passing "-v 2c"
   	       to the script.  SNMPv2c is much more efficient for walking
   	       tables, which is what this tool does.

  -p port      can be used to specify a non-standard UDP port of the SNMP
               agent (the default is UDP port 161).

  -c community SNMP community string to use.  Defaults to "public".

  hostname...  hostnames or IP addresses of multicast routers
EOM
    exit (1) if $_[0];
}

package SNMP_Session;

sub get_if_table ($) {
    my ($session) = @_;

    my $result = {};

    my $ifDescr = [1,3,6,1,2,1,2,2,1,2];
    my $ifSpeed = [1,3,6,1,2,1,2,2,1,5];
    my $locIfDescr = [1,3,6,1,4,1,9,2,2,1,1,28];
    my $ifAlias = [1,3,6,1,2,1,31,1,1,1,18];
    $session->map_table ([$ifDescr,$ifSpeed],
			 sub ($$$) {
			     my ($index, $ifDescr, $ifSpeed) = @_;
			     grep (defined $_ && ($_=pretty_print $_),
				   ($ifDescr, $ifSpeed));
			     $result->{$index} = {'ifDescr' => $ifDescr,
						  'ifSpeed' => $ifSpeed};
			 });
    $session->map_table ([$locIfDescr],
			 sub ($$$) {
			     my ($index, $locIfDescr) = @_;
			     grep (defined $_ && ($_=pretty_print $_),
				   ($locIfDescr));
			     $result->{$index}->{'locIfDescr'} = $locIfDescr;
			 });
    $session->map_table ([$ifAlias],
			 sub ($$$) {
			     my ($index, $ifAlias) = @_;
			     grep (defined $_ && ($_=pretty_print $_),
				   ($ifAlias));
			     $result->{$index}->{'ifAlias'} = $ifAlias;
			 });
    $result;
}