npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typed-snmp-native

v1.3.6

Published

A native Javascript SNMP implementation for Node.js in Typescript

Downloads

281

Readme

Typed SNMP

Overview

This library is a TypeScript rewrite of the well-known snmp-native, which implements the SNMP protocol over native Node.js. The goal was to enhance the development experience and modernize some outdated standards from the original code.

Features

  • [X] SNMP V1
  • [X] SNMP V2
  • [X] Get Requests
  • [X] Set Requests
  • [X] Get Next Requests
  • [X] Get Bulk Requests
  • [X] Get Subtree
  • [X] Walk

Note: This library does not support SNMP v3 yet. Any help with this will be welcome.

Installation

npm install typed-native-snmp

Usage

This library supports using the provided methods in two forms: callbacks and promises.

Using Callbacks

To use the callback version, you need to import the Session.

import { Session, VarBind } from 'typed-native-snmp';

const session = new Session({
    host: '192.168.0.1',
    community: 'public',
    port: 161,
    version: 0
});

function callback(err: any, varbinds: VarBind[]): void {
    if (err) {
        throw err;
    }

    console.log(varbinds);
}

session.get({ oid: '1.3.2.1' }, callback);

session.close();

Using Promises

Using the promise version is just as easy; you just need to import the AsyncSession instead:

import { AsyncSession } from 'typed-native-snmp';

const session = new AsyncSession({
    host: '192.168.0.1',
    community: 'public',
    port: 161,
    version: 0
});

session.get({ oid: '1.3.2.1' })
    .then(varbinds => {
        console.log(varbinds);
    })
    .catch(err => {
        console.log(err);
    });

session.close();

Both the callback and promise versions have the same methods and implement the same types.

Configuration Options

The Session and AsyncSession constructors accept any valid instance of SessionOption. If no option is provided, the default values are:

const defaultOptions = {
    host: 'localhost',
    port: 161,
    bindPort: 0,
    community: 'public',
    family: 'udp4',
    timeouts: [5000, 5000, 5000, 5000],
    version: versions.SNMPv2c
};

The SessionOption also provides a method to parse the SNMP VarBinds received from the hardware as you want, with a method called msgReceived that must follow this type:

msgReceived: (msg: Buffer, rinfo: any) => any

If no custom message parser is provided, the default is to parse everything according to the ASN.1 rules.

Built-in Dictionaries

The package also comes with built-in dictionaries for all the ASN.1 types for request and response types, as well as the dictionaries for the errors that can occur in the communication between the software and the hardware you are managing.

All these dictionaries can be accessed using:

// Request and Response data types
import { types } from 'typed-native-snmp';

// PDU types
import { pduTypes } from 'typed-native-snmp';

// Request and Response errors
import { errors } from 'typed-native-snmp';

The Walk Method

The walk method works just like the standard getSubtree method but can be used with a function as a parameter to format or parse the received message as you need.

Contributing

First of all, a HUGE thanks to the original developer of the JavaScript library calmh and all the contributors who have helped this library so far:

I made this TypeScript library to use at work, so I only implemented what I needed to get tasks done. If you want to contribute, fork the project, create a branch for your code, and open a pull request to the master branch. Any help will be greatly appreciated.