version 1.4, 2002/03/21 23:00:08
|
version 1.5, 2002/03/27 21:27:35
|
|
|
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 |
|
char* _trapOid = trapOid.allocateCString(); |
|
OID *sendtrapOid = MakeOIDFromDot(_trapOid); |
|
|
|
// Destination : converting destination into Transport |
|
char* trap_dest = destination.allocateCString(); |
|
TransportInfo global_ti; |
|
global_ti.type = SR_IP_TRANSPORT; |
|
global_ti.t_ipAddr = inet_addr(trap_dest); |
|
global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort()); |
|
delete [] trap_dest; |
|
|
|
// Community Name |
|
char* _community = community.allocateCString(); |
|
OctetString* community_name = MakeOctetStringFromText(_community); |
|
delete [] _community; |
|
|
// getting IP address of the host | // getting IP address of the host |
char* hostname = System::getHostName().allocateCString(); | char* hostname = System::getHostName().allocateCString(); |
char **p; | char **p; |
|
|
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; |
// 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; |
|
|
// ATTN-NU-20020312 : Write code to get enterprise, genTrap and | // ATTN-NU-20020312 : Write code to get enterprise, genTrap and |
// specTrap from trapOid. | // specTrap from trapOid. |
| |
String enterprise; |
//NU_SNMP |
|
|
|
SR_INT32 genTrap = 0; |
|
SR_INT32 specTrap = 0; |
|
|
|
OID* enterpriseOid ; |
|
|
|
Array<String> standard_traps; |
|
|
|
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")); |
|
|
|
Array<String> oids; |
|
String tmpoid = trapOid; |
|
|
|
while(tmpoid.find(".") != PEG_NOT_FOUND) |
|
{ |
|
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]; |
|
} |
| |
OID* enterpriseOid = MakeOIDFromDot(enterprise.allocateCString()); |
if (Contains(standard_traps, trapOid)) |
|
{ |
|
ent = oids[0]; |
|
for (Uint8 i = 1; i < oids.size()-1; i++) |
|
ent = ent + "." + oids[i]; |
| |
// getting trap data for do_trap() |
char* gtrap = ent.allocateCString(); |
entV2Trap = trapOid.allocateCString(); |
genTrap = atoi(gtrap) - 1; |
|
enterpriseOid = sendtrapOid; |
|
delete [] gtrap; |
|
} |
|
else |
|
{ |
|
genTrap = 6; |
| |
// getting trapOid |
ent = oids[0]; |
OID *sendtrapOid = MakeOIDFromDot(trapOid.allocateCString()); |
for (Uint8 i = 1; i < oids.size()-1; i++) |
|
ent = ent + "." + oids[i]; |
|
char* strap = oids[oids.size()-1].allocateCString(); |
|
specTrap = atoi(strap); |
|
delete [] strap; |
|
|
|
if (oids[oids.size()-2] == "0") |
|
{ |
|
ent = oids[0]; |
|
for (Uint8 i = 1; i < oids.size()-2; i++) |
|
ent = ent + "." + oids[i]; |
|
|
|
char* _ent = ent.allocateCString(); |
|
enterpriseOid = MakeOIDFromDot(_ent); |
|
delete [] _ent; |
|
} |
|
else |
|
{ |
|
ent = oids[0]; |
|
for (Uint8 i = 1; i < oids.size()-1; i++) |
|
ent = ent + "." + oids[i]; |
|
|
|
char* _ent = ent.allocateCString(); |
|
enterpriseOid = MakeOIDFromDot(_ent); |
|
delete [] _ent; |
|
} |
|
} |
|
|
|
char* _vbOid; |
|
char* _vbType; |
|
char* _vbValue; |
| |
for(Uint32 i = 0; i < vbOids.size(); i++) | for(Uint32 i = 0; i < vbOids.size(); i++) |
{ | { |
if ((object = MakeOIDFromDot(vbOids[i].allocateCString())) == NULL) |
_vbOid = vbOids[i].allocateCString(); |
|
_vbType = vbTypes[i].allocateCString(); |
|
_vbValue = vbValues[i].allocateCString(); |
|
|
|
if ((object = MakeOIDFromDot(_vbOid)) == 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 (strcmp(_vbType,"OctetString") == 0) |
{ | { |
newValue = CloneOctetString(MakeOctetStringFromText |
newValue = CloneOctetString(MakeOctetStringFromText(_vbValue)); |
(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( | newValue = CloneOctetString(MakeOctetString( |
(unsigned char *) vbValues[i].allocateCString(), |
(unsigned char *) _vbValue, strlen(_vbValue))); |
strlen(vbValues[i].allocateCString()))); |
|
| |
if (newValue == NULL) | if (newValue == NULL) |
{ | { |
|
|
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("SNMPGeneric")) |
{ | { |
do_trap(6, 4, vb2, enterpriseOid, entV2Trap); |
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(vb); |
FreeVarBindList(vb2); | FreeVarBindList(vb2); |
} | } |
|
|
{ | { |
cout << "Sending SNMPv1 Trap : " << trapOid << endl; | 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 |
|
|
{ | { |
cout << "Sending SNMPv2 Trap : " << trapOid << endl; | cout << "Sending SNMPv2 Trap : " << trapOid << endl; |
SendNotificationToDestSMIv2Params( | SendNotificationToDestSMIv2Params( |
1, // notifyType |
2, // 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 |
|
|
else | else |
{ | { |
cout << "Trap type not supported : " << trapType << endl; | cout << "Trap type not supported : " << trapType << endl; |
|
delete [] _trapOid; |
exit(2); | exit(2); |
} | } |
|
|
|
delete [] _trapOid; |
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |