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