Link to home
Start Free TrialLog in
Avatar of Cerixus
CerixusFlag for United States of America

asked on

Use VBScript to pull SNMP data from Cisco devices

I asked this in the ASP area, because that's ultimately what I'll be using, but since I haven't had a single response in 3 days (first time ever on EE) I thought I'd post here too.

Basically, as the title says, it's a straightforward problem.  I just want to be able to use SNMP to get information from a cisco device and display it in a webpage.  ASP/VBS is preferred.

https://www.experts-exchange.com/questions/23502567/ASP-page-to-pull-information-from-Cisco-routers-switches.html
Answer either question, get 500 points for both (1000 total)
Avatar of TheCapedPlodder
TheCapedPlodder
Flag of United Kingdom of Great Britain and Northern Ireland image

I'm not aware of a method for accessing standards based SNMP devices such as Cisco equipment.  You can query SNMP from Windows Hosts using WMI but this won't fly with Cisco gear.

Instead how about using a decent Syslog tool such as Kiwi and then create simple ASP or VBScript queries against the syslog text files?

Much neater and saves you querying each and every Cisco device when you can collate the data in one location.

Cheers,

TCP
Avatar of Cerixus

ASKER

That's actually what we're doing now.  But eventually we'd like realtime stats without the "middle man" and possibly even snmp changes from the internal site.
ASKER CERTIFIED SOLUTION
Avatar of purplepomegranite
purplepomegranite
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fair enough.

Well I don't think you will achieve this with VBScript but I can't comment with certainty on ASP.

You may want to invest in a pro-active Cisco monitoring tool such as CiscoWorks, or preferably SolarWinds.  If you are on a budget What's Up Gold offers some good pro-active monitoring options.

Good luck,

Cheers,

TCP
Avatar of Cerixus

ASKER

I already tried that, but I'm not exactly sure how to impliment it.  I created a private function using the code in your link, but when I call it nothing happens.  I have verified the OID and community string by using SNMPGET manually, but when I call it from the script it returns nothing at all.

Perhaps a step-by-step walkthrough?
By this do you mean that when you use SNMPGET manually (from the command line, for example), then the data is returned, but when you use the script there doesn't seem to be any data?
WinSNMP works great. Here is an example application
http://www.codeproject.com/KB/vb/VBDNFW2SNMP.aspx
Just tested it on my local router and it works.
Avatar of Cerixus

ASKER

@purplepomegranite: exactly.   I have his code in a file called snmp.asp, then I have this in snmptest.asp:

     <%@LANGUAGE="VBSCRIPT"%>
     <!--#include file="snmp.asp" -->
     <%
     %>
     SNMP TESTS:
     
     <%
     
     call snmpget("hostname","communitystring","1.3.6.1.4.1.232.11.2.3.1.1.2.0")%>
     <%=snmpget("hostname","communitystring","1.3.6.1.4.1.232.11.2.3.1.1.2.0")%>
     
     <%
     %>

I called it two different ways just for fun... also, "hostname" and "communitystring" are replaced with valid names and strings, as I said I can run SNMPGET from a command line (on the server the script is hosted on) and get the proper results.
Avatar of Cerixus

ASKER

@wingatesl:

I don't have visual studio or  anything, and wouldn't even know where to be begin implementing all those com  objects and such...
You may have picked up on this already, but just in case... the CreateObject calls in his code need to be modified to server.createobject for asp, as attached.  Have you already changed them?
<%
Function SNMPGET(vServer, vCommunityString, vOID)
    On Error Resume Next
 
    'This function will return the data from an SNMP get from the specified 
    'server and the specified OID. The information will have to be parsed 
    'afterward. The info will be retuned as the string or variable "SNMPGET".
    'This script is provided under the Creative Commons license located
    'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
    'be used for commercial purposes with out the expressed written consent
    'of NateRice.com
 
    Const OpenAsDefault = -2
    Const FailIfNotExist = 0
    Const ForReading = 1
    
    vSNMPGetPath = "C:\ScriptFiles" 'Set path to snmpget.exe
 
    Set WshShell = Server.CreateObject("WScript.Shell") 'Create filesystem objects
    sTemp = WshShell.ExpandEnvironmentStrings("%TEMP%")
    sTempFile = sTemp & "\runresult.tmp" 'Create working file string
    
    'Run the SNMPGET command and save results to tmp file
    WshShell.Run "%comspec% /C " & vSNMPGetPath & "\snmpget -c " & _
    vCommunityString & " -v 1 " & vServer & " " & vOID & " > " & _
    sTempFile, 0, True
 
    'Read tmp file for snmpget results
    Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, _
    OpenAsDefault)
    
    SNMPGET = fFile.Readline
    
    If InStr(SNMPGET, "STRING:") > 0 Then
        aSNMPGET = Split(SNMPGET, "STRING:")
        vTemp = Replace(Trim(aSNMPGET(1)), Chr(34), "")
        SNMPGET = vTemp
    ElseIf InStr(SNMPGET, "INTEGER:") > 0 Then
        aSNMPGET = Split(SNMPGET, "INTEGER:")
        vTemp = Trim(aSNMPGET(1))
        vTemp = vTemp + 0
        SNMPGET = vTemp
    ElseIf InStr(SNMPGET, "IpAddress:") > 0 Then
        aSNMPGET = Split(SNMPGET, "IpAddress:")
        vTemp = Trim(aSNMPGET(1))
        SNMPGET = vTemp
    End If
        
    
    fFile.Close
    oFSO.DeleteFile (sTempFile)
    
End Function
%>

Open in new window

Avatar of Cerixus

ASKER

Hmm, no, I hadn't done that... but just for troubleshooting purposes, here is what I have right now.

     <%
         set wshell = Server.CreateObject("WScript.Shell")
         wshell.run "%comspec% /C c:\testing.bat", 0, TRUE
         set wshell = nothing
     %>

This also does nothing.  Testing.bat  just runs "dir >c:\testing.txt".  If I execute the batch file manually, it creates the text file.  If I run the ASP above, it does nothing.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cerixus

ASKER

Okay, I've taken that approach and Im' pretty sure it's not permissions.  Tried a frew different folders, including a couple under intetpub/webroot, making sure IUSR_servername account had full control.  Still didn't work.  So, doing some testing, I  tried simply running "%comspec% /C C:\Inetpub\wwwroot\SNMPGET\testing.bat" from a command line or the run prompt.  The contents of the batch file are simply "dir >test.txt" but when I run the above command manually, the output echoed is "C:\>dir  1>test.txt"

Where is the 1 coming from???
Avatar of Cerixus

ASKER

Based on another EE question, I changed my code to this:

    <%
          Dim wshell, intReturn
          set wshell = server.createobject("wscript.shell")
          intReturn = wshell.run("%comspec% /c dir *.* > c:\test.txt", 0, True)
          Response.Write( intReturn )
          set wshell = nothing
     %>

It outputs a "1".  What does that mean?
Avatar of Cerixus

ASKER

I think I got it to work... I gave EVERY single local group full control of the folder and it worked... now I just need to figure out which one made it work, but it definitely was not the IUSR_servername account :(
Avatar of Cerixus

ASKER

purplepomegranite:

Please reply to my other post (linked in original post here) for your other 500 points.
Avatar of bala11p
bala11p

I need some help in gettin the SNMP strings from the cisco devices. I need some one who can help me to get the information using the above script.