NetSNMP-0.2.0.2: Bindings for net-snmp's C API for clients

Portabilityportable
MaintainerJohn Dorsey <haskell@colquitt.org>
Safe HaskellNone

Network.Protocol.NetSNMP

Contents

Description

Stability : provisional

This is a binding to Net-SNMP version 5, http://www.net-snmp.org/.

Synopsis

Types

data ASNValue Source

Typed representation of atomic ASN.1 data types. Some types are returned in more than one format for different uses. Some include a descriptive string built by the underlying C library.

Constructors

OctetString String [Word8]

ASN_OCTET_STR Returned as a character string, and as opaque data.

OID String String [Word32]

ASN_OBJECT_ID Returned as the C library's description, a dotted-decimal string, and a numeric list

Integer32 Int32

ASN_INTEGER 32bit signed

Integer64 Int64

ASN_INTEGER64 64bit signed

Counter32 Word32

ASN_COUNTER 32bit nondecreasing

Counter64 Word64

ASN_COUNTER64 64bit nondecreasing

Unsigned32 Word32

ASN_UNSIGNED 32bit unsigned

Unsigned64 Word64

ASN_UNSIGNED64 64bit unsigned

Gauge32 Word32

ASN_GAUGE 32bit signed with min and max

IpAddress String [Word8]

ASN_IPADDRESS IP address in string and numeric form. Example: (IpAddress "1.2.3.4" [1,2,3,4])

Opaque [Word8]

ASN_OPAQUE (Deprecated) application specific data. Use OctetString instead.

TimeTicks String Word32

ASN_TIMETICKS Time interval in 1/100 sec ticks. The C library's description is returned along with the raw value.

Boolean Bool

ASN_BOOLEAN Unimplemented.

IEEEFloat Float

ASN_FLOAT IEEE float. Unimplemented.

IEEEDouble Double

ASN_DOUBLE IEEE double. Unimplemented.

Null

ASN_NULL Null value

Unsupported Int String

Unsupported type from an agent. Returns the numeric type and the C library's description of the value.

Instances

data SnmpResult Source

An SNMP value together with its OID. Returned by the query routines snmpGet, snmpNext, and snmpWalk.

Constructors

SnmpResult 

Fields

oid :: String

Dotted-decimal ObjectId of the value

value :: ASNValue

Typed representation of the value

newtype SnmpVersion Source

SNMP Protocol version. It is recommended to use the constants snmp_version_1, snmp_version_2c, and snmp_version_3.

Constructors

SnmpVersion 

Fields

unSnmpVersion :: CLong

Numeric version. Generally unneeded.

Constants

snmp_version_1 :: SnmpVersionSource

SNMPv1. The first SNMP standard, using cleartext passwords ("communities")

snmp_version_2c :: SnmpVersionSource

SNMPv2c. Updated SMI and wire protocol, but still uses communities.

snmp_version_3 :: SnmpVersionSource

SNMPv3. Same SMI and protocol as SNMPv2c; stronger authentication. Unimplemented.

Functions

Library Initialization

initialize :: IO ()Source

Initialize the Net-SNMP library. This must be called before any other NetSNMP functions, and before starting extra threads, as the mib compiler is not thread-safe.

Queries

snmpGetSource

Arguments

:: SnmpVersion

snmp_version_1 or snmp_version_2c

-> Hostname

IP or hostname of the agent to be queried. May have prefix of tcp: or suffix of :port

-> Community

SNMP community (password)

-> String

OID to be queried

-> IO (Either String SnmpResult) 

Simple community-authenticated SNMP get. Returns the object queried, or a descriptive error message.

Examples:

  • snmpGet "localhost" "public" ".1.3.6.1.2.1.1.1.0"
  • snmpGet "tcp:localhost:5161" "mypassword" ".1.3.6.1.2.1.1.1.0"

snmpNextSource

Arguments

:: SnmpVersion

snmp_version_1 or snmp_version_2c

-> Hostname

IP or hostname of the agent to be queried. May have prefix of tcp: or suffix of :port

-> Community

SNMP community (password)

-> String

OID to be queried

-> IO (Either String SnmpResult) 

Simple community-authenticated SNMP getnext. Returns the first object after the OID queried, or a descriptive error message.

Examples:

  • snmpNext "localhost" "public" ".1.3.6.1.2.1.1.1.0"
  • snmpNext "tcp:localhost:5161" "mypassword" ".1.3.6.1.2.1.1.1.0"

snmpWalkSource

Arguments

:: SnmpVersion

snmp_version_1 or snmp_version_2c

-> Hostname

IP or hostname of the agent to be queried. May have prefix of tcp: or suffix of :port

-> Community

SNMP community (password)

-> String

OID to be queried

-> IO (Either String [SnmpResult]) 

Simple community-authenticated SNMP walk. Returns a list of objects, starting with the object after the OID queried, and continuing through all objects underneath that OID in the mib tree. On failure, returns a descriptive error message.

This implementation uses a series of next operations and is not very ressource friendly. Consider using snmpBulkWalk for better performance

Examples:

  • snmpWalk snmp_version_2c "localhost" "public" ".1.3.6.1.2.1.1"
  • snmpWalk snmp_version_2c "tcp:localhost:5161" "mypassword" ".1.3.6.1.2.1.1"

snmpBulkWalkSource

Arguments

:: Hostname

IP or hostname of the agent to be queried. May have prefix of tcp: or suffix of :port

-> Community

SNMP community (password)

-> String

OID to be queried

-> IO (Either String [SnmpResult]) 

Same as snmpWalk but implemented with bulk requests

Examples:

  • snmpBulkWalk "localhost" "public" ".1.3.6.1.2.1.1"
  • snmpBulkWalk "tcp:localhost:5161" "mypassword" ".1.3.6.1.2.1.1"

Miscellany

showASNValue :: ASNValue -> StringSource

Show ASNValue contents in a simple string, losing type differentiation. Callers should not rely on the format of the message returned, and this function may disappear in a future version.