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

analyze(table_data, opts \\ [])

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/2
  • opts - 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}
}}

column_stats(table_data, columns \\ nil)

Calculates statistics for numeric columns in the table.

Parameters

  • table_data - Table data as returned by to_table/2
  • columns - 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}}}

filter_by_column(table_data, column, filter_fn)

Filters table data by column values using a filter function.

Parameters

  • table_data - Table data as returned by to_table/2
  • column - Column number to filter on
  • filter_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}}}

filter_by_index(table_data, index_filter)

Filters table data by index using a filter function.

Parameters

  • table_data - Table data as returned by to_table/2
  • index_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"}}}

find_duplicates(table_data, columns)

Finds duplicate rows in the table based on specified columns.

Parameters

  • table_data - Table data as returned by to_table/2
  • columns - 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}}]]}

get_columns(table_data)

Extracts all unique column numbers from table data.

get_indexes(table_data)

Extracts all unique indexes from table data.

group_by_column(table_data, column)

Groups table rows by values in a specific column.

Parameters

  • table_data - Table data as returned by to_table/2
  • column - 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}]}}

sort_by_column(table_data, column, direction \\ :asc)

Sorts table data by a specific column.

Parameters

  • table_data - Table data as returned by to_table/2
  • column - Column number to sort by
  • direction - :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"}}]}

to_list(table_data)

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}
]}

to_map(oid_type_value_tuples, key_column)

Converts table data to a map keyed by a specific column.

Parameters

  • oid_type_value_tuples - List of {oid_string, type, value} tuples
  • key_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"}
}}

to_rows(oid_type_value_tuples)

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.

to_table(oid_type_value_tuples, table_oid)

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} tuples
  • table_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}
}}

validate(table_data, opts \\ [])

Validates table data integrity and consistency.

Parameters

  • table_data - Table data as returned by to_table/2
  • opts - Validation options

Examples

iex> table = %{1 => %{2 => "eth0", 3 => 100}}
iex> SnmpKit.SnmpMgr.Table.validate(table)
{:ok, %{valid: true, issues: []}}