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