version 1.4, 2002/03/21 23:00:08
|
version 1.10, 2002/06/01 00:57:11
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001 BMC Software, Hewlett Packard, IBM, The Open Group, |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
// Tivoli Systems |
// The Open Group, Tivoli Systems |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
| |
#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> |
|
|
#include "snmpDeliverTrap_emanate.h" | #include "snmpDeliverTrap_emanate.h" |
#include "prnt_lib.h" | #include "prnt_lib.h" |
| |
PEGASUS_NAMESPACE_BEGIN |
|
|
|
PEGASUS_USING_STD; |
|
|
|
static char *sr_filename = __FILE__; | static char *sr_filename = __FILE__; |
| |
IPCFunctionP IPCfp; /* IPC functions pointer */ | IPCFunctionP IPCfp; /* IPC functions pointer */ |
|
|
return 1; | return 1; |
} | } |
| |
|
PEGASUS_NAMESPACE_BEGIN |
|
|
|
PEGASUS_USING_STD; |
|
|
snmpDeliverTrap_emanate::snmpDeliverTrap_emanate() | snmpDeliverTrap_emanate::snmpDeliverTrap_emanate() |
{ | { |
| |
|
|
Array<String>& vbTypes, | Array<String>& vbTypes, |
Array<String>& vbValues) | Array<String>& vbValues) |
{ | { |
initialize(); |
|
|
|
//void* newValue; |
|
OctetString* newValue; | OctetString* newValue; |
char* entV2Trap; |
|
int vb_link_flag = 0; |
|
| |
VarBind *vb = NULL; | VarBind *vb = NULL; |
VarBind *vb2 = NULL; | VarBind *vb2 = NULL; |
|
|
| |
OID *object = NULL; | OID *object = NULL; |
| |
|
// Initializing with Master agent |
|
initialize(); |
|
|
|
// TRAP OID: getting trapOid |
|
ArrayDestroyer<char> _trapOid(trapOid.allocateCString()); |
|
_trapOid.getPointer()[strlen(_trapOid.getPointer())-1] = '\0'; |
|
OID *sendtrapOid = MakeOIDFromDot(_trapOid.getPointer()); |
|
|
|
// Destination : converting destination into Transport |
|
ArrayDestroyer<char> trap_dest(destination.allocateCString()); |
|
TransportInfo global_ti; |
|
global_ti.type = SR_IP_TRANSPORT; |
|
global_ti.t_ipAddr = inet_addr(trap_dest.getPointer()); |
|
global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort()); |
|
|
|
// Community Name |
|
ArrayDestroyer<char> _community(community.allocateCString()); |
|
OctetString* community_name = MakeOctetStringFromText( |
|
_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); |
| |
// converting destination into Transport |
|
TransportInfo global_ti; |
|
global_ti.type = SR_IP_TRANSPORT; |
|
// address to which to send trap |
|
global_ti.t_ipAddr = inet_addr(destination.allocateCString()); |
|
// port to which to send trap |
|
global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort()); |
|
|
|
// 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. |
|
SR_INT32 genTrap = 0; |
|
SR_INT32 specTrap = 0; |
|
|
|
OID* enterpriseOid ; |
| |
String enterprise; |
Array<String> standard_traps; |
| |
OID* enterpriseOid = MakeOIDFromDot(enterprise.allocateCString()); |
standard_traps.append(String("1.3.6.1.6.3.1.1.5.1")); |
|
standard_traps.append(String("1.3.6.1.6.3.1.1.5.2")); |
|
standard_traps.append(String("1.3.6.1.6.3.1.1.5.3")); |
|
standard_traps.append(String("1.3.6.1.6.3.1.1.5.4")); |
|
standard_traps.append(String("1.3.6.1.6.3.1.1.5.5")); |
|
standard_traps.append(String("1.3.6.1.6.3.1.1.5.6")); |
| |
// getting trap data for do_trap() |
Array<String> oids; |
entV2Trap = trapOid.allocateCString(); |
String tmpoid = trapOid; |
| |
// getting trapOid |
while(tmpoid.find(".") != PEG_NOT_FOUND) |
OID *sendtrapOid = MakeOIDFromDot(trapOid.allocateCString()); |
{ |
|
oids.append(tmpoid.subString(0, tmpoid.find("."))); |
|
tmpoid = tmpoid.subString(tmpoid.find(".") + 1); |
|
} |
|
oids.append(tmpoid); |
|
|
|
String ent; |
|
if (oids[oids.size()-2] == "0") |
|
{ |
|
ent = oids[0]; |
|
for (Uint8 i = 1; i < oids.size()-2; i++) |
|
ent = ent + "." + oids[i]; |
|
} |
|
|
|
if (Contains(standard_traps, trapOid)) |
|
{ |
|
ent = oids[0]; |
|
for (Uint8 i = 1; i < oids.size()-1; i++) |
|
ent = ent + "." + oids[i]; |
|
|
|
ArrayDestroyer<char> gtrap(ent.allocateCString()); |
|
genTrap = atoi(gtrap.getPointer()) - 1; |
|
enterpriseOid = sendtrapOid; |
|
} |
|
else |
|
{ |
|
genTrap = 6; |
|
|
|
ent = oids[0]; |
|
for (Uint8 i = 1; i < oids.size()-1; i++) |
|
ent = ent + "." + oids[i]; |
|
ArrayDestroyer<char> strap(oids[oids.size()-1].allocateCString()); |
|
specTrap = atoi(strap.getPointer()); |
|
|
|
if (oids[oids.size()-2] == "0") |
|
{ |
|
ent = oids[0]; |
|
for (Uint8 i = 1; i < oids.size()-2; i++) |
|
ent = ent + "." + oids[i]; |
|
|
|
ArrayDestroyer<char> _ent(ent.allocateCString()); |
|
enterpriseOid = MakeOIDFromDot(_ent.getPointer()); |
|
} |
|
else |
|
{ |
|
ent = oids[0]; |
|
for (Uint8 i = 1; i < oids.size()-1; i++) |
|
ent = ent + "." + oids[i]; |
|
|
|
ArrayDestroyer<char> _ent(ent.allocateCString()); |
|
enterpriseOid = MakeOIDFromDot(_ent.getPointer()); |
|
} |
|
} |
| |
for(Uint32 i = 0; i < vbOids.size(); i++) | for(Uint32 i = 0; i < vbOids.size(); i++) |
{ | { |
if ((object = MakeOIDFromDot(vbOids[i].allocateCString())) == NULL) |
ArrayDestroyer<char> _vbOid(vbOids[i].allocateCString()); |
|
ArrayDestroyer<char> _vbValue(vbValues[i].allocateCString()); |
|
|
|
if ((object = MakeOIDFromDot(_vbOid.getPointer())) == NULL) |
{ | { |
cout << "Invalid OID received: " << vbOids[i] << endl; | cout << "Invalid OID received: " << vbOids[i] << endl; |
return; | return; |
} | } |
| |
if (strcmp(vbTypes[i].allocateCString(),"OctetString") == 0) |
if (vbTypes[i] == String("OctetString")) |
{ | { |
newValue = CloneOctetString(MakeOctetStringFromText |
newValue = CloneOctetString(MakeOctetStringFromText(_vbValue.getPointer())); |
(vbValues[i].allocateCString())); |
|
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 *) vbValues[i].allocateCString(), |
void* value = &vbvalue; |
strlen(vbValues[i].allocateCString()))); |
|
| |
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; |
|
|
vb3->next_var = NULL; | vb3->next_var = NULL; |
| |
// Now sending the trap | // Now sending the trap |
if (trapType == String("SNMPGeneric")) |
if (trapType == String("SNMPv1")) |
{ | { |
do_trap(6, 4, vb2, enterpriseOid, entV2Trap); |
|
FreeVarBindList(vb); |
|
FreeVarBindList(vb2); |
|
} |
|
else if (trapType == String("SNMPv1")) |
|
{ |
|
cout << "Sending SNMPv1 Trap : " << trapOid << endl; |
|
SendNotificationToDestSMIv1Params( | SendNotificationToDestSMIv1Params( |
1, // notifyType |
1, // notifyType - TRAP |
6, // genTrap |
genTrap, // genTrap |
1, // specTrap |
specTrap, // specTrap |
enterpriseOid, // enterprise | enterpriseOid, // enterprise |
agent_addr, // agent_addr | agent_addr, // agent_addr |
vb2, // vb |
vb, // vb |
NULL, // contextName | NULL, // contextName |
1, // retryCount | 1, // retryCount |
1, // timeout | 1, // timeout |
MakeOctetStringFromText(community.allocateCString()), // securityName, |
community_name, // securityName, |
SR_SECURITY_LEVEL_NOAUTH, // securityLevel | SR_SECURITY_LEVEL_NOAUTH, // securityLevel |
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( |
1, // notifyType |
1, // notifyType - NOTIFICATION |
sendtrapOid, // snmpTrapOID | sendtrapOid, // snmpTrapOID |
agent_addr, // agent_addr | agent_addr, // agent_addr |
//vb2, // vb |
|
vb, // vb | vb, // vb |
NULL, // contextName | NULL, // contextName |
1, // retryCount | 1, // retryCount |
100, // timeout | 100, // timeout |
MakeOctetStringFromText(community.allocateCString()), // securityName or community |
community_name, // securityName or community |
SR_SECURITY_LEVEL_NOAUTH, // securityLevel | SR_SECURITY_LEVEL_NOAUTH, // securityLevel |
SR_SECURITY_MODEL_V1, // securityModel | SR_SECURITY_MODEL_V1, // securityModel |
&global_ti, // TransportInfo | &global_ti, // TransportInfo |
|
|
cout << "Trap type not supported : " << trapType << endl; | cout << "Trap type not supported : " << trapType << endl; |
exit(2); | exit(2); |
} | } |
|
|
|
FreeVarBindList(vb); |
|
FreeVarBindList(vb2); |
|
FreeVarBindList(vb3); |
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |