<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: snmpget, snmptrap - Splunk and SNMP polling in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81476#M16819</link>
    <description>&lt;P&gt;Here is a simple quick and dirty prototype of an snmp manager I've written using pysnmp.&lt;/P&gt;

&lt;P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;BR /&gt;
from pysnmp.entity import engine, config&lt;BR /&gt;
from pysnmp.carrier.asynsock.dgram import udp&lt;BR /&gt;
from pysnmp.entity.rfc3413 import cmdgen&lt;BR /&gt;
from pysnmp.smi import builder, view, error&lt;BR /&gt;
from time import localtime, strftime&lt;BR /&gt;
import sys, os &lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;H1&gt;parses response from getoidval&lt;/H1&gt;

&lt;P&gt;def cbFun(sendRequestHandle, errorIndication, errorStatus, errorIndex,varBinds, cbCtx): &lt;BR /&gt;
    cbCtx['errorIndication'] = errorIndication&lt;BR /&gt;
    cbCtx['errorStatus'] = errorStatus&lt;BR /&gt;
    cbCtx['varBinds'] = varBinds &lt;BR /&gt;
    return 1  # will countine if using bulk or next&lt;/P&gt;

&lt;H1&gt;gets oid and value&lt;/H1&gt;

&lt;P&gt;def getoidval(agentname, params, communitystr, targetadd, targetport, targetoid):&lt;BR /&gt;
    snmpEngine = engine.SnmpEngine()&lt;BR /&gt;
    #transport and snmpv2 setup&lt;BR /&gt;
    config.addV1System(snmpEngine, agentname, communitystr)&lt;BR /&gt;
    config.addTargetParams(snmpEngine, params, agentname, 'noAuthNoPriv', 1)&lt;BR /&gt;
    config.addTargetAddr( snmpEngine, targetname, config.snmpUDPDomain,(targetadd, targetport), params)&lt;BR /&gt;
    config.addSocketTransport(snmpEngine,config.snmpUDPDomain,udp.UdpSocketTransport().openClientMode())&lt;BR /&gt;&lt;BR /&gt;
    #test = cmdgen.NextCommandGenerator().sendReq(snmpEngine, targetname, ((targetoid, None),), cbFun)&lt;BR /&gt;
    cbCtx = {}&lt;BR /&gt;
    cmdgen.GetCommandGenerator().sendReq(snmpEngine, targetname, ((targetoid, None),), cbFun, cbCtx)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;snmpEngine.transportDispatcher.runDispatcher()
return  cbCtx
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;H1&gt;generates tsv file for all oid give for target&lt;/H1&gt;

&lt;P&gt;def gensnmbtsv(agentname, params, communitystr, targetadd, targetport, lstoid,basepath, filename):&lt;BR /&gt;
    mibView = view.MibViewController(mibBuilder)&lt;BR /&gt;
    lstreturn = []&lt;BR /&gt;
    localdate = strftime("_%Y-%m%d", localtime())&lt;BR /&gt;
    timestamp = strftime("%Y-%m-%d\t%H:%M\t",localtime())&lt;BR /&gt;
    header = 'date time\t'&lt;BR /&gt;
    value = timestamp&lt;BR /&gt;
    tsvname = basepath + filename + localdate + '.tsv'&lt;BR /&gt;
    errname= basepath + filename + 'Err.log'&lt;BR /&gt;
    for targetoid in lstoid:&lt;BR /&gt;&lt;BR /&gt;
        dictoidval = {}&lt;BR /&gt;
        returnoid = getoidval(agentname, params, communitystr, targetadd, targetport, targetoid)&lt;BR /&gt;
        if returnoid['errorIndication']:&lt;BR /&gt;
            errfile = open(errname, 'a')&lt;BR /&gt;
            errfile.write(timestamp+str(returnoid['errorIndication']) + '\n')&lt;BR /&gt;
            print str(returnoid['errorIndication'])&lt;BR /&gt;
            errfile.close()&lt;BR /&gt;
            sys.exit(12)&lt;BR /&gt;
        elif returnoid['errorStatus']:&lt;BR /&gt;
            errfile = open(errname, 'a')&lt;BR /&gt;
            errfile.write(timestamp+str(returnoid['errorStatus']) + '\n')&lt;BR /&gt;
            print str(returnoid['errorStatus'])&lt;BR /&gt;
            errfile.close()&lt;BR /&gt;
            sys.exit(12)&lt;BR /&gt;
        else:&lt;BR /&gt;
            try:&lt;BR /&gt;
                oid, labels, suffix = mibView.getNodeName(returnoid['varBinds'][0][0])&lt;BR /&gt;
                dictoidval[labels[-1]] = str(returnoid['varBinds'][0][1])&lt;BR /&gt;
                lstreturn.append(dictoidval)&lt;BR /&gt;
            except:&lt;BR /&gt;
                print 'Unable to find label associated with oid.  Make sure you have loaded all necessary .py MIB definitions. This can done by using  builder.MibBuilder().loadModules.'&lt;BR /&gt;
                sys.exit(12)&lt;BR /&gt;
    for i in range(len(lstreturn)):&lt;BR /&gt;
        header += lstreturn[i].keys()[0] + '\t'&lt;BR /&gt;
        value += lstreturn[i].values()[0] + '\t'&lt;BR /&gt;
    tsvfile = basepath + filename + localdate&lt;BR /&gt;
    if not (os.path.exists(tsvname)):&lt;BR /&gt;
        tsvfile =open(tsvname, 'w')&lt;BR /&gt;
        tsvfile.write(header.lower() + '\n' + value +'\n')&lt;BR /&gt;
        tsvfile.close()&lt;BR /&gt;
    else:&lt;BR /&gt;
        tsvfile =open(tsvname, 'a')&lt;BR /&gt;
        tsvfile.write(value + '\n')&lt;BR /&gt;
        tsvfile.close()&lt;/P&gt;

&lt;H1&gt;Main&lt;/H1&gt;

&lt;H1&gt;########################&lt;/H1&gt;

&lt;H1&gt;Set alternative location of mib sources and loads mibs&lt;/H1&gt;

&lt;P&gt;mibsource = '&amp;lt;pysnmpMibDir&amp;gt;/mib'&lt;BR /&gt;
mibBuilder = builder.MibBuilder()&lt;BR /&gt;
mibPath = mibBuilder.getMibSources() + (builder.DirMibSource(mibsource),)&lt;BR /&gt;
mibBuilder.setMibSources(*mibPath)&lt;BR /&gt;
mibBuilder.loadModules('MSFT-MIB','WINDOWS-NT-PERFORMANCE','SNMPv2-TC','RFC1213-MIB','RFC1155-SMI','RFC1158-MIB','RFC1354-MIB','MSFT-MIB','WINS-MIB','InternetServer-MIB','HTTPSERVER-MIB')&lt;/P&gt;

&lt;P&gt;agentname = ''&lt;BR /&gt;
params = ''&lt;BR /&gt;
targetname = ''&lt;BR /&gt;
communitystr = ''&lt;BR /&gt;
targetadd = ''&lt;BR /&gt;
targetport = 161&lt;BR /&gt;
lstoid =  ['1.3.6.1.4.1.311.1.7.3.1.14.0',&lt;BR /&gt;
                '1.3.6.1.4.1.311.1.7.3.1.15.0',&lt;BR /&gt;
                '1.3.6.1.4.1.311.1.7.3.1.16.0',&lt;BR /&gt;
                '1.3.6.1.4.1.311.1.7.3.1.17.0',&lt;BR /&gt;
                '1.3.6.1.4.1.311.1.7.3.1.18.0',]&lt;BR /&gt;
basepath = '&amp;lt;script path/python/snmp/&amp;gt;' # Where error and out put wil be placed&lt;BR /&gt;
filename = '&amp;lt;somename&amp;gt;' # file will be a tsv with current data appended&lt;/P&gt;

&lt;P&gt;gensnmbtsv(agentname, params, communitystr, targetadd, targetport, lstoid,basepath, filename)&lt;/P&gt;

&lt;P&gt;sys.exit(0)&lt;BR /&gt;
&lt;/P&gt;</description>
    <pubDate>Thu, 20 Sep 2012 21:20:27 GMT</pubDate>
    <dc:creator>bmacias84</dc:creator>
    <dc:date>2012-09-20T21:20:27Z</dc:date>
    <item>
      <title>snmpget, snmptrap - Splunk and SNMP polling</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81472#M16815</link>
      <description>&lt;P&gt;I am looking for resources on how to poll e.g. Cisco ASA firewalls via snmp (snmpget) from Splunk. I would like to pull things like interface usage, RAM usage, CPU usage etc, anything that can be gathered via SNMP. &lt;/P&gt;

&lt;P&gt;Is it something along the lines of scripting snmpgets, writing output into a file on the splunk server and then pulling the data out?&lt;/P&gt;

&lt;P&gt;Does anyone have any good examples for this?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2011 05:30:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81472#M16815</guid>
      <dc:creator>splunker30039</dc:creator>
      <dc:date>2011-04-14T05:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: snmpget, snmptrap - Splunk and SNMP polling</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81473#M16816</link>
      <description>&lt;P&gt;I don't have a good example, but yes it's fundamentally how you describe it - define a scripted input into Splunk that runs your script to do the various &lt;CODE&gt;snmpget&lt;/CODE&gt; commands and format their output.&lt;/P&gt;

&lt;P&gt;One thing to consider might be that Cisco has always been a little skimpy in their PIX/ASA MIBS.  The stuff you're looking for might not be available via SNMP - but you could always resort to something like expect.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2011 06:53:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81473#M16816</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2011-04-14T06:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: snmpget, snmptrap - Splunk and SNMP polling</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81474#M16817</link>
      <description>&lt;P&gt;I could need some pointers on how to do that, tbh. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2011 08:40:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81474#M16817</guid>
      <dc:creator>splunker30039</dc:creator>
      <dc:date>2011-04-14T08:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: snmpget, snmptrap - Splunk and SNMP polling</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81475#M16818</link>
      <description>&lt;P&gt;This is something that I'll try to look into when I have time.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2011 05:01:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81475#M16818</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2011-04-15T05:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: snmpget, snmptrap - Splunk and SNMP polling</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81476#M16819</link>
      <description>&lt;P&gt;Here is a simple quick and dirty prototype of an snmp manager I've written using pysnmp.&lt;/P&gt;

&lt;P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;BR /&gt;
from pysnmp.entity import engine, config&lt;BR /&gt;
from pysnmp.carrier.asynsock.dgram import udp&lt;BR /&gt;
from pysnmp.entity.rfc3413 import cmdgen&lt;BR /&gt;
from pysnmp.smi import builder, view, error&lt;BR /&gt;
from time import localtime, strftime&lt;BR /&gt;
import sys, os &lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;H1&gt;parses response from getoidval&lt;/H1&gt;

&lt;P&gt;def cbFun(sendRequestHandle, errorIndication, errorStatus, errorIndex,varBinds, cbCtx): &lt;BR /&gt;
    cbCtx['errorIndication'] = errorIndication&lt;BR /&gt;
    cbCtx['errorStatus'] = errorStatus&lt;BR /&gt;
    cbCtx['varBinds'] = varBinds &lt;BR /&gt;
    return 1  # will countine if using bulk or next&lt;/P&gt;

&lt;H1&gt;gets oid and value&lt;/H1&gt;

&lt;P&gt;def getoidval(agentname, params, communitystr, targetadd, targetport, targetoid):&lt;BR /&gt;
    snmpEngine = engine.SnmpEngine()&lt;BR /&gt;
    #transport and snmpv2 setup&lt;BR /&gt;
    config.addV1System(snmpEngine, agentname, communitystr)&lt;BR /&gt;
    config.addTargetParams(snmpEngine, params, agentname, 'noAuthNoPriv', 1)&lt;BR /&gt;
    config.addTargetAddr( snmpEngine, targetname, config.snmpUDPDomain,(targetadd, targetport), params)&lt;BR /&gt;
    config.addSocketTransport(snmpEngine,config.snmpUDPDomain,udp.UdpSocketTransport().openClientMode())&lt;BR /&gt;&lt;BR /&gt;
    #test = cmdgen.NextCommandGenerator().sendReq(snmpEngine, targetname, ((targetoid, None),), cbFun)&lt;BR /&gt;
    cbCtx = {}&lt;BR /&gt;
    cmdgen.GetCommandGenerator().sendReq(snmpEngine, targetname, ((targetoid, None),), cbFun, cbCtx)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;snmpEngine.transportDispatcher.runDispatcher()
return  cbCtx
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;H1&gt;generates tsv file for all oid give for target&lt;/H1&gt;

&lt;P&gt;def gensnmbtsv(agentname, params, communitystr, targetadd, targetport, lstoid,basepath, filename):&lt;BR /&gt;
    mibView = view.MibViewController(mibBuilder)&lt;BR /&gt;
    lstreturn = []&lt;BR /&gt;
    localdate = strftime("_%Y-%m%d", localtime())&lt;BR /&gt;
    timestamp = strftime("%Y-%m-%d\t%H:%M\t",localtime())&lt;BR /&gt;
    header = 'date time\t'&lt;BR /&gt;
    value = timestamp&lt;BR /&gt;
    tsvname = basepath + filename + localdate + '.tsv'&lt;BR /&gt;
    errname= basepath + filename + 'Err.log'&lt;BR /&gt;
    for targetoid in lstoid:&lt;BR /&gt;&lt;BR /&gt;
        dictoidval = {}&lt;BR /&gt;
        returnoid = getoidval(agentname, params, communitystr, targetadd, targetport, targetoid)&lt;BR /&gt;
        if returnoid['errorIndication']:&lt;BR /&gt;
            errfile = open(errname, 'a')&lt;BR /&gt;
            errfile.write(timestamp+str(returnoid['errorIndication']) + '\n')&lt;BR /&gt;
            print str(returnoid['errorIndication'])&lt;BR /&gt;
            errfile.close()&lt;BR /&gt;
            sys.exit(12)&lt;BR /&gt;
        elif returnoid['errorStatus']:&lt;BR /&gt;
            errfile = open(errname, 'a')&lt;BR /&gt;
            errfile.write(timestamp+str(returnoid['errorStatus']) + '\n')&lt;BR /&gt;
            print str(returnoid['errorStatus'])&lt;BR /&gt;
            errfile.close()&lt;BR /&gt;
            sys.exit(12)&lt;BR /&gt;
        else:&lt;BR /&gt;
            try:&lt;BR /&gt;
                oid, labels, suffix = mibView.getNodeName(returnoid['varBinds'][0][0])&lt;BR /&gt;
                dictoidval[labels[-1]] = str(returnoid['varBinds'][0][1])&lt;BR /&gt;
                lstreturn.append(dictoidval)&lt;BR /&gt;
            except:&lt;BR /&gt;
                print 'Unable to find label associated with oid.  Make sure you have loaded all necessary .py MIB definitions. This can done by using  builder.MibBuilder().loadModules.'&lt;BR /&gt;
                sys.exit(12)&lt;BR /&gt;
    for i in range(len(lstreturn)):&lt;BR /&gt;
        header += lstreturn[i].keys()[0] + '\t'&lt;BR /&gt;
        value += lstreturn[i].values()[0] + '\t'&lt;BR /&gt;
    tsvfile = basepath + filename + localdate&lt;BR /&gt;
    if not (os.path.exists(tsvname)):&lt;BR /&gt;
        tsvfile =open(tsvname, 'w')&lt;BR /&gt;
        tsvfile.write(header.lower() + '\n' + value +'\n')&lt;BR /&gt;
        tsvfile.close()&lt;BR /&gt;
    else:&lt;BR /&gt;
        tsvfile =open(tsvname, 'a')&lt;BR /&gt;
        tsvfile.write(value + '\n')&lt;BR /&gt;
        tsvfile.close()&lt;/P&gt;

&lt;H1&gt;Main&lt;/H1&gt;

&lt;H1&gt;########################&lt;/H1&gt;

&lt;H1&gt;Set alternative location of mib sources and loads mibs&lt;/H1&gt;

&lt;P&gt;mibsource = '&amp;lt;pysnmpMibDir&amp;gt;/mib'&lt;BR /&gt;
mibBuilder = builder.MibBuilder()&lt;BR /&gt;
mibPath = mibBuilder.getMibSources() + (builder.DirMibSource(mibsource),)&lt;BR /&gt;
mibBuilder.setMibSources(*mibPath)&lt;BR /&gt;
mibBuilder.loadModules('MSFT-MIB','WINDOWS-NT-PERFORMANCE','SNMPv2-TC','RFC1213-MIB','RFC1155-SMI','RFC1158-MIB','RFC1354-MIB','MSFT-MIB','WINS-MIB','InternetServer-MIB','HTTPSERVER-MIB')&lt;/P&gt;

&lt;P&gt;agentname = ''&lt;BR /&gt;
params = ''&lt;BR /&gt;
targetname = ''&lt;BR /&gt;
communitystr = ''&lt;BR /&gt;
targetadd = ''&lt;BR /&gt;
targetport = 161&lt;BR /&gt;
lstoid =  ['1.3.6.1.4.1.311.1.7.3.1.14.0',&lt;BR /&gt;
                '1.3.6.1.4.1.311.1.7.3.1.15.0',&lt;BR /&gt;
                '1.3.6.1.4.1.311.1.7.3.1.16.0',&lt;BR /&gt;
                '1.3.6.1.4.1.311.1.7.3.1.17.0',&lt;BR /&gt;
                '1.3.6.1.4.1.311.1.7.3.1.18.0',]&lt;BR /&gt;
basepath = '&amp;lt;script path/python/snmp/&amp;gt;' # Where error and out put wil be placed&lt;BR /&gt;
filename = '&amp;lt;somename&amp;gt;' # file will be a tsv with current data appended&lt;/P&gt;

&lt;P&gt;gensnmbtsv(agentname, params, communitystr, targetadd, targetport, lstoid,basepath, filename)&lt;/P&gt;

&lt;P&gt;sys.exit(0)&lt;BR /&gt;
&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2012 21:20:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81476#M16819</guid>
      <dc:creator>bmacias84</dc:creator>
      <dc:date>2012-09-20T21:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: snmpget, snmptrap - Splunk and SNMP polling</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81477#M16820</link>
      <description>&lt;P&gt;Check out this new add-on : &lt;A href="http://splunk-base.splunk.com/apps/88686/snmp-modular-input"&gt;http://splunk-base.splunk.com/apps/88686/snmp-modular-input&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2013 21:24:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/snmpget-snmptrap-Splunk-and-SNMP-polling/m-p/81477#M16820</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2013-05-28T21:24:04Z</dc:date>
    </item>
  </channel>
</rss>

