Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 08-06-2004
Alessan Alessan is offline
Registrado
 
Registrado: jun 2004
Posts: 5
Poder: 0
Alessan Va por buen camino
Indy 9

Hola,

Tengo un problemilla con Indy 9, mas en concreto con el componente TidSNMP, puedo leer perfectamente cualquier OID, pero no soy capaz de modificar ningun valor.
Os dejo la función a ver si me podeis decir que es lo que está mal:

-----------------------------------------------------------------------
function TfrmMainSNMP.GetOID(OID: String; var Reply, Error: String): Boolean;
var
Tmp: String;

begin
Result := False;
try
if SNMP = Nil then begin
SNMP := TIdSNMP.Create(nil);
end;

if not LeerIni(RutaIni, 'HOST', 'Address', Tmp, '', Error) then begin
GrabarLog(RutaLog, Error, Error);
end;
IP := Tmp;

SNMP.Community := 'public';
SNMP.Host := IP;
SNMP.Query.Clear;
SNMP.Query.PDUType := PDUGetRequest;
SNMP.Query.MIBAdd(OID, '');

snmp.Active := True;
if not SNMP.SendQuery then begin
Error := 'Error al consultar OID(' + IntToStr(SNMP.Query.ErrorStatus) + '): ' + OID;
memo1.Lines.Add(Error);
end else begin
Reply := SNMP.Reply.Value[0];
memo1.Lines.Add(Trim(SNMP.Reply.MIBOID.Text) + ': ' + Trim(SNMP.Reply.MIBValue.Text));
end;
Result := True;
Except On E: Exception do begin
Error := 'Error en la función (TfrmMainTPVSNMP)ConsultarOID. ' + E.Message;
end;
end;
end;
------------------------------------------------------------------------
function TfrmMainSNMP.SetOID(OID: String; Value: String; var Error: String): Boolean;
var
Tmp: String;

begin
Result := False;
try
if SNMP = Nil then begin
SNMP := TIdSNMP.Create(nil);
end;

if not LeerIni(RutaIni, 'HOST', 'Address', Tmp, '', Error) then begin
GrabarLog(RutaLog, Error, Error);
end;
IP := Tmp;

SNMP.Community := 'public';
SNMP.Host := IP;
SNMP.Query.Clear;
SNMP.Query.MIBAdd(OID, Value);
SNMP.Query.PDUType := PDUSetRequest;
if not SNMP.SendQuery then begin
Error := 'Error al Escribir en OID: ' + OID + '(' + Value + ')';
end else begin
snmp.Reply.MIBGet(OID);
memo1.Lines.Add('OID ' + OID + ' = ' + Value + '.');
end;
Result := True;
Except On E: Exception do begin
Error := 'Error en la función (TfrmMainTPVSNMP)ConsultarOID. ' + E.Message;
end;
end;
end;
Responder Con Cita
  #2  
Antiguo 08-06-2004
Avatar de DarkByte
DarkByte DarkByte is offline
Miembro
 
Registrado: sep 2003
Ubicación: Desconocido
Posts: 1.322
Poder: 22
DarkByte Va por buen camino
Cita:
Empezado por Alessan
puedo leer perfectamente cualquier OID,
Si no es mucha molestia, ¿Qué es un OID?-

Intenta usar las etiquetas [ Delphi ] y [/ Delphi ] (sin espacios) cuanod vayas a utilizar código delphi

Ej:
Código Delphi [-]
function TfrmMainSNMP.GetOID(OID: String; var Reply, Error: String): Boolean;
var
  Tmp: String;

begin
  Result := False;
  try
      if SNMP = Nil then begin
          SNMP := TIdSNMP.Create(nil);
      end;

      if not LeerIni(RutaIni, 'HOST', 'Address', Tmp, '', Error) then begin
          GrabarLog(RutaLog, Error, Error);
      end;
      IP := Tmp;
      
      SNMP.Community := 'public';
      SNMP.Host := IP;
      SNMP.Query.Clear;
      SNMP.Query.PDUType := PDUGetRequest;
      SNMP.Query.MIBAdd(OID, '');

      snmp.Active := True;
      if not SNMP.SendQuery then begin
          Error := 'Error al consultar OID(' + IntToStr(SNMP.Query.ErrorStatus) + '): ' + OID;
          memo1.Lines.Add(Error);
        end else begin
          Reply := SNMP.Reply.Value[0];
          memo1.Lines.Add(Trim(SNMP.Reply.MIBOID.Text) + ': ' + Trim(SNMP.Reply.MIBValue.Text));
      end;
      Result := True;
  Except On E: Exception do begin
      Error := 'Error en la función (TfrmMainTPVSNMP)ConsultarOID. ' + E.Message;
  end;
  end;
end;


function TfrmMainSNMP.SetOID(OID: String; Value: String; var Error: String): Boolean;
var
  Tmp: String;

begin
  Result := False;
  try
      if SNMP = Nil then begin
          SNMP := TIdSNMP.Create(nil);
      end;

      if not LeerIni(RutaIni, 'HOST', 'Address', Tmp, '', Error) then begin
          GrabarLog(RutaLog, Error, Error);
      end;
      IP := Tmp;

      SNMP.Community := 'public';
      SNMP.Host := IP;
      SNMP.Query.Clear;
      SNMP.Query.MIBAdd(OID, Value);
      SNMP.Query.PDUType := PDUSetRequest;
      if not SNMP.SendQuery then begin
          Error := 'Error al Escribir en OID: ' + OID + '(' + Value + ')';
      end else begin
          snmp.Reply.MIBGet(OID);
          memo1.Lines.Add('OID ' + OID + ' = ' + Value + '.');
      end;
      Result := True;
  Except On E: Exception do begin
      Error := 'Error en la función (TfrmMainTPVSNMP)ConsultarOID. ' + E.Message;
  end;
  end;
end;
__________________
:)
Responder Con Cita
  #3  
Antiguo 08-06-2004
Alessan Alessan is offline
Registrado
 
Registrado: jun 2004
Posts: 5
Poder: 0
Alessan Va por buen camino
Hola,

OID = ObjectID, Identificardor de un MIB en consultas SNMP.
de todas maneras ya arregle las funciones. Ahora el problemas lo tengo con la captura de los SNMP TRAPS.

Si alguien sabe donde conseguir información sobre esto, por favor que me responda aqui o me mande un PM.

Gracias.

PD: po zi, es útil lo de [ Delphi] [ /Delphi] .
Responder Con Cita
  #4  
Antiguo 19-01-2007
GMV Man GMV Man is offline
Registrado
 
Registrado: ene 2007
Posts: 1
Poder: 0
GMV Man Va por buen camino
Smile La respuesta al problema

Aparentemente el código es correcto pero pero le falta un pequeño detalle. Como norma general debe indicarse el tipo de variable del que se va a hacer el "MIBSet". So esto no es así (como en los ejemplos anteriores) la variable por defecto a escribir será del tipo "Octeto" (ASN1_OCTSTR).
Para solucionar esto sugiero cambiar la función para indicar también el tipo de variable a escribir:

function TfrmMainSNMP.SetOID(OID: String; Value: String; var iType: Integer; var Error: String): Boolean;
var
Tmp: String;

begin
Result := False;
try
if SNMP = Nil then begin
SNMP := TIdSNMP.Create(nil);
end;

if not LeerIni(RutaIni, 'HOST', 'Address', Tmp, '', Error) then begin
GrabarLog(RutaLog, Error, Error);
end;
IP := Tmp;

SNMP.Community := 'public';
SNMP.Host := IP;
SNMP.Query.Clear;
SNMP.Query.MIBAdd(OID, Value, iType);
SNMP.Query.PDUType := PDUSetRequest;
if not SNMP.SendQuery then begin
Error := 'Error al Escribir en OID: ' + OID + '(' + Value + ')';
end else begin
snmp.Reply.MIBGet(OID);
memo1.Lines.Add('OID ' + OID + ' = ' + Value + '.');
end;
Result := True;
Except On E: Exception do begin
Error := 'Error en la función (TfrmMainTPVSNMP)ConsultarOID. ' + E.Message;
end;
end;
end;


A la variable iType podrá tener cualquiera de los valores siguientes:
ASN1_INT
ASN1_OCTSTR
ASN1_NULL
ASN1_OBJID
ASN1_SEQ
ASN1_IPADDR
ASN1_COUNTER
ASN1_GAUGE
ASN1_TIMETICKS
ASN1_OPAQUE

Aleeee.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 10:10:35.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi