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