📄 idsnmp.pas
字号:
Self.ID:=StrToIntDef(ASNItem(Pos,buffer,vt),0);
Self.ErrorStatus:=StrToIntDef(ASNItem(Pos,buffer,vt),0);
Self.ErrorIndex:=StrToIntDef(ASNItem(Pos,buffer,vt),0);
ASNItem(Pos,buffer,vt);
while Pos<Endpos do // Decode MIB/Value pairs
begin
ASNItem(Pos,buffer,vt);
Sm:=ASNItem(Pos,buffer,vt);
Sv:=ASNItem(Pos,buffer,vt);
MIBadd(sm,sv, vt);
end;
end;
(*----------------------------------------------------------------------------*
| function TSNMPInfo.EncodeBuf |
| |
| Encode the details into an ASN string |
| |
| The function returns the encoded ASN string |
*----------------------------------------------------------------------------*)
function TSNMPInfo.EncodeBuf:string;
var
data,s:string;
n:integer;
objType:Integer;
begin
data:=''; {Do not Localize}
SyncMIB;
for n:=0 to Self.MIBOID.Count-1 do
begin
objType := Integer (Self.MIBValue.Objects[n]);
if objType = 0 then
objType := ASN1_OCTSTR;
case objType of
ASN1_INT:
s := ASNObject(MibToID(Self.MIBOID[n]), ASN1_OBJID) +
ASNObject(ASNEncInt(StrToIntDef(Self.MIBValue[n], 0)), objType);
ASN1_COUNTER, ASN1_GAUGE, ASN1_TIMETICKS:
s := ASNObject(MibToID(Self.MIBOID[n]), ASN1_OBJID) +
ASNObject(ASNEncUInt(StrToIntDef(Self.MIBValue[n], 0)), objType);
ASN1_OBJID:
s := ASNObject(MibToID(Self.MIBOID[n]), ASN1_OBJID) +
ASNObject(MibToID(Self.MIBValue[n]), objType);
ASN1_IPADDR:
s := ASNObject(MibToID(Self.MIBOID[n]), ASN1_OBJID) +
ASNObject(IPToID(Self.MIBValue[n]), objType);
ASN1_NULL:
s := ASNObject(MibToID(Self.MIBOID[n]), ASN1_OBJID) +
ASNObject('', ASN1_NULL); {Do not Localize}
else
s := ASNObject(MibToID(Self.MIBOID[n]), ASN1_OBJID) +
ASNObject(Self.MIBValue[n], objType);
end;
data:=data+ASNObject(s,$30);
end;
data:=ASNObject(data,$30);
data:=ASNObject(char(Self.ID),2)+ASNObject(char(Self.ErrorStatus),2)
+ASNObject(char(Self.ErrorIndex),2)+data;
data:=ASNObject(char(Self.Version),2)+ASNObject(Self.community,4)+ASNObject(data,Self.PDUType);
data:=ASNObject(data,$30);
Result:=data;
end;
(*----------------------------------------------------------------------------*
| procedure TSNMPInfo.Clear |
| |
| Clear the header info and MIBOID/Value lists. |
*----------------------------------------------------------------------------*)
procedure TSNMPInfo.Clear;
begin
version:=0;
fCommunity:=Owner.Community;
if Self = fOwner.Trap then
Port := Owner.TrapPort
else
Port := Owner.Port;
Host := Owner.Host;
PDUType:=0;
ID:=0;
ErrorStatus:=0;
ErrorIndex:=0;
MIBOID.Clear;
MIBValue.Clear;
end;
(*----------------------------------------------------------------------------*
| procedure TSNMPInfo.MIBAdd |
| |
| Add a MIBOID/Value pair |
| |
| Parameters: |
| MIB : string The MIBOID to add |
| Value : string The Value |
| valueType : Integer The Value's type. Optional - defaults to | {Do not Localize}
| ASN1_OCTSTR |
*----------------------------------------------------------------------------*)
procedure TSNMPInfo.MIBAdd(MIB,Value:string; valueType : Integer);
var
x:integer;
begin
SyncMIB;
MIBOID.Add (MIB);
x:=MIBOID.Count;
if MIBValue.Count>x then
begin
MIBvalue[x-1]:=Value;
MibValue.Objects [x-1] := TObject (valueType)
end
else MIBValue.AddObject(Value, TObject (valueType));
end;
(*----------------------------------------------------------------------------*
| procedure TSNMPInfo.MIBDelete |
| |
| Delete a MIBOID/Value pair |
| |
| Parameters: |
| Index:integer The index of the pair to delete |
*----------------------------------------------------------------------------*)
procedure TSNMPInfo.MIBDelete(Index:integer);
begin
SyncMIB;
MIBOID.Delete(Index);
if (MIBValue.Count-1)>= Index then MIBValue.Delete(Index);
end;
(*----------------------------------------------------------------------------*
| function TSNMPInfo.MIBGet |
| |
| Get a string representation of tha value of the specified MIBOID |
| |
| Parameters: |
| MIB:string The MIBOID to query |
| |
| The function returns the string representation of the value. |
*----------------------------------------------------------------------------*)
function TSNMPInfo.MIBGet(MIB:string):string;
var
x:integer;
begin
SyncMIB;
x:=MIBOID.IndexOf(MIB);
if x<0 then Result:='' {Do not Localize}
else Result:=MIBValue[x];
end;
{======================= TRAPS =====================================}
(*----------------------------------------------------------------------------*
| procedure TSNMPInfo.EncodeTrap |
| |
| Encode the trap details into an ASN string - the 'Buffer' member | {Do not Localize}
| |
| The function returns 1 for historical reasons! |
*----------------------------------------------------------------------------*)
function TSNMPInfo.EncodeTrap: integer;
var
s: string;
n: integer;
begin
Buffer := ''; {Do not Localize}
for n:=0 to MIBOID.Count-1 do
begin
s := ASNObject(MibToID(MIBOID[n]), ASN1_OBJID)
+ ASNObject(MIBValue[n], ASN1_OCTSTR);
Buffer := Buffer + ASNObject(s, ASN1_SEQ);
end;
Buffer := ASNObject(Buffer, ASN1_SEQ);
Buffer := ASNObject(ASNEncInt(GenTrap), ASN1_INT)
+ ASNObject(ASNEncInt(SpecTrap), ASN1_INT)
+ ASNObject(ASNEncInt(TimeTicks), ASN1_TIMETICKS) + Buffer;
Buffer := ASNObject(MibToID(Enterprise), ASN1_OBJID)
+ ASNObject(IPToID(Host), ASN1_IPADDR) + Buffer;
Buffer := ASNObject(Char(Version), ASN1_INT)
+ ASNObject(Community, ASN1_OCTSTR) + ASNObject(Buffer, Self.PDUType);
Buffer := ASNObject(Buffer, ASN1_SEQ);
Result := 1;
end;
(*----------------------------------------------------------------------------*
| procedure TSNMPInfo.DecodeTrap |
| |
| Decode the 'Buffer' trap string to fil in our member variables. | {Do not Localize}
| |
| The function returns 1. |
*----------------------------------------------------------------------------*)
function TSNMPInfo.DecodeTrap: integer;
var
Pos, EndPos, vt: integer;
Sm, Sv: string;
begin
Pos := 2;
EndPos := ASNDecLen(Pos, Buffer);
Version := StrToIntDef(ASNItem(Pos, Buffer,vt), 0);
Community := ASNItem(Pos, Buffer,vt);
PDUType := StrToIntDef(ASNItem(Pos, Buffer,vt), PDUTRAP);
Enterprise := IdToMIB(ASNItem(Pos, Buffer,vt));
Host := ASNItem(Pos, Buffer,vt);
GenTrap := StrToIntDef(ASNItem(Pos, Buffer,vt), 0);
Spectrap := StrToIntDef(ASNItem(Pos, Buffer,vt), 0);
TimeTicks := StrToIntDef(ASNItem(Pos, Buffer,vt), 0);
ASNItem(Pos, Buffer,vt);
while (Pos < EndPos) do
begin
ASNItem(Pos, Buffer,vt);
Sm := ASNItem(Pos, Buffer,vt);
Sv := ASNItem(Pos, Buffer,vt);
MIBAdd(Sm, Sv, vt);
end;
Result := 1;
end;
(*----------------------------------------------------------------------------*
| TSNMPInfo.SetCommunity |
| |
| Set the community. |
| |
| Parameters: |
| const Value: string The new community value |
*----------------------------------------------------------------------------*)
procedure TSNMPInfo.SetCommunity(const Value: string);
begin
if Community <> Value then
begin
Clear;
fCommunity := Value
end
end;
{ TIdSNMP }
{============================== IdSNMP OBJECT ================================}
(*----------------------------------------------------------------------------*
| constructor TIdSNMP.Create |
| |
| Contructor for TIdSNMP component |
| |
| Parameters: |
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -