Cerixus
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)
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)
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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?
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.
http://www.codeproject.com/KB/vb/VBDNFW2SNMP.aspx
Just tested it on my local router and it works.
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","commun itystring" ,"1.3.6.1. 4.1.232.11 .2.3.1.1.2 .0")%>
<%=snmpget("hostname","com munitystri ng","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.
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="snmp.asp" -->
<%
%>
SNMP TESTS:
<%
call snmpget("hostname","commun
<%=snmpget("hostname","com
<%
%>
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.
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...
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
%>
ASKER
Hmm, no, I hadn't done that... but just for troubleshooting purposes, here is what I have right now.
<%
set wshell = Server.CreateObject("WScri pt.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.
<%
set wshell = Server.CreateObject("WScri
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.b at" 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???
Where is the 1 coming from???
ASKER
Based on another EE question, I changed my code to this:
<%
Dim wshell, intReturn
set wshell = server.createobject("wscri pt.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?
<%
Dim wshell, intReturn
set wshell = server.createobject("wscri
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?
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 :(
ASKER
purplepomegranite:
Please reply to my other post (linked in original post here) for your other 500 points.
Please reply to my other post (linked in original post here) for your other 500 points.
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.
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