1 karl 1.11 //%2004////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.11 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.9 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.11 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 mike 1.2 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
11 kumpf 1.5 // of this software and associated documentation files (the "Software"), to
12 // deal in the Software without restriction, including without limitation the
13 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
14 mike 1.2 // sell copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
16 //
|
17 kumpf 1.5 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
18 mike 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
19 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
20 kumpf 1.5 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
23 mike 1.2 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26 //==============================================================================
27 //
28 // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
29 //
|
30 kumpf 1.6 // Modified By: Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
|
31 mike 1.2 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
|
34 kumpf 1.3 #include "sr_conf.h"
35 #include <stdio.h>
36 #include <stdarg.h>
37 #include <unistd.h>
38 #include <fcntl.h>
39 #include <string.h>
40 #include <stdlib.h>
41
42 #include <sys/types.h>
43 #include <sys/sem.h>
44 #include <sys/stat.h>
45 #include <sys/param.h>
46
47 #include <signal.h>
48 #include <netinet/in.h>
49 #include <sys/socket.h>
50 #include <arpa/inet.h>
51 #include <netdb.h>
52 #include <errno.h>
53
54 #include "sr_snmp.h"
55 kumpf 1.3 #include "comunity.h"
56 #include "v2clssc.h"
57 #include "sr_trans.h"
58 #include "context.h"
59 #include "method.h"
60 #include "diag.h"
61 #include "subagent.h"
62 #include "agentsoc.h"
63 #include "evq.h"
64 #include "sig.h"
65
|
66 mike 1.2 #include <iostream>
67 #include <Pegasus/Common/Config.h>
68
69 #include "snmpDeliverTrap.h"
70
|
71 kumpf 1.6 PEGASUS_NAMESPACE_BEGIN
72
|
73 humberto 1.7 // l10n
74 // lots of hacking to make up these messages
|
75 kumpf 1.6
|
76 humberto 1.8 static const char _MSG_INITSUBAGENT_FAILED [] = "InitSubagent Failed to initialize";
|
77 humberto 1.7 static const char _MSG_INITSUBAGENT_FAILED_KEY [] =
78 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_INITSUBAGENT_FAILED";
79
|
80 humberto 1.8 static const char _MSG_INVALID_TRAPOID [] = "Invalid trapOid.";
|
81 humberto 1.7 static const char _MSG_INVALID_KEY [] =
82 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_INVALID";
|
83 kumpf 1.6
84 static const char _MSG_DESTINATION_NOT_FOUND [] = "Can not find trap destination.";
|
85 humberto 1.7 static const char _MSG_DESTINATION_NOT_FOUND_KEY [] =
86 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_DESTINATION_NOT_FOUND";
|
87 kumpf 1.6
88 static const char _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED [] =
|
89 humberto 1.8 "Host Name and IPV4 Address are the only supported TargetHostFormat values.";
|
90 humberto 1.7 static const char _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED_KEY [] =
91 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_TARGETHOSTFORMAT_NOT_SUPPORTED";
92
|
93 humberto 1.8 static const char _MSG_INVALID_SECURITY_NAME [] = "Invalid SNMP SecurityName.";
|
94 humberto 1.7 static const char _MSG_INVALID_SECURITY_NAME_KEY [] =
95 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_INVALID";
|
96 kumpf 1.6
97 static const char _MSG_INVALID_OCTET_VALUE [] =
98 "Invalid octet value in trap destination.";
|
99 humberto 1.7 static const char _MSG_INVALID_OCTET_VALUE_KEY [] =
100 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_INVALID_OCTET_VALUE";
|
101 kumpf 1.6
102 static const char _MSG_CREATE_OCTET_FAILED [] =
|
103 humberto 1.8 "Creation of empty 4 length OctetString failed.";
|
104 humberto 1.7 static const char _MSG_CREATE_OCTET_FAILED_KEY [] =
105 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_CREATE_OCTET_FAILED";
106
|
107 humberto 1.8 static const char _MSG_INVALID_ENTERPRISEOID [] = "Invalid enterpriseOid.";
|
108 humberto 1.7 static const char _MSG_INVALID_ENTERPRISEOID_KEY [] =
109 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_INVALID";
110
|
111 humberto 1.8 static const char _MSG_INVALID_PROPERTYOID [] = "Invalid OID of CIM Property.";
|
112 humberto 1.7 static const char _MSG_INVALID_PROPERTYOID_KEY [] =
113 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_INVALID_PROPERTYOID";
114
|
115 humberto 1.8 static const char _MSG_INVALID_PROPERTYVALUE [] = "Invalid value of CIM Property.";
|
116 humberto 1.7 static const char _MSG_INVALID_PROPERTYVALUE_KEY [] =
117 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_INVALID_PROPERTY";
118
|
119 humberto 1.8 static const char _MSG_MAKE_VARBIND_FAILED_FOR_OCTET_PRIM_TYPE [] =
120 "Failed to MakeVarBindWithValue for type OCTET_PRIM_TYPE.";
121 static const char _MSG_MAKE_VARBIND_FAILED_FOR_OCTET_PRIM_TYPE_KEY [] =
122 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_MAKE_FAILED_FOR_OCTET_PRIM_TYPE";
123
124 static const char _MSG_MAKE_VARBIND_FAILED_FOR_OBJECT_ID_TYPE [] =
125 "Failed to MakeVarBindWithValue for type OBJECT_ID_TYPE.";
126 static const char _MSG_MAKE_VARBIND_FAILED_FOR_OBJECT_ID_TYPE_KEY [] =
127 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_MAKE_FAILED_FOR_OBJECT_ID_TYPE";
128
129 static const char _MSG_MAKE_VARBIND_FAILED_FOR_INTEGER_TYPE [] =
130 "Failed to MakeVarBindWithValue for type INTEGER_TYPE.";
131 static const char _MSG_MAKE_VARBIND_FAILED_FOR_INTEGER_TYPE_KEY [] =
132 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_MAKE_FAILED_FOR_INTEGER_TYPE";
|
133 kumpf 1.6
134
135 static const char _MSG_VERSION_NOT_SUPPORTED [] =
|
136 humberto 1.8 "SNMPv1 Trap and SNMPv2C Trap are the only supported SNMPVersion values.";
|
137 humberto 1.7 static const char _MSG_VERSION_NOT_SUPPORTED_KEY [] =
138 "Handler.snmpIndicationHandler.snmpDeliverTrap_emanate._MSG_VERSION_NOT_SUPPORTED";
|
139 mike 1.2
140 class snmpDeliverTrap_emanate : public snmpDeliverTrap
141 {
142 public:
|
143 kumpf 1.3
144 snmpDeliverTrap_emanate();
145
146 ~snmpDeliverTrap_emanate();
147
148 void initialize();
149
|
150 kumpf 1.6 /**
151 Send snmp trap to the target.
152 @param trapOid snmp trap OID
153 @param securityName either an SNMPv1 or SNMPv2c community
154 name or an SNMPv3 user name
155 @param targetHost address of the trap/infom destination
156 @param targetHostFormat targetHost format
157 @param otherTargetHostFormat other target format type
158 @param portNumber UDP port number to send the trap/inform
159 @param snmpVersion snmp version and format to use to send the indication
160 @param engineID snmp engine ID used to create the SNMPv3 inform
161 @param vbOids VarBind OIDs
162 @param vbTypes VarBind types
163 @param vbValues VarBind values
164 */
|
165 mike 1.2 void deliverTrap(
|
166 kumpf 1.6 const String& trapOid,
167 const String& securityName,
168 const String& targetHost,
169 const Uint16& targetHostFormat,
170 const String& otherTargetHostFormat,
171 const Uint32& portNumber,
172 const Uint16& snmpVersion,
173 const String& engineID,
|
174 kumpf 1.10 const Array<String>& vbOids,
175 const Array<String>& vbTypes,
176 const Array<String>& vbValues);
|
177 kumpf 1.6
178 private:
179 char * _getIPAddress(const CString& hostName);
180 Boolean _isValidOctet(const Uint32& octetValue);
181
182 /**
183 Values for the TargetHostFormat property of the
184 PG_IndicationHandlerSNMPMapper class.
185 */
186 enum TargetHostFormat {_OTHER = 1, _HOST_NAME = 2,
187 _IPV4_ADDRESS = 3, _IPV6_ADDRESS = 4};
188 enum SNMPVersion {_SNMPv1_TRAP = 2, _SNMPv2C_TRAP = 3,
189 _SNMPv2C_INFORM = 4, _SNMPv3_TRAP = 5, _SNMPv3_INFORM = 6};
|
190 mike 1.2 };
191
192 PEGASUS_NAMESPACE_END
|