SnmpKit.SnmpMgr.Table (snmpkit v0.6.3)
Table processing utilities for SNMP table data.
Provides functions to convert flat OID/type/value lists into structured table representations and perform table analysis operations.
Summary
Functions
Analyzes table structure and returns metadata about the table.
Calculates statistics for numeric columns in the table.
Filters table data by column values using a filter function.
Filters table data by index using a filter function.
Finds duplicate rows in the table based on specified columns.
Extracts all unique column numbers from table data.
Extracts all unique indexes from table data.
Groups table rows by values in a specific column.
Sorts table data by a specific column.
Converts table data to a list format for easier processing.
Converts table data to a map keyed by a specific column.
Converts OID/type/value tuples to a list of row maps.
Converts flat OID/type/value tuples to a structured table format.
Validates table data integrity and consistency.
Functions
Analyzes table structure and returns metadata about the table.
Provides detailed information about table dimensions, column types, missing data, and statistical analysis.
Parameters
table_data
- Table data as returned by to_table/2opts
- Options including :analyze_types, :find_missing
Examples
iex> table = %{1 => %{2 => "eth0", 3 => 100}, 2 => %{2 => "eth1", 3 => 200}}
iex> SnmpKit.SnmpMgr.Table.analyze(table)
{:ok, %{
row_count: 2,
column_count: 2,
columns: [2, 3],
indexes: [1, 2],
completeness: 1.0,
column_types: %{2 => :string, 3 => :integer}
}}
Calculates statistics for numeric columns in the table.
Parameters
table_data
- Table data as returned by to_table/2columns
- List of column numbers to analyze (optional, analyzes all numeric columns)
Examples
iex> table = %{1 => %{2 => "eth0", 3 => 100}, 2 => %{2 => "eth1", 3 => 200}}
iex> SnmpKit.SnmpMgr.Table.column_stats(table, [3])
{:ok, %{3 => %{count: 2, sum: 300, avg: 150.0, min: 100, max: 200}}}
Filters table data by column values using a filter function.
Parameters
table_data
- Table data as returned by to_table/2column
- Column number to filter onfilter_fn
- Function that takes a value and returns boolean
Examples
iex> table = %{1 => %{2 => "eth0", 3 => 1}, 2 => %{2 => "eth1", 3 => 0}}
iex> SnmpKit.SnmpMgr.Table.filter_by_column(table, 3, fn val -> val == 1 end)
{:ok, %{1 => %{2 => "eth0", 3 => 1}}}
Filters table data by index using a filter function.
Parameters
table_data
- Table data as returned by to_table/2index_filter
- Function that takes an index and returns boolean
Examples
iex> table = %{1 => %{2 => "eth0"}, 2 => %{2 => "eth1"}, 10 => %{2 => "lo"}}
iex> SnmpKit.SnmpMgr.Table.filter_by_index(table, fn index -> index < 10 end)
{:ok, %{1 => %{2 => "eth0"}, 2 => %{2 => "eth1"}}}
Finds duplicate rows in the table based on specified columns.
Parameters
table_data
- Table data as returned by to_table/2columns
- List of column numbers to check for duplicates
Examples
iex> table = %{1 => %{2 => "eth", 3 => 1}, 2 => %{2 => "eth", 3 => 1}}
iex> SnmpKit.SnmpMgr.Table.find_duplicates(table, [2, 3])
{:ok, [[{1, %{2 => "eth", 3 => 1}}, {2, %{2 => "eth", 3 => 1}}]]}
Extracts all unique column numbers from table data.
Extracts all unique indexes from table data.
Groups table rows by values in a specific column.
Parameters
table_data
- Table data as returned by to_table/2column
- Column number to group by
Examples
iex> table = %{1 => %{2 => "eth", 3 => 1}, 2 => %{2 => "lo", 3 => 1}}
iex> SnmpKit.SnmpMgr.Table.group_by_column(table, 3)
{:ok, %{1 => [%{index: 1, 2 => "eth", 3 => 1}, %{index: 2, 2 => "lo", 3 => 1}]}}
Sorts table data by a specific column.
Parameters
table_data
- Table data as returned by to_table/2column
- Column number to sort bydirection
- :asc or :desc (default: :asc)
Examples
iex> table = %{1 => %{2 => "eth1"}, 2 => %{2 => "eth0"}}
iex> SnmpKit.SnmpMgr.Table.sort_by_column(table, 2)
{:ok, [{2, %{2 => "eth0"}}, {1, %{2 => "eth1"}}]}
Converts table data to a list format for easier processing.
Examples
iex> table = %{1 => %{2 => "eth0", 3 => 6}, 2 => %{2 => "eth1", 3 => 6}}
iex> SnmpKit.SnmpMgr.Table.to_list(table)
{:ok, [
%{index: 1, 2 => "eth0", 3 => 6},
%{index: 2, 2 => "eth1", 3 => 6}
]}
Converts table data to a map keyed by a specific column.
Parameters
oid_type_value_tuples
- List of {oid_string, type, value} tupleskey_column
- Column number to use as the key
Examples
iex> tuples = [
...> {"1.3.6.1.2.1.2.2.1.1.1", :integer, 1},
...> {"1.3.6.1.2.1.2.2.1.2.1", :string, "eth0"},
...> {"1.3.6.1.2.1.2.2.1.1.2", :integer, 2},
...> {"1.3.6.1.2.1.2.2.1.2.2", :string, "eth1"}
...> ]
iex> SnmpKit.SnmpMgr.Table.to_map(tuples, 1)
{:ok, %{
1 => %{ifIndex: 1, ifDescr: "eth0"},
2 => %{ifIndex: 2, ifDescr: "eth1"}
}}
Converts OID/type/value tuples to a list of row maps.
Each row is a map where keys are column numbers and values are the data values.
Converts flat OID/type/value tuples to a structured table format.
Takes a list of {oid_string, type, value} tuples from a table walk and converts them into a structured table with rows and columns.
Parameters
oid_type_value_tuples
- List of {oid_string, type, value} tuplestable_oid
- The base table OID (used to determine table structure)
Examples
iex> tuples = [
...> {"1.3.6.1.2.1.2.2.1.2.1", :string, "eth0"},
...> {"1.3.6.1.2.1.2.2.1.2.2", :string, "eth1"},
...> {"1.3.6.1.2.1.2.2.1.3.1", :integer, 6},
...> {"1.3.6.1.2.1.2.2.1.3.2", :integer, 6}
...> ]
iex> SnmpKit.SnmpMgr.Table.to_table(tuples, [1, 3, 6, 1, 2, 1, 2, 2])
{:ok, %{
1 => %{2 => "eth0", 3 => 6},
2 => %{2 => "eth1", 3 => 6}
}}
Validates table data integrity and consistency.
Parameters
table_data
- Table data as returned by to_table/2opts
- Validation options
Examples
iex> table = %{1 => %{2 => "eth0", 3 => 100}}
iex> SnmpKit.SnmpMgr.Table.validate(table)
{:ok, %{valid: true, issues: []}}