2 # Copyright (C) 2002 Stanislav Sinyagin
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.
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.
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.
18 # $Id: action_snmpv1trap.in,v 1.1 2010-12-27 00:04:02 ivan Exp $
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
21 # Obsoleted and not used SNMP v1 trap script.
22 # Version 2c is preferred one.
26 use Net::SNMP qw(:ALL);
29 require '@snmptrap_siteconfig_pl@';
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';
36 if( not $ENV{'TORRUS_TOKEN'} )
38 print STDERR ("Torrus environment variables missing. This program ",
39 "must be run from Torrus Monitor\n");
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 );
54 print STDERR ("Error parsing options\n");
58 if( scalar(@hosts) > 0 )
60 @Torrus::Snmptrap::hosts = @hosts;
63 my %specifictrap = ( 'set' => 1,
69 my @varbindlist = ( $Torrus::Snmptrap::enterprise . '.2',
70 OCTET_STRING, $ENV{'TORRUS_TOKEN'},
72 $Torrus::Snmptrap::enterprise . '.5',
73 OCTET_STRING, $ENV{'TORRUS_NODEPATH'},
75 $Torrus::Snmptrap::enterprise . '.3',
76 OCTET_STRING, $ENV{'TORRUS_MONITOR'},
78 $Torrus::Snmptrap::enterprise . '.4',
79 OCTET_STRING, $ENV{'TORRUS_EVENT'},
81 $Torrus::Snmptrap::enterprise . '.6',
82 OCTET_STRING, scalar(localtime($ENV{'TORRUS_TSTAMP'})),
84 $Torrus::Snmptrap::enterprise . '.7',
85 OCTET_STRING, $ENV{'TORRUS_TREE'},
87 $Torrus::Snmptrap::enterprise . '.9',
88 OCTET_STRING, $ENV{'TORRUS_MCOMMENT'}
91 if( defined( $severity ) )
94 $Torrus::Snmptrap::enterprise . '.8',
95 INTEGER32, $severity );
98 foreach my $host ( @Torrus::Snmptrap::hosts )
100 my( $session, $error ) =
101 Net::SNMP->session( -hostname => $host,
102 -community => $Torrus::Snmptrap::community,
103 -port => $Torrus::Snmptrap::port
106 if( not defined($session) )
108 printf STDERR ("Error opening SNMP trap session: %s.\n", $error);
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
123 printf STDERR ("Error sending SNMP trap: %s.\n", $session->error());
132 # indent-tabs-mode: nil
133 # perl-indent-level: 4