📄 notifyreceive.cpp
字号:
/*============================================================================
Copyright (c) 1996
Hewlett-Packard Company
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
Permission to use, copy, modify, distribute and/or sell this software
and/or its documentation is hereby granted without fee. User agrees
to display the above copyright notice and this license notice in all
copies of the software and any documentation of the software. User
agrees to assume all liability for the use of the software; Hewlett-Packard
makes no representations about the suitability of this software for any
purpose. It is provided "AS-IS without warranty of any kind,either express
or implied. User hereby grants a royalty-free license to any and all
derivatives based upon this software code base.
=============================================================================*/
#include "stdafx.h"
#include "browser.h"
#include "NotifyReceive.h"
#include "NotifyFilter.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// NotifyReceive dialog
void my_trap_callback ( int reason,
Snmp* session, // session handle
Pdu & pdu, // trap pdu
SnmpTarget & target, // source of the trap
unsigned long callback_data) // optional callback data
{
NotifyReceive *me;
me = (NotifyReceive *) callback_data;
CTreeCtrl *tree;
tree = (CTreeCtrl *) me->GetDlgItem( IDC_NOTIFIES);
CString outbuff;
HTREEITEM new_node, vb_node;
Oid coldStart("1.3.6.1.6.3.1.1.5.1");
Oid warmStart("1.3.6.1.6.3.1.1.5.2");
Oid linkUp("1.3.6.1.6.3.1.1.5.4");
Oid linkDown("1.3.6.1.6.3.1.1.5.3");
Oid authenticationFailure("1.3.6.1.6.3.1.1.5.5");
Oid egpNeighborLoss("1.3.6.1.6.3.1.1.5.6");
// get the address
GenAddress genaddress;
target.get_address( genaddress);
// determine the type of trap
Oid trapid;
pdu.get_notify_id( trapid);
if ( trapid == coldStart)
outbuff = "ColdStart ";
else if ( trapid == warmStart)
outbuff = "WarmStart ";
else if ( trapid == linkUp)
outbuff = "LinkUp ";
else if ( trapid == linkDown)
outbuff = "LinkDown ";
else if ( trapid == authenticationFailure)
outbuff = "AuthFail ";
else if ( trapid == egpNeighborLoss)
outbuff = "EgpLoss ";
else
{
outbuff = "Enterprise Specific (";
outbuff += trapid.get_printable();
outbuff += ") ";
}
// display where the trap came from
outbuff += " From ";
outbuff += genaddress.get_printable();
new_node = tree->InsertItem( outbuff);
// show the timestamp
outbuff = "TimeStamp = ";
TimeTicks timestamp;
pdu.get_notify_timestamp( timestamp);
outbuff += timestamp.get_printable();
tree->InsertItem( outbuff, new_node);
// show the enterprise
outbuff = "Enterprise = ";
Oid enterprise;
pdu.get_notify_enterprise( enterprise);
outbuff += enterprise.get_printable();
// don't show if we don't have one
if ( enterprise != "0.0")
tree->InsertItem( outbuff, new_node);
// show all the vbs in the trap payload
if ( pdu.get_vb_count() >0)
{
outbuff = "Payload";
new_node = tree->InsertItem( outbuff, new_node);
}
char vbname[40];
Vb vb;
for (int x=0;x<pdu.get_vb_count();x++)
{
sprintf( vbname,"Variable Binding #%d",x+1);
vb_node = tree->InsertItem( vbname, new_node);
pdu.get_vb( vb,x);
outbuff = "Oid = ";
outbuff += vb.get_printable_oid();
tree->InsertItem(outbuff,vb_node);
outbuff = "Value = ";
outbuff += vb.get_printable_value();
tree->InsertItem( outbuff, vb_node);
}
};
NotifyReceive::NotifyReceive(CWnd* pParent /*=NULL*/)
: CDialog(NotifyReceive::IDD, pParent)
{
//{{AFX_DATA_INIT(NotifyReceive)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
int cstatus = Create(IDD, pParent);
// create a snmp++ object
int status;
TargetCollection targets; // empty get all from all targets
snmp = new Snmp( status);
if ( status != SNMP_CLASS_SUCCESS)
{
AfxMessageBox("Unable To Create Snmp Object!");
snmp = NULL;
}
// start out with all filters enabled
Oid coldStart("1.3.6.1.6.3.1.1.5.1");
my_filters += coldStart;
Oid warmStart("1.3.6.1.6.3.1.1.5.2");
my_filters += warmStart;
Oid linkUp("1.3.6.1.6.3.1.1.5.4");
my_filters += linkUp;
Oid linkDown("1.3.6.1.6.3.1.1.5.3");
my_filters += linkDown;
Oid authenticationFailure("1.3.6.1.6.3.1.1.5.5");
my_filters += authenticationFailure;
Oid egpNeighborLoss("1.3.6.1.6.3.1.1.5.6");
my_filters += egpNeighborLoss;
status = snmp->notify_register( my_filters,targets,
(snmp_callback) &my_trap_callback,
(void *) this);
if ( status != SNMP_CLASS_SUCCESS)
AfxMessageBox("Unable to Regsiter For Traps");
}
void NotifyReceive::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(NotifyReceive)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(NotifyReceive, CDialog)
//{{AFX_MSG_MAP(NotifyReceive)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
ON_BN_CLICKED(IDC_FILTERS, OnFilters)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// NotifyReceive message handlers
void NotifyReceive::OnClear()
{
// TODO: Add your control notification handler code here
// TODO: Add extra initialization here
CTreeCtrl *tree;
tree = (CTreeCtrl *) GetDlgItem( IDC_NOTIFIES);
tree->DeleteAllItems();
}
BOOL NotifyReceive::OnInitDialog()
{
CDialog::OnInitDialog();
// clear the tree control
OnClear();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void NotifyReceive::OnCancel()
{
// TODO: Add extra cleanup here
DestroyWindow();
}
void NotifyReceive::OnFilters()
{
// TODO: Add your control notification handler code here
NotifyFilter nf;
// assign the dialog class filters my_filters
nf.filters = my_filters;
// invoke as modal
nf.DoModal();
// get the filters back
my_filters = nf.filters;
// reset the snmp++ filtering
TargetCollection targets;
// use another temporary collection
// if all selected then use an empty set to denote all
int status = snmp->notify_register( my_filters,targets,
(snmp_callback) &my_trap_callback,
(void *) this);
if ( status != SNMP_CLASS_SUCCESS)
AfxMessageBox("Unable to Register For Traps");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -