Solved

Use VBScript to pull SNMP data from Cisco devices

Posted on 2008-06-23
17
3,140 Views
Last Modified: 2010-08-30
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.

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_23502567.html
Answer either question, get 500 points for both (1000 total)
0
Comment
Question by:Cerixus
  • 9
  • 4
  • 2
  • +2
17 Comments
 
LVL 13

Expert Comment

by:TheCapedPlodder
Comment Utility
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
0
 
LVL 1

Author Comment

by:Cerixus
Comment Utility
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.
0
 
LVL 24

Accepted Solution

by:
purplepomegranite earned 500 total points
Comment Utility
You can query standard SNMP using a third-party tool.  There is a good example here: http://www.naterice.com/blog/template_permalink.asp?id=4
0
 
LVL 13

Expert Comment

by:TheCapedPlodder
Comment Utility
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
0
 
LVL 1

Author Comment

by:Cerixus
Comment Utility
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?
0
 
LVL 24

Expert Comment

by:purplepomegranite
Comment Utility
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?
0
 
LVL 15

Expert Comment

by:wingatesl
Comment Utility
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.
0
 
LVL 1

Author Comment

by:Cerixus
Comment Utility
@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.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:Cerixus
Comment Utility
@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...
0
 
LVL 24

Expert Comment

by:purplepomegranite
Comment Utility
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

0
 
LVL 1

Author Comment

by:Cerixus
Comment Utility
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.
0
 
LVL 24

Assisted Solution

by:purplepomegranite
purplepomegranite earned 500 total points
Comment Utility
Ah, it may well be a rights issue... the IUSR account won't have permissions to create a file on the root of the c drive (at least, it certainly shouldn't!!).

Can you create a new folder on c and give the IUSR account(s) permission to write to the folder, then move the bat file into the folder and change the code above accordingly.  I believe that scripts, etc. called from ASP all run in the IUSR account for security.
0
 
LVL 1

Author Comment

by:Cerixus
Comment Utility
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???
0
 
LVL 1

Author Comment

by:Cerixus
Comment Utility
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?
0
 
LVL 1

Author Comment

by:Cerixus
Comment Utility
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 :(
0
 
LVL 1

Author Comment

by:Cerixus
Comment Utility
purplepomegranite:

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

Expert Comment

by:bala11p
Comment Utility
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Tired of waiting for your show or movie to load?  Are buffering issues a constant problem with your internet connection?  Check this article out to see if these simple adjustments are the solution for you.
Creating an OSPF network that automatically (dynamically) reroutes network traffic over other connections to prevent network downtime.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now