查看源代码 snmp (snmp v5.18)
SNMP 工具包的接口函数
模块 snmp
包含 SNMP 工具包的接口函数。
另请参阅
calendar(3)
概要
类型
SNMP BITS(伪)数据类型的 Erlang 表示形式。
验证器函数的输入如下所示
一个字符串,表示目录的文件路径。
当错误状态为 noError
时使用 0
,当错误状态为实际错误时,错误索引为 pos_integer/0
。
我们应该真正指定所有这些,但是它们数量太多了...此外,通常您需要知道的是 'noError'
是正常的,其他所有都是错误。
这基本上是 dlog_size() 的副本。
表示一个 ASN.1 对象标识符。
RFC1903 中指定的 DateAndTime 数据类型,一个 OCTET STRING。
表示 OID 的最后一部分,该部分指定表中行的索引(有关 INDEX 的更多信息,请参阅 RFC1212,4.1.6)。
注意
“表示指向概念行的指针。该值是概念行中第一个可访问的列对象的实例名称。”
注意
“以 0.01 秒为单位测量的时间段。”
对于最低的详细程度 silence
,不打印任何内容。详细程度越高,打印的内容越多。
当函数的返回值被忽略时使用该类型。
函数
根据 RFC1906 第 8 节,将 BITS
类型的值转换为 OCTET-STRING
的实用函数。
更改审计跟踪日志的日志大小。必须配置应用程序以使用审计跟踪日志功能。有关如何更改日志大小的说明,请参阅 Kernel Reference Manual 中的 disk_log(3)。
一个简单的交互式配置工具。可以生成简单的配置文件,但更复杂的配置仍然需要手动编辑。
按照 RFC1903 的规定,以 DateAndTime 数据类型返回当前日期和时间。这是一个 OCTET STRING。
根据 RFC2579 中的 DISPLAY-HINT 定义,将 DateAndTime 列表转换为可打印的字符串,扩展之处在于它还允许值“与 UTC 的小时数”= 14 以及“与 UTC 的分钟数”= 0。
根据 RFC2579 中的 DISPLAY-HINT 定义,将 DateAndTime 列表转换为可打印的字符串。
将 DateAndTime 列表转换为可能的通用时间列表。通用时间值与 calendar(3) 中定义的格式相同。
停止跟踪器。
启动一个 dbg 跟踪器,该跟踪器将跟踪事件打印到 stdout(在进行少量格式化后使用纯 io:format)。
将本地时间值转换为可能的 DateAndTime 列表。本地时间值与 calendar(3) 中定义的格式相同。
等效于 log_to_io/7
。
等效于 log_to_io/7
。
将审计跟踪日志转换为可读格式并将其打印在 stdio 上。有关更多信息,请参见 log_to_txt/8
。
等效于 log_to_txt/8
。
等效于 log_to_txt/8
。
将审计跟踪日志转换为可读的文本文件,其中每个项目都有一个尾随 TAB 字符,并且项目正文中的任何 TAB 字符都已被 ESC TAB 替换。
根据 RFC1906 第 8 节,将 OCTET-STRING
类型的值转换为 BITS
的实用函数。
生成可使用 MD5、SHA、SHA224、SHA256、SHA384 或 SHA512 用作身份验证或隐私密钥的密钥。该密钥已针对 EngineID 进行本地化。
用于生成由 versions1
函数生成的版本信息的格式化打印输出的实用程序函数。
用于生成由 versions1
和 versions2
函数生成的版本信息的格式化打印输出的实用程序函数。
读取已编译的 mib。
此函数用于重置(禁用)给定模块的跟踪。
此函数用于在给定模块的一个或多个函数上设置默认跟踪。跟踪的范围将是所有导出的函数(包括调用信息和返回值)。还将包括时间戳信息。
此函数用于在给定模块的一个或多个函数上设置跟踪。
启动 SNMP 应用程序。
SNMP 应用程序由多个实体组成,其中代理是其中之一。此函数启动应用程序的代理实体。
SNMP 应用程序由多个实体组成,其中管理器是其中之一。此函数启动应用程序的管理器实体。
停止 SNMP 应用程序。
将通用时间值转换为 DateAndTime 列表。通用时间值与 calendar(3) 中定义的格式相同。
检查 DateAndTime
是否是正确的 DateAndTime 值,如 RFC2579 中指定的那样。此函数可以在仪器函数中使用,以验证 DateAndTime 值。
等效于 versions2/0
。
用于检索一些系统和应用程序信息的实用程序函数。
类型
-type algorithm() :: md5 | sha | sha224 | sha256 | sha384 | sha512.
-type atl_type() :: read | write | read_write.
-type bits() :: integer().
SNMP BITS(伪)数据类型的 Erlang 表示形式。
-type column() :: pos_integer().
-type community() :: snmp_community_mib:name().
-type context_name() :: snmp_community_mib:context_name().
-type date_and_time_validator() :: fun((Kind :: date_and_time_validator_kind(), Data :: term()) -> boolean()).
验证器函数的输入如下所示
Kind Data
-------------- ----------------------
year {Year1, Year2}
month Month
day Day
hour Hour
minute Minute
seconds Seconds
deci_seconds DeciSeconds
diff [Sign, Hour, Minute]
valid_date {Year, Month, Day}
-type date_and_time_validator_kind() ::
year | month | day | hour | minute | seconds | deci_seconds | diff | valid_date.
-type dir() :: string().
一个字符串,表示目录的文件路径。
-type engine_id() :: snmp_framework_mib:engine_id().
-type error_index() :: non_neg_integer().
当错误状态为 noError
时使用 0
,当错误状态为实际错误时,错误索引为 pos_integer/0
。
-type error_status() :: noError | atom().
我们应该真正指定所有这些,但是它们数量太多了...此外,通常您需要知道的是 'noError'
是正常的,其他所有都是错误。
-type log_size() :: infinity | pos_integer() | {MaxNoBytes :: pos_integer(), MaxNoFiles :: pos_integer()}.
这基本上是 dlog_size() 的副本。
-type log_time() :: calendar:datetime() | {local_time, calendar:datetime()} | {universal_time, calendar:datetime()}.
-type mib_name() :: string().
-type mms() :: snmp_framework_mib:max_message_size().
-type octet() :: 0..255.
-type octet_string() :: [octet()].
-type oid() :: [non_neg_integer()].
表示一个 ASN.1 对象标识符。
-type pdu_type() :: snmp_pdus:pdu_type().
-type rfc1903_date_and_time() :: octet_string().
RFC1903 中指定的 DateAndTime 数据类型,一个 OCTET STRING。
-type row_index() :: oid().
表示 OID 的最后一部分,该部分指定表中行的索引(有关 INDEX 的更多信息,请参阅 RFC1212,4.1.6)。
-type row_pointer() :: oid().
注意
“表示指向概念行的指针。该值是概念行中第一个可访问的列对象的实例名称。”
OBJECT IDENTIFIER
由 SNMPv2-TC 定义。
-type sec_level() :: snmp_framework_mib:security_level().
-type sec_model() :: snmp_framework_mib:security_model().
-type sec_name() :: snmp_framework_mib:admin_string().
-type taddress() :: snmpa_conf:transportAddress().
-type tdomain() :: transportDomainUdpIpv4 | transportDomainUdpIpv6.
-type time_interval() :: 0..2147483647.
注意
“以 0.01 秒为单位测量的时间段。”
INTEGER (0..2147483647)
由 SNMPv2-TC 定义。
-type usm_auth_key() :: snmp_user_based_sm_mib:auth_key().
-type usm_auth_protocol() :: snmp_user_based_sm_mib:auth_protocol().
-type usm_name() :: snmp_user_based_sm_mib:name().
-type usm_priv_key() :: snmp_user_based_sm_mib:priv_key().
-type usm_priv_protocol() :: snmp_user_based_sm_mib:priv_protocol().
-type variable_info() :: #variable_info{defval :: term()}.
-type verbosity() :: silence | info | log | debug | trace.
对于最低的详细程度 silence
,不打印任何内容。详细程度越高,打印的内容越多。
-type version() :: v1 | v2 | v3.
-type void() :: term().
当函数的返回值被忽略时使用该类型。
函数
-spec bits_to_octet_string(B) -> octet_string() when B :: bits().
根据 RFC1906 第 8 节,将 BITS
类型的值转换为 OCTET-STRING
的实用函数。
-spec change_log_size(LogName, NewSize) -> ok | {error, Reason} when LogName :: string(), NewSize :: log_size(), Reason :: term().
更改审计跟踪日志的日志大小。必须配置应用程序以使用审计跟踪日志功能。有关如何更改日志大小的说明,请参阅 Kernel Reference Manual 中的 disk_log(3)。
只要不删除日志,更改就是永久性的。这意味着,日志大小会在重启时记住。
-spec config() -> ok | {error, Reason} when Reason :: term().
一个简单的交互式配置工具。可以生成简单的配置文件,但更复杂的配置仍然需要手动编辑。
该工具是一个基于文本的工具,它会询问一些问题并生成 sys.config
和 *.conf
文件。
请注意,如果应用程序应支持版本 3,则必须在运行此函数之前启动 crypto 应用程序(密码生成)。
还要注意,代理和管理器的某些配置文件共享相同的名称。这意味着它们必须存储在不同的目录中!
-spec date_and_time() -> DateAndTime when DateAndTime :: rfc1903_date_and_time().
按照 RFC1903 的规定,以 DateAndTime 数据类型返回当前日期和时间。这是一个 OCTET STRING。
-spec date_and_time_to_string2(DAT) -> string() when DAT :: rfc1903_date_and_time().
根据 RFC2579 中的 DISPLAY-HINT 定义,将 DateAndTime 列表转换为可打印的字符串,扩展之处在于它还允许值“与 UTC 的小时数”= 14 以及“与 UTC 的分钟数”= 0。
-spec date_and_time_to_string(DAT) -> string() when DAT :: rfc1903_date_and_time().
-spec date_and_time_to_string(DAT, Validate) -> string() when DAT :: rfc1903_date_and_time(), Validate :: date_and_time_validator().
根据 RFC2579 中的 DISPLAY-HINT 定义,将 DateAndTime 列表转换为可打印的字符串。
验证函数 Validate
允许对 DateAndTime
参数进行更“灵活”的验证。每当发现数据不符合 RFC2579 时,就会调用该函数以允许进行更“宽松”的验证。有关 Validate
函数的更多信息,请参见 validate_date_and_time/2
函数。
-spec date_and_time_to_universal_time_dst(DAT) -> UTCs when DAT :: rfc1903_date_and_time(), UTCs :: [calendar:datetime1970()].
将 DateAndTime 列表转换为可能的通用时间列表。通用时间值与 calendar(3) 中定义的格式相同。
-spec disable_trace() -> void().
停止跟踪器。
-spec enable_trace() -> void().
启动一个 dbg 跟踪器,该跟踪器将跟踪事件打印到 stdout(在进行少量格式化后使用纯 io:format)。
-spec local_time_to_date_and_time_dst(Local) -> DATs when Local :: calendar:datetime1970(), DATs :: [rfc1903_date_and_time()].
将本地时间值转换为可能的 DateAndTime 列表。本地时间值与 calendar(3) 中定义的格式相同。
-spec log_to_io(LogDir, Mibs, LogName, LogFile) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], LogName :: string(), LogFile :: string(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term().
等效于 log_to_io/7
。
-spec log_to_io(LogDir, Mibs, LogName, LogFile, Block) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], LogName :: string(), LogFile :: string(), Block :: boolean(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term(); (LogDir, Mibs, LogName, LogFile, Start) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], LogName :: string(), LogFile :: string(), Start :: null | log_time(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term().
等效于 log_to_io/7
。
-spec log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], LogName :: string(), LogFile :: string(), Block :: boolean(), Start :: null | log_time(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term(); (LogDir, Mibs, LogName, LogFile, Start, Stop) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], LogName :: string(), LogFile :: string(), Start :: null | log_time(), Stop :: null | log_time(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term().
等效于 log_to_io/7
。
-spec log_to_io(LogDir, Mibs, LogName, LogFile, Block, Start, Stop) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], LogName :: string(), LogFile :: string(), Block :: boolean(), Start :: null | log_time(), Stop :: null | log_time(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term().
将审计跟踪日志转换为可读格式并将其打印在 stdio 上。有关更多信息,请参见 log_to_txt/8
。
-spec log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], OutFile :: string(), LogName :: string(), LogFile :: string(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term().
等效于 log_to_txt/8
。
-spec log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], OutFile :: string(), LogName :: string(), LogFile :: string(), Block :: boolean(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term(); (LogDir, Mibs, OutFile, LogName, LogFile, Start) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], OutFile :: string(), LogName :: string(), LogFile :: string(), Start :: null | log_time(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term().
等效于 log_to_txt/8
。
-spec log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], OutFile :: string(), LogName :: string(), LogFile :: string(), Block :: boolean(), Start :: null | log_time(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term(); (LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], OutFile :: string(), LogName :: string(), LogFile :: string(), Start :: null | log_time(), Stop :: null | log_time(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term().
等效于 log_to_txt/8
。
log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop)
查看源代码 (自 OTP R16B03 起)-spec log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Block, Start, Stop) -> ok | {ok, Cnt} | {error, Reason} when LogDir :: string(), Mibs :: [mib_name()], OutFile :: string(), LogName :: string(), LogFile :: string(), Block :: boolean(), Start :: null | log_time(), Stop :: null | log_time(), Cnt :: {NumOK, NumERR}, NumOK :: non_neg_integer(), NumERR :: pos_integer(), Reason :: term().
将审计跟踪日志转换为可读的文本文件,其中每个项目都有一个尾随 TAB 字符,并且项目正文中的任何 TAB 字符都已被 ESC TAB 替换。
该函数可以在正在运行的系统上使用,也可以通过复制整个日志目录并调用此函数来使用。SNMP 必须正在运行才能提供 MIB 信息。
LogDir
是存储审计跟踪日志的目录的名称。Mibs
是要使用的 Mib 列表。该函数使用 Mib 中的信息来转换例如对象标识符到其符号名称。OutFile
是生成的文本文件的名称。LogName
是日志的名称,LogFile
是日志文件的名称。Start
是开始(第一个)日期和时间,从该日期和时间开始转换日志事件,Stop
是停止(最后)日期和时间,到该日期和时间为止将转换日志事件。Block
参数指示是否在转换期间阻止日志。在转换大型日志时,这可能会很有用(否则,日志可能会在转换期间包装)。默认为 true
。
审计跟踪日志文本项的格式如下
标签 地址 - 社区 [时间戳] 版本
PDU
其中,Tag
为 request
、response
、report
、trap
或 inform
;Addr 为 IP:Port
(或此类以逗号空格分隔的列表);Community
是团体参数(SNMP 版本 v1 和 v2),或 SecLevel:"AuthEngineID":"UserName"
(SNMP v3);TimeStamp
是日期和时间戳,Vsn
是 SNMP 版本。PDU
是协议数据单元的文本版本。Vsn
和 PDU
之间有一个新行。
如果整个日志转换成功,该函数将返回 ok
。如果一个或多个条目转换失败,该函数将返回 {ok, {NumOK, NumERR}}
,其中计数器指示找到了多少个有效条目和错误条目。如果返回 {error, Reason}
,则表示转换遇到致命错误,要么从未完成,要么中途中止。
-spec octet_string_to_bits(S) -> bits() when S :: octet_string().
根据 RFC1906 第 8 节,将 OCTET-STRING
类型的值转换为 BITS
的实用函数。
-spec passwd2localized_key(Algorithm, Passwd, EngineID) -> Key when Algorithm :: algorithm(), Passwd :: string(), EngineID :: string(), Key :: list().
生成可使用 MD5、SHA、SHA224、SHA256、SHA384 或 SHA512 用作身份验证或隐私密钥的密钥。该密钥已针对 EngineID 进行本地化。
-spec print_version_info() -> void().
等效于 print_version_info/1
。
-spec print_version_info(Prefix) -> void() when Prefix :: string() | non_neg_integer().
用于生成由 versions1
函数生成的版本信息的格式化打印输出的实用程序函数。
这与执行以下操作相同,例如:
{ok, V} = snmp:versions1(),
snmp:print_versions(V).
等效于 print_versions/2
。
-spec print_versions(Prefix, Versions) -> void() when Prefix :: string() | non_neg_integer(), Versions :: [VersionInfo], VersionInfo :: term().
用于生成由 versions1
和 versions2
函数生成的版本信息的格式化打印输出的实用程序函数。
示例
{ok, V} = snmp:versions1(),
snmp:print_versions(V).
-spec read_mib(FileName) -> {ok, Mib} | {error, Reason} when FileName :: string(), Mib :: mib(), Reason :: term().
读取已编译的 mib。
此函数用于重置(禁用)给定模块的跟踪。
-spec set_trace(Targets) -> void() when Targets :: module() | [module() | {module(), [TargetOpt]}], TargetOpt :: {return_trace, boolean()} | {scope, Scope}, Scope :: all_functions | exported_functions | FunctionName | {FunctionName, FunctionArity}, FunctionName :: atom(), FunctionArity :: non_neg_integer().
此函数用于在给定模块的一个或多个函数上设置默认跟踪。跟踪的范围将是所有导出的函数(包括调用信息和返回值)。还将包括时间戳信息。
-spec set_trace(Targets, TraceOpts) -> void() when Targets :: module() | [module() | {module(), [TargetOpt]}], TargetOpt :: {return_trace, boolean()} | {scope, Scope}, Scope :: all_functions | exported_functions | FunctionName | {FunctionName, FunctionArity}, FunctionName :: atom(), FunctionArity :: non_neg_integer(), TraceOpts :: disable | [TraceOpt], TraceOpt :: {timestamp, boolean()} | TargetOpt.
此函数用于在给定模块的一个或多个函数上设置跟踪。
下面的示例在模块 snmp_generic
的导出函数(默认)和模块 snmp_generic_mnesia
的所有函数上设置跟踪。在两种情况下都使用返回值(默认)和时间戳(也是默认)。
snmp:enable_trace(),
snmp:set_trace([snmp_generic,
{snmp_generic_mnesia, [{scope, all_functions}]}]),
.
.
.
snmp:set_trace(snmp_generic, disable),
.
.
.
snmp:disable_trace(),
-spec start() -> ok | {error, Reason} when Reason :: term().
等效于 start/1
。
-spec start(Type) -> ok | {error, Reason} when Type :: p | permanent | tr | transient | te | temporary, Reason :: term().
启动 SNMP 应用程序。
有关更多信息,请参见 application
。
-spec start_agent() -> ok | {error, Reason} when Reason :: term().
等效于 start_agent/1
。
-spec start_agent(Type) -> ok | {error, Reason} when Type :: application:start_type(), Reason :: term().
SNMP 应用程序由多个实体组成,其中代理是其中之一。此函数启动应用程序的代理实体。
请注意,以这种方式实际启动代理的唯一方法是在启动应用程序后添加与代理相关的配置(例如,它不能是普通应用程序配置的一部分;sys.config)。这通过调用:application:set_env(snmp, agent, Conf)
来完成。
Type
的默认值为 normal
。
-spec start_manager() -> ok | {error, Reason} when Reason :: term().
等效于 start_manager/1
。
-spec start_manager(Type) -> ok | {error, Reason} when Type :: application:start_type(), Reason :: term().
SNMP 应用程序由多个实体组成,其中管理器是其中之一。此函数启动应用程序的管理器实体。
请注意,以这种方式实际启动管理器的唯一方法是在启动应用程序后添加与管理器相关的配置(例如,它不能是普通应用程序配置的一部分;sys.config)。这通过调用:application:set_env(snmp, manager, Conf)
来完成。
Type
的默认值为 normal
。
-spec stop() -> ok | {error, Reason} when Reason :: term().
停止 SNMP 应用程序。
有关更多信息,请参见 application
。
此函数已存在很长时间,但没有适当的 since 标签,因此为了简化,我们将 since 标签设置为其被记录的时间。
-spec universal_time_to_date_and_time(UTC) -> DateAndTime when UTC :: calendar:datetime(), DateAndTime :: rfc1903_date_and_time().
将通用时间值转换为 DateAndTime 列表。通用时间值与 calendar(3) 中定义的格式相同。
-spec validate_date_and_time(DateAndTime) -> boolean() when DateAndTime :: rfc1903_date_and_time().
-spec validate_date_and_time(DateAndTime, Validate) -> boolean() when DateAndTime :: rfc1903_date_and_time(), Validate :: date_and_time_validator().
检查 DateAndTime
是否是正确的 DateAndTime 值,如 RFC2579 中指定的那样。此函数可以在仪器函数中使用,以验证 DateAndTime 值。
验证函数 Validate
允许对 DateAndTime
参数进行更“灵活”的验证。每当发现数据不符合 RFC2579 时,就会调用该函数以允许更“宽松”的验证。
-spec versions1() -> {ok, VersionsInfo} | {error, Reason} when VersionsInfo :: [VersionInfo], VersionInfo :: term(), Reason :: term().
等效于 versions2/0
。
-spec versions2() -> {ok, VersionsInfo} | {error, Reason} when VersionsInfo :: [VersionInfo], VersionInfo :: term(), Reason :: term().
用于检索一些系统和应用程序信息的实用程序函数。
这两个函数之间的区别在于它们如何获取要检查的模块。versions1
使用 app 文件,而 versions2
使用函数 application:get_key
。