gufo.snmp.cli¶
gufo-snmp command.
Attributes:
Name | Type | Description |
---|---|---|
NAME |
Utility's name. |
Cli
¶
Bases: object
gufo-snmp
utility class.
die(msg=None)
classmethod
¶
Die with message.
get_command(ns)
¶
Get command from arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ns
|
Namespace
|
Parsed namespace. |
required |
Returns:
Type | Description |
---|---|
Command
|
Parsed command. |
get_community(ns)
¶
Get SNMP community from arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ns
|
Namespace
|
Parsed namespace. |
required |
Returns:
Type | Description |
---|---|
str
|
SNMP community |
get_session(ns)
¶
Construct SnmpSession from args.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ns
|
Namespace
|
Parsed namespace. |
required |
Returns:
Type | Description |
---|---|
SnmpSession
|
SnmpSession |
get_user(ns)
¶
Get USM configuration from arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ns
|
Namespace
|
Parsed namespace. |
required |
Returns:
Type | Description |
---|---|
User
|
USM configuration |
get_version(ns)
¶
Parse SNMP version from arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ns
|
Namespace
|
Parsed namespace. |
required |
Returns:
Type | Description |
---|---|
SnmpVersion
|
Protocol version |
is_valid_oid(oid)
classmethod
¶
Check oid is valid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
oid
|
str
|
Object id as string. |
required |
Returns:
Name | Type | Description |
---|---|---|
True |
bool
|
if oid is valid. |
False |
bool
|
otherwise. |
parse_args(args)
classmethod
¶
Parse arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
List[str]
|
Arguments list. |
required |
Returns:
Type | Description |
---|---|
Namespace
|
Parsed namespace. |
run(args)
¶
Parse command-line arguments and run appropriative command.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
List[str]
|
List of command-line arguments |
required |
Returns: ExitCode
run_get(session, oids, formatter)
¶
Perform GET request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
SnmpSession
|
Configured session. |
required |
oids
|
List[str]
|
List of oid, we must be sure, only one is used. |
required |
formatter
|
Formatter
|
Formatter instance. |
required |
run_get_many(session, oids, formatter)
¶
Perform multi-value GET request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
SnmpSession
|
Configured session. |
required |
oids
|
List[str]
|
List of oids. |
required |
formatter
|
Formatter
|
Formatter instance. |
required |
run_getbulk(session, oids, formatter)
¶
Perform GETBULK.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
SnmpSession
|
Configured session. |
required |
oids
|
List[str]
|
List of oids. |
required |
formatter
|
Formatter
|
Formatter instance. |
required |
run_getnext(session, oids, formatter)
¶
Perform GETNEXT.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
SnmpSession
|
Configured session. |
required |
oids
|
List[str]
|
List of oids. |
required |
formatter
|
Formatter
|
Formatter instance. |
required |
CollectOFlags
¶
Bases: Action
Argparse action for collecting multiple -O option flags.
This action mimics the behavior of Net-SNMP's -O
option, which can be
specified multiple times (e.g., -On -Oq -Ov
) or combined in a single
token (e.g., -Onqv
). Each occurrence contributes its flag characters
to a set stored in the destination attribute.
__call__(parser, namespace, values, option_string=None)
¶
Process a single -O argument occurrence.
Each time the -O option is encountered, this method extracts the individual flag characters from values and merges them into the destination attribute (a set of characters). Duplicate flags are ignored automatically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parser
|
ArgumentParser
|
The argument parser invoking this action. |
required |
namespace
|
Namespace
|
The namespace object where parsed values are stored. |
required |
values
|
Union[str, Sequence[Any], None]
|
The string of flag characters passed to -O
(e.g., "nqv" for |
required |
option_string
|
Optional[str]
|
The option string that triggered this action, e.g., "-O" (may be None when called programmatically). |
None
|
Command
¶
Bases: Enum
Command to execute.
ExitCode
¶
Bases: IntEnum
Cli exit codes.
Attributes:
Name | Type | Description |
---|---|---|
OK |
Successful exit. |
|
ERR |
Error. |
Formatter
¶
StrFormat
¶
Bases: Enum
OctetString formatters.
Attributes:
Name | Type | Description |
---|---|---|
REPR |
Using python's repr(). |
|
ASCII |
Show printable ASCII symbols, replacing others with dots. |
|
HEX |
Hex-dump. |
|
ASCII_HEX |
ASCII + HEX |
default()
classmethod
¶
Get default value.
main(args=None)
¶
Run gufo-ping
with command-line arguments.