This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / torrus / bin / action_snmpv1trap.in
1 #!@PERL@
2 #  Copyright (C) 2002  Stanislav Sinyagin
3 #
4 #  This program is free software; you can redistribute it and/or modify
5 #  it under the terms of the GNU General Public License as published by
6 #  the Free Software Foundation; either version 2 of the License, or
7 #  (at your option) any later version.
8 #
9 #  This program is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #  GNU General Public License for more details.
13 #
14 #  You should have received a copy of the GNU General Public License
15 #  along with this program; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17
18 # $Id: action_snmpv1trap.in,v 1.1 2010-12-27 00:04:02 ivan Exp $
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
20
21 # Obsoleted and not used SNMP v1 trap script.
22 # Version 2c is preferred one.
23
24
25 use strict;
26 use Net::SNMP qw(:ALL);
27 use Getopt::Long;
28
29 require '@snmptrap_siteconfig_pl@';
30
31 # SNMP Enterprise. Needed for SNMP v1 trap.
32 # See http://www.iana.org/assignments/enterprise-numbers for reference
33 $Torrus::Snmptrap::enterprise = '1.3.6.1.4.1.14697.1.1.1';
34
35
36 if( not $ENV{'TORRUS_TOKEN'} )
37 {
38     print STDERR ("Torrus environment variables missing. This program ",
39                   "must be run from Torrus Monitor\n");
40     exit 1;
41 }
42
43 my @hosts;
44 my $severity;
45
46 my $ok = GetOptions( 'host=s'     => \@hosts,
47                      'community=s' => \$Torrus::Snmptrap::community,
48                      'port=i'      => \$Torrus::Snmptrap::port,
49                      'enterprise'  => \$Torrus::Snmptrap::enterprise,
50                      'severity=i'  => \$severity );
51
52 if( not $ok )
53 {
54     print STDERR ("Error parsing options\n");
55     exit 1;
56 }
57
58 if( scalar(@hosts) > 0 )
59 {
60     @Torrus::Snmptrap::hosts = @hosts;
61 }
62
63 my %specifictrap = ( 'set'    => 1,
64                      'repeat' => 2,
65                      'clear'  => 3,
66                      'forget' => 4
67                      );
68
69 my @varbindlist = ( $Torrus::Snmptrap::enterprise . '.2',
70                     OCTET_STRING, $ENV{'TORRUS_TOKEN'},
71
72                     $Torrus::Snmptrap::enterprise . '.5',
73                     OCTET_STRING, $ENV{'TORRUS_NODEPATH'},
74
75                     $Torrus::Snmptrap::enterprise . '.3',
76                     OCTET_STRING, $ENV{'TORRUS_MONITOR'},
77
78                     $Torrus::Snmptrap::enterprise . '.4',
79                     OCTET_STRING, $ENV{'TORRUS_EVENT'},
80
81                     $Torrus::Snmptrap::enterprise . '.6',
82                     OCTET_STRING, scalar(localtime($ENV{'TORRUS_TSTAMP'})),
83
84                     $Torrus::Snmptrap::enterprise . '.7',
85                     OCTET_STRING, $ENV{'TORRUS_TREE'},
86                     
87                     $Torrus::Snmptrap::enterprise . '.9',
88                     OCTET_STRING, $ENV{'TORRUS_MCOMMENT'}
89                     );
90
91 if( defined( $severity ) )
92 {
93     push( @varbindlist,
94           $Torrus::Snmptrap::enterprise . '.8',
95           INTEGER32, $severity );
96 }
97
98 foreach my $host ( @Torrus::Snmptrap::hosts )
99 {
100     my( $session, $error ) =
101         Net::SNMP->session( -hostname  => $host,
102                             -community => $Torrus::Snmptrap::community,
103                             -port      => $Torrus::Snmptrap::port
104                             );
105
106     if( not defined($session) )
107     {
108         printf STDERR ("Error opening SNMP trap session: %s.\n", $error);
109         exit 1;
110     }
111
112
113     my $result =
114         $session->trap( -enterprise   => $Torrus::Snmptrap::enterprise,
115                         -generictrap  => ENTERPRISE_SPECIFIC,
116                         -specifictrap => $specifictrap{$ENV{'TORRUS_EVENT'}},
117                         -timestamp    => $ENV{'TORRUS_UPTIME'} * 100,
118                         -varbindlist  => \@varbindlist
119                         );
120
121     if( not $result )
122     {
123         printf STDERR ("Error sending SNMP trap: %s.\n", $session->error());
124     }
125
126     $session->close();
127 }
128
129
130 # Local Variables:
131 # mode: perl
132 # indent-tabs-mode: nil
133 # perl-indent-level: 4
134 # End: