View previous topic :: View next topic |
Author |
Message |
Jax
Joined: 12 Jan 2004 Posts: 13
|
Posted: Mon Jan 12, 2004 7:53 pm Post subject: VBS on HS |
|
|
Hi There,
First I'd like to introduce myself, I am new to this forum and am currently evaluation AHM, so far it looks good however we would like to do a few more things with it and it seems we will need to do some scripting which I'll be happy to contribute to the board when they are done.
Perhaps I am missing something obvious be it seems we cant use any of the WScript methods here is a piece of code at its simplest
FUNCTION PerformTest()
WScript.Sleep(100) '<-- Line 13
PerformTest = "Null"
END FUNCTION
I am getting the error:
Error in script:
Error number :424
Source :Microsoft VBScript runtime error
Description :Object required: 'WScript'
Text :
Line :13
Column :0
Also I need to get SNMP values from the VBS I tried OlePRN.OleSNMP but it seems to have bugs and read the values as long instead of doubles and overflows the VB counters so I had to revert to use an external snmpget.exe or snmputil.exe and capture stdout to get the result inside the vbs.
Has anyone got a more elegant way to do things ? like using an activex control or other ?
Thanks |
|
Back to top |
|
|
Marcus
Joined: 18 Nov 2002 Posts: 367
|
Posted: Tue Jan 13, 2004 2:31 am Post subject: |
|
|
HostMonitor does not interfere with scripting. Most likely your problem is not *on* line 13, but detected on line 13. Search your code above these statements. |
|
Back to top |
|
|
Guest
|
Posted: Tue Jan 13, 2004 5:48 am Post subject: |
|
|
Hi Marcus, thanks for the reply,
That is all the code, a one line script plus constants. I researched a bit more and it seems HM wants WScript to be instantiated but it cant be instantiated because it is at the root of the DOM.
As stated before perhaps I am missing something obvious, else the VB scripting capabilities are seriously reduced.
Here is the full script
const statusAlive = "Host is alive:"
const statusDead = "No answer:"
const statusUnknown = "Unknown:"
const statusNotResolved = "Unknown host:"
const statusOk = "Ok:"
const statusBad = "Bad:"
const statusBadContents = "Bad contents:"
FUNCTION PerformTest()
WScript.Sleep(100) '<-- Line 13
PerformTest = "Null"
END FUNCTION
ps: I tried with wsh 5.1 and 5.6 |
|
Back to top |
|
|
Marcus
Joined: 18 Nov 2002 Posts: 367
|
Posted: Tue Jan 13, 2004 7:23 am Post subject: |
|
|
It runs fine on my installation. Do you have HM running as a service or as an application?
I start the script as an external application with "cscript //B <full path to script>
The only thin I can think of is that you have some kind of output to the screen, which does not run completely due to the fact HM is running under a non system account and therefore has no access to screen output. If so you can test it by running HM as application. |
|
Back to top |
|
|
Jax
Joined: 12 Jan 2004 Posts: 13
|
Posted: Tue Jan 13, 2004 7:52 am Post subject: |
|
|
I run HM as an app not service
I assume you then run "External program" instead of "Script"
Running external program I assume any valid VB script would work but you can only send an error code back to HM and not a value.
I can run VB scripts that have output to a dos window as "Script" and read stdout for the result that works, (with the anoying popup and disappear dos window but it works). However any method from WScript.xx eg WScript.Sleep WScript.echo will not work, something up in the DOM I can instantiate and it will work eg: WScript.Shell.
Folowing code returns an snmp value to HM (you need snmpget.exe and the hostname or IP in the comments line 1) and works fine
const statusAlive = "Host is alive:"
const statusDead = "No answer:"
const statusUnknown = "Unknown:"
const statusNotResolved = "Unknown host:"
const statusOk = "Ok:"
const statusBad = "Bad:"
const statusBadContents = "Bad contents:"
FUNCTION PerformTest()
target = "%CommentLine1%"
community = "public"
oid = ".1.3.6.1.2.1.2.2.1.10.1"
prog = "snmpget.exe"
snmpcmd = prog & " " & target & " " & community & " " & oid
Set WshShell = CreateObject("WScript.Shell")
set oExec = WshShell.Exec(snmpcmd)
sStdOut = oExec.StdOut.ReadAll
'Catch error if the oid is wrong
IF Left(sStdout,9) = "<No Data>" THEN
status = statusBad
value = ""
ELSE 'Catch the error if the community is wrong
IF Left(sStdout,5) = "Error" THEN
status = statusBad
value = ""
ELSE ' Catch the error if it cant contact the host
IF Left(sStdout,11) = "SnmpMgrOpen" THEN
status = statusBad
value = ""
ELSE ' Catch the error if command line parameters are invalid
IF Mid(sStdout,3,7) = "SNMPGET" THEN
status = statusBad
value = ""
ELSE
status = statusOk
value = sStdout
END IF
END IF
END IF
END IF
PerformTest = status+value 'return the Status and Value to HM
END FUNCTION
Now add the line "WScript.Sleep(500)" somewhere in it and it does not work anymore.
Weird.... |
|
Back to top |
|
|
Marcus
Joined: 18 Nov 2002 Posts: 367
|
Posted: Tue Jan 13, 2004 8:22 am Post subject: |
|
|
Running it as a script gives me the same results as yours. Error when checking under HM and running OK when from the command line.
It's Alex's turn , since you could call this a 'reproducable' problem.
It will only run correctly when started as an external application. So I have to say my first reaction was not correct. It seems HM is not calling the script environment correctly. |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12807 Location: USA
|
Posted: Tue Jan 13, 2004 11:16 pm Post subject: |
|
|
Yeah, something wrong here...
Ok, we can work in 2 directions:
- check what is wrong with "Script" test
- finish implementation of new "Shell Script" test. This test already works, it can be performed by HostMonitor, RMA for Windows, RMA for UNIX. We just need to finish GUI, and (what needs most of time manual and help file.
So, probably 2 weeks. Ok, ok, as usually release will need more time because we will find something importand to fix/add/modify... lets say 3 weeks
Advantages? You will be able to start your script as external program (like External test) using any command line (e.g "cmd /c cscript /B /E:VBScript %Script%"). So, your script will work (I just checked "WScript.sleep(100)", it works), DOS window will not appear. And your script will be able to return status and reply values, just like "Script" test does. Also you will be able to use BAT files on Windows systems, script files on UNIX systems, and custom executable modules as well.
Regards
Alex |
|
Back to top |
|
|
Marcus
Joined: 18 Nov 2002 Posts: 367
|
Posted: Wed Jan 14, 2004 2:46 am Post subject: |
|
|
I would say the "Shell Script" test. |
|
Back to top |
|
|
Jax
Joined: 12 Jan 2004 Posts: 13
|
Posted: Wed Jan 14, 2004 6:11 am Post subject: |
|
|
At this time I am only evaluating the product so I am not pressed to get that thing working and the developpement should really go in the way of the current users.
In any case it makes more sense to look forward rather than to fix something that will be replaced.
Thanks for looking at it so promptly |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12807 Location: USA
|
Posted: Wed Jan 14, 2004 3:01 pm Post subject: |
|
|
Actually "Script" test will be kept in future versions as well, and we will try to fix this problem later.
Regards
Alex |
|
Back to top |
|
|
|