net-snmp-typed
Version:
typed-net-snmp
163 lines (142 loc) • 3.53 kB
TypeScript
declare module 'net-snmp-typed' {
// 版本常量
export const Version1: number;
export const Version2c: number;
export const Version3: number;
// 错误状态常量
export enum ErrorStatus {
NoError,
TooBig,
NoSuchName,
BadValue,
ReadOnly,
GeneralError,
NoAccess,
WrongType,
WrongLength,
WrongEncoding,
WrongValue,
NoCreation,
InconsistentValue,
ResourceUnavailable,
CommitFailed,
UndoFailed,
AuthorizationError,
NotWritable,
InconsistentName
}
// 对象类型常量
export enum ObjectType {
Boolean,
Integer,
OctetString,
Null,
OID,
IpAddress,
Counter,
Gauge,
TimeTicks,
Opaque,
Integer32,
Counter32,
Gauge32,
Unsigned32,
Counter64,
NoSuchObject,
NoSuchInstance,
EndOfMibView
}
// 陷阱类型常量
export enum TrapType {
ColdStart,
WarmStart,
LinkDown,
LinkUp,
AuthenticationFailure,
EgpNeighborLoss,
EnterpriseSpecific
}
// PDU 类型常量
export enum PduType {
GetRequest = 160,
GetNextRequest = 161,
GetResponse = 162,
SetRequest = 163,
Trap = 164,
GetBulkRequest = 165,
InformRequest = 166,
TrapV2 = 167,
Report = 168
}
// 安全级别常量
export enum SecurityLevel {
noAuthNoPriv,
authNoPriv,
authPriv
}
// 认证协议常量
export const AuthProtocols: {
md5: number;
sha: number;
sha224: number;
sha256: number;
sha384: number;
sha512: number;
};
// 加密协议常量
export const PrivProtocols: {
des: number;
aes: number;
aes256b: number;
aes256r: number;
};
// Varbind 接口
export interface Varbind {
oid: string;
type: ObjectType;
value: any;
}
// Session 选项接口
export interface SessionOptions {
port?: number;
retries?: number;
timeout?: number;
transport?: string;
trapPort?: number;
version?: number;
backwardsGetNexts?: boolean;
reportOidMismatchErrors?: boolean;
idBitsSize?: number;
}
// V3 用户接口
export interface V3User {
name: string;
level: SecurityLevel;
authProtocol?: number;
authKey?: string;
privProtocol?: number;
privKey?: string;
}
// Session 类
export class Session {
constructor(target: string, community: string, options?: SessionOptions);
close(): void;
get(oids: string[], callback: (error: Error | null, varbinds: Varbind[]) => void): void;
getBulk(oids: string[], nonRepeaters: number, maxRepetitions: number,
callback: (error: Error | null, varbinds: Varbind[]) => void): void;
getNext(oids: string[], callback: (error: Error | null, varbinds: Varbind[]) => void): void;
set(varbinds: Varbind[], callback: (error: Error | null, varbinds: Varbind[]) => void): void;
trap(typeOrOid: TrapType | string, varbinds?: Varbind[],
callback?: (error: Error | null) => void): void;
inform(typeOrOid: TrapType | string, varbinds?: Varbind[],
callback?: (error: Error | null) => void): void;
}
// 创建会话函数
export function createSession(target: string, community: string,
options?: SessionOptions): Session;
export function createV3Session(target: string, user: V3User,
options?: SessionOptions): Session;
// 工具函数
export function isVarbindError(varbind: Varbind): boolean;
export function varbindError(varbind: Varbind): string;
}