version 1.5, 2002/03/27 21:27:35
|
version 1.8, 2002/04/25 16:27:25
|
|
|
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/System.h> | #include <Pegasus/Common/System.h> |
|
#include <Pegasus/Common/Destroyer.h> |
#include <fcntl.h> | #include <fcntl.h> |
#include <unistd.h> | #include <unistd.h> |
#include <ctype.h> | #include <ctype.h> |
|
|
initialize(); | initialize(); |
| |
// TRAP OID: getting trapOid | // TRAP OID: getting trapOid |
char* _trapOid = trapOid.allocateCString(); |
ArrayDestroyer<char> _trapOid(trapOid.allocateCString()); |
OID *sendtrapOid = MakeOIDFromDot(_trapOid); |
_trapOid.getPointer()[strlen(_trapOid.getPointer())-1] = '\0'; |
|
OID *sendtrapOid = MakeOIDFromDot(_trapOid.getPointer()); |
| |
// Destination : converting destination into Transport | // Destination : converting destination into Transport |
char* trap_dest = destination.allocateCString(); |
ArrayDestroyer<char> trap_dest(destination.allocateCString()); |
TransportInfo global_ti; | TransportInfo global_ti; |
global_ti.type = SR_IP_TRANSPORT; | global_ti.type = SR_IP_TRANSPORT; |
global_ti.t_ipAddr = inet_addr(trap_dest); |
global_ti.t_ipAddr = inet_addr(trap_dest.getPointer()); |
global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort()); | global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort()); |
delete [] trap_dest; |
|
| |
// Community Name | // Community Name |
char* _community = community.allocateCString(); |
ArrayDestroyer<char> _community(community.allocateCString()); |
OctetString* community_name = MakeOctetStringFromText(_community); |
OctetString* community_name = MakeOctetStringFromText( |
delete [] _community; |
_community.getPointer()); |
| |
// getting IP address of the host | // getting IP address of the host |
char* hostname = System::getHostName().allocateCString(); |
ArrayDestroyer<char> hostname(System::getHostName().allocateCString()); |
char **p; | char **p; |
struct hostent *hp; | struct hostent *hp; |
struct in_addr in; | struct in_addr in; |
hp=gethostbyname(hostname); |
hp=gethostbyname(hostname.getPointer()); |
p = hp->h_addr_list; | p = hp->h_addr_list; |
(void)memcpy(&in.s_addr, *p, sizeof(in.s_addr)); | (void)memcpy(&in.s_addr, *p, sizeof(in.s_addr)); |
char* IP_string = inet_ntoa(in); | char* IP_string = inet_ntoa(in); |
delete [] hostname; |
|
| |
// formatting agent(host) address into OctetString format | // formatting agent(host) address into OctetString format |
OctetString* agent_addr; | OctetString* agent_addr; |
|
|
agent_addr->octet_ptr[2] = (unsigned char)s3; | agent_addr->octet_ptr[2] = (unsigned char)s3; |
agent_addr->octet_ptr[3] = (unsigned char)s4; | agent_addr->octet_ptr[3] = (unsigned char)s4; |
| |
// ATTN-NU-20020312 : Write code to get enterprise, genTrap and |
|
// specTrap from trapOid. | // specTrap from trapOid. |
|
|
//NU_SNMP |
|
|
|
SR_INT32 genTrap = 0; | SR_INT32 genTrap = 0; |
SR_INT32 specTrap = 0; | SR_INT32 specTrap = 0; |
| |
|
|
for (Uint8 i = 1; i < oids.size()-1; i++) | for (Uint8 i = 1; i < oids.size()-1; i++) |
ent = ent + "." + oids[i]; | ent = ent + "." + oids[i]; |
| |
char* gtrap = ent.allocateCString(); |
ArrayDestroyer<char> gtrap(ent.allocateCString()); |
genTrap = atoi(gtrap) - 1; |
genTrap = atoi(gtrap.getPointer()) - 1; |
enterpriseOid = sendtrapOid; | enterpriseOid = sendtrapOid; |
delete [] gtrap; |
|
} | } |
else | else |
{ | { |
|
|
ent = oids[0]; | ent = oids[0]; |
for (Uint8 i = 1; i < oids.size()-1; i++) | for (Uint8 i = 1; i < oids.size()-1; i++) |
ent = ent + "." + oids[i]; | ent = ent + "." + oids[i]; |
char* strap = oids[oids.size()-1].allocateCString(); |
ArrayDestroyer<char> strap(oids[oids.size()-1].allocateCString()); |
specTrap = atoi(strap); |
specTrap = atoi(strap.getPointer()); |
delete [] strap; |
|
| |
if (oids[oids.size()-2] == "0") | if (oids[oids.size()-2] == "0") |
{ | { |
|
|
for (Uint8 i = 1; i < oids.size()-2; i++) | for (Uint8 i = 1; i < oids.size()-2; i++) |
ent = ent + "." + oids[i]; | ent = ent + "." + oids[i]; |
| |
char* _ent = ent.allocateCString(); |
ArrayDestroyer<char> _ent(ent.allocateCString()); |
enterpriseOid = MakeOIDFromDot(_ent); |
enterpriseOid = MakeOIDFromDot(_ent.getPointer()); |
delete [] _ent; |
|
} | } |
else | else |
{ | { |
|
|
for (Uint8 i = 1; i < oids.size()-1; i++) | for (Uint8 i = 1; i < oids.size()-1; i++) |
ent = ent + "." + oids[i]; | ent = ent + "." + oids[i]; |
| |
char* _ent = ent.allocateCString(); |
ArrayDestroyer<char> _ent(ent.allocateCString()); |
enterpriseOid = MakeOIDFromDot(_ent); |
enterpriseOid = MakeOIDFromDot(_ent.getPointer()); |
delete [] _ent; |
|
} | } |
} | } |
| |
char* _vbOid; |
|
char* _vbType; |
|
char* _vbValue; |
|
|
|
for(Uint32 i = 0; i < vbOids.size(); i++) | for(Uint32 i = 0; i < vbOids.size(); i++) |
{ | { |
_vbOid = vbOids[i].allocateCString(); |
ArrayDestroyer<char> _vbOid(vbOids[i].allocateCString()); |
_vbType = vbTypes[i].allocateCString(); |
ArrayDestroyer<char> _vbValue(vbValues[i].allocateCString()); |
_vbValue = vbValues[i].allocateCString(); |
|
| |
if ((object = MakeOIDFromDot(_vbOid)) == NULL) |
if ((object = MakeOIDFromDot(_vbOid.getPointer())) == NULL) |
{ | { |
cout << "Invalid OID received: " << vbOids[i] << endl; | cout << "Invalid OID received: " << vbOids[i] << endl; |
return; | return; |
} | } |
| |
if (strcmp(_vbType,"OctetString") == 0) |
if (vbTypes[i] == String("OctetString")) |
{ | { |
newValue = CloneOctetString(MakeOctetStringFromText(_vbValue)); |
newValue = CloneOctetString(MakeOctetStringFromText(_vbValue.getPointer())); |
if (newValue == NULL) | if (newValue == NULL) |
{ | { |
cout << "Invalid Value provided : " << vbValues[i] << endl; | cout << "Invalid Value provided : " << vbValues[i] << endl; |
|
|
} | } |
else | else |
{ | { |
newValue = CloneOctetString(MakeOctetString( |
int vbvalue = atoi(_vbValue.getPointer()); |
(unsigned char *) _vbValue, strlen(_vbValue))); |
void* value = &vbvalue; |
| |
if (newValue == NULL) | if (newValue == NULL) |
{ | { |
|
|
if ((vb2 = MakeVarBindWithValue(object, | if ((vb2 = MakeVarBindWithValue(object, |
(OID *) NULL, | (OID *) NULL, |
INTEGER_TYPE, | INTEGER_TYPE, |
newValue)) == NULL) |
value)) == NULL) |
{ | { |
cout << "Invalid Integer Value: " << vbValues[i] << endl; | cout << "Invalid Integer Value: " << vbValues[i] << endl; |
return; | return; |
|
|
FreeOID(object); | FreeOID(object); |
} | } |
| |
delete [] _vbType; |
|
delete [] _vbValue; |
|
delete [] _vbOid; |
|
|
|
vb3->next_var = NULL; | vb3->next_var = NULL; |
| |
// Now sending the trap | // Now sending the trap |
if (trapType == String("SNMPGeneric")) |
if (trapType == String("SNMPv1")) |
{ |
|
cout << genTrap << endl; |
|
cout << specTrap << endl; |
|
PrintVarBindList(vb); |
|
//PrintOID(enterpriseOid); |
|
cout << _trapOid << endl; |
|
cout << "Sending SNMP generic trap : " << trapOid << endl; |
|
|
|
do_trap(genTrap, specTrap, vb, enterpriseOid, _trapOid); |
|
|
|
FreeVarBindList(vb); |
|
FreeVarBindList(vb2); |
|
} |
|
else if (trapType == String("SNMPv1")) |
|
{ | { |
cout << "Sending SNMPv1 Trap : " << trapOid << endl; |
|
SendNotificationToDestSMIv1Params( | SendNotificationToDestSMIv1Params( |
1, // notifyType - TRAP | 1, // notifyType - TRAP |
genTrap, // genTrap | genTrap, // genTrap |
|
|
SR_SECURITY_MODEL_V1, // securityModel | SR_SECURITY_MODEL_V1, // securityModel |
&global_ti, // Transport Info | &global_ti, // Transport Info |
0); // cfg_chk | 0); // cfg_chk |
|
|
FreeVarBindList(vb); |
|
FreeVarBindList(vb2); |
|
} | } |
else if (trapType == String("SNMPv2")) | else if (trapType == String("SNMPv2")) |
{ | { |
cout << "Sending SNMPv2 Trap : " << trapOid << endl; |
|
SendNotificationToDestSMIv2Params( | SendNotificationToDestSMIv2Params( |
2, // notifyType - NOTIFICATION |
1, // notifyType - NOTIFICATION |
sendtrapOid, // snmpTrapOID | sendtrapOid, // snmpTrapOID |
agent_addr, // agent_addr | agent_addr, // agent_addr |
vb, // vb | vb, // vb |
|
|
else | else |
{ | { |
cout << "Trap type not supported : " << trapType << endl; | cout << "Trap type not supported : " << trapType << endl; |
delete [] _trapOid; |
|
exit(2); | exit(2); |
} | } |
| |
delete [] _trapOid; |
FreeVarBindList(vb); |
|
FreeVarBindList(vb2); |
|
FreeVarBindList(vb3); |
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |