Solved

Use VBScript to pull SNMP data from Cisco devices

Posted on 2008-06-23
17
3,328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
  • 2
  • +2
17 Comments
 
LVL 13

Expert Comment

by:TheCapedPlodder
ID: 21847266
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
ID: 21847362
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
ID: 21847404
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 13

Expert Comment

by:TheCapedPlodder
ID: 21847424
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
ID: 21847429
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
ID: 21847480
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
ID: 21847542
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
ID: 21847551
@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
 
LVL 1

Author Comment

by:Cerixus
ID: 21847577
@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
ID: 21847586
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
ID: 21847844
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
ID: 21847893
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
ID: 21848548
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
ID: 21848618
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
ID: 21848791
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
ID: 21848913
purplepomegranite:

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

Expert Comment

by:bala11p
ID: 33563850
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Description:   Couple of months ago we upgraded the ADSL line at our branch office from Home to Business line. The purpose of transforming the service to have static public IP’s. We were in need for public IP’s to publish our web resour…
I recently attended Cisco Live! in Las Vegas, a conference that boasted over 28,000 techies in attendance, and a week of hands-on learning hosted by a solid partner with which Concerto goes to market.  Every year, Cisco displays cutting-edge technol…
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…
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

623 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