This file is indexed.

/usr/share/doc/libsnmp-perl/examples/trap-example.pl is in libsnmp-perl 5.7.2~dfsg-8.1ubuntu3.

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
use strict;
use vars qw();
use SNMP qw();

&SNMP::initMib();

&SNMP::loadModules(
  'RFC2127-MIB',
  );

sub trap_call_setup;
sub trap_dummy;

#
# should eventually get these out of the MIB...
#
my %dispatch_table = (
  'isdnMibCallInformation', \&trap_call_setup,
  '.', \&trap_dummy,
);

sub trap_dispatcher
{
  my $session = shift;
  my $ref = shift;
  my $trapType;
  my ($reqid, $addr, $community);

  # if this is a timeout, then there will be no args...
  if (defined($ref)) {
    $ref->[1]->[2] = SNMP::translateObj($ref->[1]->val);
    $trapType = $ref->[1]->val;
    my $args = shift;
    ($reqid, $addr, $community) = @{$args};
  } else {
    $trapType = 'timeout';
  }

  if (defined($dispatch_table{$trapType})) {
    &{$dispatch_table{$trapType}}($session, $ref);
  } elsif (defined($dispatch_table{'.'})) {
    &{$dispatch_table{'.'}}($session, $ref);
  } else {
    # don't do anything... silently discard.
  }
}

sub trap_dummy
{
  my $session = shift;
  my $ref = shift;

  my $trapType = $ref->[1]->val;

  warn "unexpected trap " . $trapType;
}


sub trap_call_setup
{
  my $session = shift;
  my $varlist = shift;
  my $args = shift;

  my $ifIndex = $varlist->[2]->val;
  my $isdnBearerOperStatus = $varlist->[3]->val;
  my $isdnBearerPeerAddress = $varlist->[4]->val;
  my $isdnBearerPeerSubAddress = $varlist->[5]->val;
  my $isdnBearerInfoType = $varlist->[6]->val;
  my $isdnBearerCallOrigin = $varlist->[5]->val;

  my ($reqid, $ipaddr, $community) = @{$args};

  printf "Call from %s", $isdnBearerPeerAddress;
  printf "*%s", $isdnBearerPeerSubAddress if ($isdnBearerPeerSubAddress ne '');
  printf "\n";
}

my $session = new SNMP::Session(
  DestHost => 'udp:162',
  LocalPort => 1,
  Version => '2c',
  UseEnums => 0,
  );

if (!defined($session)) {
  die "can't create listener session";
}

# otherwise assume that ErrorNum is zero...

$session->SNMP::_catch([\&trap_dispatcher, $session]);

&SNMP::MainLoop();