⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmpdelivertrap_emanate.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/System.h>#include <Pegasus/Common/ArrayInternal.h>#include <Pegasus/Common/InternalException.h>#include "snmpDeliverTrap_emanate.h"#include <Pegasus/Common/MessageLoader.h>// EMANATE specific declarations and entry points - MUST be in begining// and outside NAMESPACE.// master agent needs these two declarations for communication with sub-agent.// Following two declarations must be in the CODE.#include <prnt_lib.h>  // MUST be at the end in include list.static const char* sr_filename = __FILE__;IPCFunctionP IPCfp;  /* IPC functions pointer */// This code would normally be generated by Emanate from defined MIB objects.// Since we do not have MIB objects defined, just defined here to load// subagent as library. OidList[] provides objects for entry point to master// agent.// The objects internal to the agentObjectInfo OidList[] ={    {        { 0, NULL },#ifndef LIGHT        NULL,#endif /* LIGHT */        0, 0, 0, 0,        NULL, NULL    }};// This code would normally be generated by Emanate in k_* routine from// defined MIB objects.  Since we do not have MIB objects defined, just// define here to pass compile and enable entry point for master agent to// start communication with library.// Called by the master agent during initialization */int k_initialize(){    return 1;}// END EMANATE specific declarations.PEGASUS_NAMESPACE_BEGINPEGASUS_USING_STD;snmpDeliverTrap_emanate::snmpDeliverTrap_emanate(){}snmpDeliverTrap_emanate::~snmpDeliverTrap_emanate(){}// initialize sub-agent// This also defines the communication protocol to be used between master// and sub-agent.void snmpDeliverTrap_emanate::initialize(){#ifndef SR_UDS_IPC    InitIPCArrayTCP(&IPCfp);#else /* SR_UDS_IPC */    InitIPCArrayUDS(&IPCfp);#endif /* SR_UDS_IPC */    if (InitSubagent() == -1)    {        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(            _MSG_INITSUBAGENT_FAILED_KEY,            _MSG_INITSUBAGENT_FAILED));    }}void snmpDeliverTrap_emanate::terminate(){    //    // Close the connection to the Master Agent and shut down the    // Subagent    //    EndSubagent();}void snmpDeliverTrap_emanate::deliverTrap(        const String& trapOid,        const String& securityName,        const String& targetHost,        const Uint16& targetHostFormat,        const String& otherTargetHostFormat,        const Uint32& portNumber,        const Uint16& snmpVersion,        const String& engineID,        const Array<String>& vbOids,        const Array<String>& vbTypes,        const Array<String>& vbValues){    VarBind* vbhead = NULL;    VarBind* vb = NULL;    VarBind* vblast = NULL;    OID* object = NULL;    // Translate a string into an OID    OID* sendtrapOid = MakeOIDFromDot(trapOid.getCString());    if (sendtrapOid == NULL)    {        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(            _MSG_INVALID_KEY,            _MSG_INVALID_TRAPOID));    }    // Destination : convert targetHost into Transport    CString trap_dest = targetHost.getCString();    TransportInfo global_ti;    global_ti.type = SR_IP_TRANSPORT;    switch (targetHostFormat)    {        case _HOST_NAME:        {            char* ipAddr = _getIPAddress(trap_dest);            if (ipAddr == NULL)            {                throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,                    MessageLoaderParms(                       _MSG_DESTINATION_NOT_FOUND_KEY,                       _MSG_DESTINATION_NOT_FOUND));            }            global_ti.t_ipAddr = inet_addr(trap_dest);            break;        }        case _IPV4_ADDRESS:        {            global_ti.t_ipAddr = inet_addr(trap_dest);            break;        }        default:        {            throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED,                MessageLoaderParms(                    _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED_KEY,                    _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED));            break;        }    }    global_ti.t_ipPort = htons((unsigned short)portNumber);    // Community Name, default is public    CString _community;    if (securityName.size() == 0)    {        String community;        community.assign("public");        _community = community.getCString();    }    else    {        _community = securityName.getCString();    }    OctetString* community_name = MakeOctetStringFromText(_community);    if (community_name == NULL)    {        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(            _MSG_INVALID_SECURITY_NAME_KEY,            _MSG_INVALID_SECURITY_NAME));    }    // getting IP address of the host    CString hostname = System::getHostName().getCString();    char* IP_string = _getIPAddress(hostname);    // formatting agent(host) address into OctetString format    OctetString* agent_addr;    SR_INT32 s1, s2, s3, s4;    SR_UINT32 ipaddr;    // pull out each of the 4 octet values from IP address    sscanf(IP_string,"%d.%d.%d.%d", &s1, &s2, &s3, &s4);    // validate the values for s1, s2, s3, and s4 to make sure values are    // between 0 and 255    if (!_isValidOctet(s1) || !_isValidOctet(s2) ||        !_isValidOctet(s3) || !_isValidOctet(s4))    {        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(            _MSG_INVALID_OCTET_VALUE_KEY,            _MSG_INVALID_OCTET_VALUE));    }    // create an empty 4 length OctetString    agent_addr = MakeOctetString(NULL,4);    if (agent_addr == NULL)    {        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(            _MSG_CREATE_OCTET_FAILED_KEY,            _MSG_CREATE_OCTET_FAILED));    }    // fill in values for OctetString    agent_addr->octet_ptr[0] = (unsigned char)s1;    agent_addr->octet_ptr[1] = (unsigned char)s2;    agent_addr->octet_ptr[2] = (unsigned char)s3;    agent_addr->octet_ptr[3] = (unsigned char)s4;    // specTrap from trapOid.    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);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -