Giter Site home page Giter Site logo

snmp's Introduction

snmp

Build Status Gitter chat

This is library for work with SNMPv2, SNMPv3.

It can be usefull if you need write agent or server.

Usage example:

import Data.ByteString (ByteString)
import Control.Exception (bracket, try)

import Network.Snmp.Client
import Network.Protocol.Snmp

-- For SNMPv3
conf2 :: Config
conf2 = (initial Version2) { hostname = "salt" 
                           , community = Community "helloall"
                           } 

-- For SNMPv3
conf3 :: Config
conf3 = (initial Version3) { hostname = "salt" 
                           , sequrityName = "aes"
                           , authPass = "helloallhello"
                           , privPass = "helloallhello"
                           , authType = SHA
                           , privType = AES
                           , sequrityLevel = AuthPriv
                           } 
-- do io 
client3 :: IO ()
client3 = bracket (client conf3)
                  close
                  requests

client2 :: IO ()
client2 = bracket (client conf2)
                  close
                  requests

-- Describe oids which you need
root, eth0, tabl, ipAddr, zeroDotZero :: [Integer]
root = [1,3,6,1,2,1,2,2,1,2]
eth0 = [1,3,6,1,2,1,2,2,1,2,1]
tabl = [31,1,1,1,1]
ipAddr = [1,3,6,1,2,1,4,22,1,3,3,192,168,3,1]
zeroDotZero = [1,3,6,1,2,1,2,2,1,22,20]

oi, sysUptime, memory, sysContact, bad, testOid :: ByteString
oi = ".1.3.6.1.2.1.1.9.1.2.1"
sysUptime = "1.3.6.1.2.1.25.1.1.0"
memory = "1.3.6.1.2.1.25.2"
sysContact = "1.3.6.1.2.1.1.4.0"
bad = "1.4.6.1.2.1.1.4"
testOid = "1.3.6.1.2.1.25.1.1.0"

-- Describe requests
requests :: Client -> IO ()
requests snmp = do
    print "get request"
    putStr . show =<< get snmp [oidFromBS testOid]
    putStr . show =<< get snmp [oidFromBS testOid]
    putStr . show =<< get snmp [oidFromBS sysUptime, oidFromBS oi, zeroDotZero]
    print "bulkget request"
    putStr . show =<< bulkget snmp [oidFromBS sysUptime]
    print "getnext request"
    putStr . show =<< getnext snmp [oidFromBS sysUptime]
    print "walk memory"
    putStr . show =<< walk snmp [oidFromBS memory]
    print "bulkwalk memory"
    putStr . show =<< bulkwalk snmp [oidFromBS memory]
    print "get sysContact"
    putStr . show =<< get snmp [oidFromBS sysContact]
    print "set sysContact"
    putStr . show =<< (try $ set snmp (Suite [Coupla (oidFromBS sysContact) (String "hello all")]) :: IO (Either ClientException Suite))
    print "get sysContact"
    putStr . show =<< get snmp [oidFromBS sysContact]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.