This file is indexed.

/usr/share/perl5/Mon/SNMP.pm is in mon-client 1.2.0-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
=head1 NAME

Mon::SNMP - decode SNMP trap

=head1 SYNOPSIS

    use Mon::SNMP;

    $trap = new Mon::SNMP;

    $trap->buffer($snmptrap);

    %traphash = $trap->decode;

    $error = $trap->error;


=head1 DESCRIPTION

Mon::SNMP provides methods to decode SNMP trap PDUs. It is based on
Graham Barr's Convert::BER module, and its purpose is to provide
SNMP trap handling to "mon".

It is not complete, so don't bother trying to use it unless you are
ready to debug and write some code.

=head1 METHODS

=over 4

=item B<new>

creates a new Mon::SNMP object.

=item B<buffer> ( buffer )

Assigns a raw SNMP trap message to the object.

=item B<decode>

Decodes a SNMP trap message, and returns a hash of the variable
assignments for the SNMP header and trap protocol data unit of the
associated message. The hash consists of the following members:

        version         =>      SNMP version (1)
        community       =>      community string
        ent_OID         =>      enterprise OID of originating agent
        agentaddr       =>      IP address of originating agent
        generic_trap    =>      /COLDSTART|WARMSTART|LINKDOWN|LINKUP|AUTHFAIL|EGPNEIGHBORLOSS|ENTERPRISESPECIFIC/
        specific_trap   =>      specific trap type (integer)
        timeticks       =>      timeticks (integer)
        varbindlist     =>      { oid1 => value, oid2 => value, ... }

=back

=head1 ERRORS

All methods return a hash with no elements upon errors which they detect,
and the detail of the error is available from the 

=head1 EXAMPLES

    use Mon::SNMP;

    $trap = new Mon::SNMP;

    $trap->buffer($snmptrap);

    %traphash = $trap->decode;

    foreach $oid (keys $traphash{"varbindlist"}) {
	$val = $traphash{"varbindlist"}{$oid};
    	print "oid($oid) = val($val)\n";
    }

=head1 ENVIRONMENT

None.

=head1 SEE ALSO

Graham Barr's Convert::BER module.

=head1 NOTES

=head1 CAVEATS

Mon::SNMP depends upon Convert::BER to do the real work.

=cut

#
#
# $Id: SNMP.pm,v 1.1.1.1 2004/06/18 14:25:16 trockij Exp $
#
# Copyright (C) 1998 Jim Trocki
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

package Mon::SNMP;

require Exporter;
require 5.004;

use Convert::BER;
use Convert::BER qw(/^(\$|BER_)/);
use Socket;

@ISA = qw(Exporter);
@EXPORT_OK = qw(@traptypes @ASN_DEFS $VERSION);

$VERSION = "1.0000";

@traptypes = ("COLDSTART", "WARMSTART", "LINKDOWN", "LINKUP", "AUTHFAIL",
	"EGPNEIGHBORLOSS", "ENTERPRISESPECIFIC");

@ASN_DEFS = (
	[ Trap_PDU              => $SEQUENCE,      BER_CONTEXT | BER_CONSTRUCTOR     | 0x04 ],
	[ IpAddress             => $STRING,        BER_APPLICATION                   | 0x00 ],
	[ Counter               => $INTEGER,       BER_APPLICATION                   | 0x01 ],
	[ Gauge                 => $INTEGER,       BER_APPLICATION                   | 0x02 ],
	[ TimeTicks             => $INTEGER,       BER_APPLICATION                   | 0x03 ],
	[ Opaque                => undef,          BER_APPLICATION                   | 0x04 ],
);


sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self  = {};

    $self->{"ERROR"} = undef;
    $self->{"version"} = undef;
    $self->{"community"} = undef;
    $self->{"ent_OID"} = undef;
    $self->{"agentaddr"} = undef;
    $self->{"generic_trap"} = undef;
    $self->{"specific_trap"} = undef;
    $self->{"timeticks"} = undef;
    %{$self->{"varbindlist"}} = ();
    $self->{"ber_varbindlist"} = undef;

    $self->{"BER"} = Convert::BER->new;
    $self->{"BER"}->define(@ASN_DEFS);

    bless ($self, $class);
    return $self;
}


sub error {
    my $self = shift;

    return $self->{"ERROR"};
}


sub buffer {
    my $self = shift;
    my $buf = shift;

    $self->{"ERROR"} = undef;

    $self->{"BER"}->buffer($buf);
}


sub decode {
    my $self = shift;
    my ($oid, $val);

    $self->{"ERROR"} = undef;

    if (! $self->{"BER"}->decode (
		SEQUENCE => [
		    INTEGER => \$self->{"version"},
		    STRING => \$self->{"community"},
		    Trap_PDU => [
			OBJECT_ID => \$self->{"ent_OID"},
			IpAddress => \$self->{"agentaddr"},
			INTEGER => \$self->{"generic_trap"},
			INTEGER => \$self->{"specific_trap"},
			TimeTicks => \$self->{"timeticks"},
			SEQUENCE => [
			    ANY => \$self->{"ber_varbindlist"},
			],
		    ],
		],
	    )) {
	
	$self->{"ERROR"} = "problem decoding BER";
	return ();
    }


   while ($self->{"ber_varbindlist"}->decode (
		SEQUENCE => [
			OBJECT_ID => \$oid,
			ANY => \$val,
		]
				)) {

	$self->{"varbindlist"}->{$oid} = $val;
   }

   return (
   	version		=>	$self->{"version"},
	community	=>	$self->{"community"},
	ent_OID		=>	$self->{"ent_OID"},
	agentaddr	=>	inet_ntoa ($self->{"agentaddr"}),
	generic_trap	=>	$traptypes[$self->{"generic_trap"}],
	specific_trap	=>	$self->{"specific_trap"},
	timeticks	=>	$self->{"timeticks"},
	varbindlist	=>	$self->{"varbindlist"},
   );
}


sub dump {
    my $self = shift;

    $self->{"BER"}->dump;
}