Реализация SharpSNMP на основе примера snmptrad перестает работатьC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Реализация SharpSNMP на основе примера snmptrad перестает работать

Сообщение Anonymous »

Я создаю прототип приложения на основе примера, включенного в библиотеку Sharp-SNMP (snmptrapd), чтобы получить некоторые данные из протокола SNMP, но он вообще перестал работать по неизвестной причине, перестал работать, но не выдает никаких исключений. , хорошо компилируется и выполняется.

проблема в том, что события никогда не возникают.

Зависимости:
  • Контейнер Unity от Microsoft
  • Библиотека SharpSNMP
  • SourceGrid (Windows.Forms)
Я должен был отметить, что еще 2 дня назад работал как часы, но теперь у меня заканчивается идей. (и я не менял ничего радикального в своем коде).

Код C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using Lextm.SharpSnmpLib;
using Lextm.SharpSnmpLib.Security;
using Lextm.SharpSnmpLib.Messaging;
using Lextm.SharpSnmpLib.Pipeline;
using Lextm.SharpSnmpLib.Mib;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using Microsoft.Practices.Unity.Utility;
using System.Configuration;
using SourceGrid;

namespace Kraken
{
public partial class frmConsola : Form
{
internal static IUnityContainer Container { get; private set; }
private SnmpEngine engine;

// Delegates ....
private delegate void MostrarMensajeDelegate(SourceGrid.Grid oGrd, DateTime eventTime, String eventType, IPAddress agentAddress, String Elemento, String Valor);

public frmConsola()
{
InitializeComponent();
this.crear_demonio_trampas();
this.crear_grid();
}

private void crear_grid()
{
grdData.BorderStyle = BorderStyle.FixedSingle;

grdData.ColumnsCount = 6;
grdData.FixedRows = 1;
grdData.Rows.Insert(0);

grdData[0, 0] = new SourceGrid.Cells.ColumnHeader("Id");
grdData[0, 1] = new SourceGrid.Cells.ColumnHeader("Hora");
grdData[0, 2] = new SourceGrid.Cells.ColumnHeader("Tipo");
grdData[0, 3] = new SourceGrid.Cells.ColumnHeader("Agente");
grdData[0, 4] = new SourceGrid.Cells.ColumnHeader("Elemento");
grdData[0, 5] = new SourceGrid.Cells.ColumnHeader("Valor");
grdData.AutoSizeCells();
}

public void MostrarMensaje(SourceGrid.Grid oGrd, DateTime eventTime, String eventType, IPAddress agentAddress, String Elemento, String Valor)
{
int r = 0;
if (!oGrd.IsDisposed)
{
r = oGrd.Rows.Count;
oGrd.Rows.Insert(r);
oGrd[r, 0] = new SourceGrid.Cells.Cell(r.ToString(), typeof(string));
oGrd[r, 1] = new SourceGrid.Cells.Cell("?", typeof(string));
oGrd[r, 2] = new SourceGrid.Cells.Cell(eventType, typeof(string));
oGrd[r, 3] = new SourceGrid.Cells.Cell(agentAddress.ToString(), typeof(string));
oGrd[r, 4] = new SourceGrid.Cells.Cell(Elemento, typeof(string));
oGrd[r, 5] = new SourceGrid.Cells.Cell(Valor, typeof(string));
grdData.AutoSizeCells();
}
else
{
throw (new ObjectDisposedException(oGrd.Name.ToString()));
}
}

private void crear_demonio_trampas()
{
Container = new UnityContainer().LoadConfiguration("snmptrapd");
var users = Container.Resolve();
users.Add(new OctetString("neither"), DefaultPrivacyProvider.DefaultPair);
users.Add(new OctetString("authen"), new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("authentication"))));
users.Add(new OctetString("privacy"), new DESPrivacyProvider(new OctetString("privacyphrase"),
new MD5AuthenticationProvider(new OctetString("authentication"))));
// -------------- Plantas de fuerza ----------------------
users.Add(new OctetString("PCC"), DefaultPrivacyProvider.DefaultPair);
users.Add(new OctetString("peacct"), DefaultPrivacyProvider.DefaultPair);
// -------------------------------------------------------
var trapv1 = Container.Resolve("TrapV1Handler");
trapv1.MessageReceived += WatcherTrapV1Received;
var trapv2 = Container.Resolve("TrapV2Handler");
trapv2.MessageReceived += WatcherTrapV2Received;
var inform = Container.Resolve("InformHandler");
inform.MessageReceived += WatcherInformRequestReceived;
this.engine = Container.Resolve();
}

private void WatcherInformRequestReceived(object sender, InformRequestMessageReceivedEventArgs e)
{
string sTipo = "";
uint[] codigo;
Object[] oParams = new Object[6];
oParams[0] = this.grdData;
oParams[1] = new DateTime(e.InformRequestMessage.TimeStamp);
codigo = e.InformRequestMessage.Enterprise.ToNumerical();
foreach (int num in codigo)
{
if (sTipo != null)
sTipo += ".";
sTipo += num.ToString();
}
oParams[2] = sTipo;
oParams[3] = null;
oParams[4] = e.InformRequestMessage.Variables()[0].ToString();
oParams[5] = "";
BeginInvoke(new MostrarMensajeDelegate(MostrarMensaje), oParams);
}

private void WatcherTrapV2Received(object sender, TrapV2MessageReceivedEventArgs e)
{
string sTipo = "";
uint[] codigo;
Object[] oParams = new Object[6];
oParams[0] = this.grdData;
oParams[1] = new DateTime(e.TrapV2Message.TimeStamp);
codigo = e.TrapV2Message.Enterprise.ToNumerical();
foreach (int num in codigo)
{
if (sTipo != null)
sTipo += ".";
sTipo += num.ToString();
}
oParams[2] = sTipo;
oParams[3] = null;
oParams[4] = e.TrapV2Message.Variables()[0].Id.ToString();
oParams[5] = e.TrapV2Message.Variables()[0].Data.ToString();
BeginInvoke(new MostrarMensajeDelegate(MostrarMensaje), oParams);
}

private void WatcherTrapV1Received(object sender, TrapV1MessageReceivedEventArgs e)
{
string sTipo = "";
uint[] codigo;
Object[] oParams = new Object[6];
oParams[0] = this.grdData;
oParams[1] = new DateTime(e.TrapV1Message.TimeStamp);
codigo = e.TrapV1Message.Enterprise.ToNumerical();
foreach (int num in codigo)
{
if (sTipo != null)
sTipo += ".";
sTipo += num.ToString();
}
oParams[2] = sTipo;
oParams[3] = e.TrapV1Message.AgentAddress;
oParams[4] = e.TrapV1Message.Variables()[0].Id.ToString();
oParams[5] = e.TrapV1Message.Variables()[0].Data.ToString();
//DateTime eventTime, String eventType, IPAddress agentAddress, String infoText
BeginInvoke(new MostrarMensajeDelegate(MostrarMensaje), oParams);
}

private void Form1_Shown(object sender, EventArgs e)
{
this.engine.Listener.AddBinding(new IPEndPoint(IPAddress.Any, 162));
this.engine.Start();
this.txtStatus.Text = "Iniciando Captura ...";
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
this.engine.Stop();
this.txtStatus.Text = "... Finalizando Captura.";
}

}
}


App.Config



































































































































































Подробнее здесь: https://stackoverflow.com/questions/142 ... op-working
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»