Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3478
  • Last Modified:

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.

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
Cerixus
Asked:
Cerixus
  • 9
  • 4
  • 2
  • +2
2 Solutions
 
TheCapedPlodderCommented:
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
 
CerixusAuthor Commented:
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
 
purplepomegraniteCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TheCapedPlodderCommented:
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
 
CerixusAuthor Commented:
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
 
purplepomegraniteCommented:
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
 
wingateslCommented:
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
 
CerixusAuthor Commented:
@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
 
CerixusAuthor Commented:
@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
 
purplepomegraniteCommented:
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
 
CerixusAuthor Commented:
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
 
purplepomegraniteCommented:
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
 
CerixusAuthor Commented:
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
 
CerixusAuthor Commented:
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
 
CerixusAuthor Commented:
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
 
CerixusAuthor Commented:
purplepomegranite:

Please reply to my other post (linked in original post here) for your other 500 points.
0
 
bala11pCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now