Possible to use Java?
Possible to use Java?
I know it's possible to use Javascript, but javascript is a bit to limited for what I need (and my VBScript knowledge is not that extended).
So I was wondering if there's a possibility to use Java instead?
(Java is installed on the servers I have to monitor, that's not the problem.)
So I was wondering if there's a possibility to use Java instead?
(Java is installed on the servers I have to monitor, that's not the problem.)
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
I think, "Shell Script" and "External" test methods are able to launch java application. In case of "External" test method your application should return particular exit code in order to be processed by HostMonitor.
http://www.ks-soft.net/hostmon.eng/mfra ... m#execheck
In case of "Shell Script" test method, java application you start should write some information into console (e.g. ScriptRes:Ok:15) in order to suit requirements. http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
Regards,
Max
http://www.ks-soft.net/hostmon.eng/mfra ... m#execheck
In case of "Shell Script" test method, java application you start should write some information into console (e.g. ScriptRes:Ok:15) in order to suit requirements. http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
Regards,
Max
Thanks, fast answer
I've been able to create a .jar, it's running fine when I execute it manually (on the server with the remote agent).
Now, I created a new Shell Script with start cmd "C:\Location-of-file\Hello.jar %Params%". When I try to execute it, I get the following error:
Now, I have 3 questions:
The location of the file, should it be on the server that monitors or on the server that has the agent running?
If the file should be located on the server with the agent, can HM automate the distribution?
How do I fix the 301 - Error

I've been able to create a .jar, it's running fine when I execute it manually (on the server with the remote agent).
Now, I created a new Shell Script with start cmd "C:\Location-of-file\Hello.jar %Params%". When I try to execute it, I get the following error:
Code: Select all
[5:51:28 PM]Agent: Test is going to execute "Hello" script ...
[5:51:28 PM] Response from the agent: 301 - Error: unable to start script
The location of the file, should it be on the server that monitors or on the server that has the agent running?
If the file should be located on the server with the agent, can HM automate the distribution?
How do I fix the 301 - Error

-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
If test is performed by HostMonitor, file should be located on the machine, where HostMonitor is running. If test is performed by agent, file should be located on the machine, where agent is running.bbackx wrote:The location of the file, should it be on the server that monitors or on the server that has the agent running?
No. HostMonitor is not responsible for external files.bbackx wrote:If the file should be located on the server with the agent, can HM automate the distribution?
You program should suit requirements. Quote from the manual: http://www.ks-soft.net/hostmon.eng/test ... m#shellmngbbackx wrote:How do I fix the 301 - Error
=====================================
1. First obligatory part - marker "scriptres" tells to HostMonitor or RMA that this string is the result string.
2. Second obligatory part represents the test status, it can take one of the following values (case insensitive):
Status string Comment
Host is alive status means " script executed successfully, target system correctly responds"
No answer script executed successfully, target system does not respond
Unknown status means "test cannot be performed for some reason"
Unknown host use this status when script cannot resolve target host name into IP address
Ok script executed, result satisfies (some) requirements
Bad script executed, result does not satisfy (some) requirements
Bad contents use this status if script found some error in monitored file, web page, etc
3. Third optional part contains Reply value, HostMonitor displays this value in Reply field, writes to log files, uses to displays charts (Log Analyzer), etc. If you want Log Analyzer to process Reply values correctly and display charts, use one of the following formats for Reply value:
* decimal_number (like "123", "0", "6456.45". as decimal separator use symbol that is specified on your system, usually a dot (.) or a comma (,))
* decimal_number + space + "Kb" (like "512 Kb", "64 Kb")
* decimal_number + space + "Mb" (like "1024 Mb", "5 Mb")
* decimal_number + space + "Gb" (like "12 Gb", "4 Gb")
* decimal_number + space + "%" (like "50 %", "99 %")
* decimal_number + space + "ms" (like "100 ms", "5400 ms")
Several examples:
String printed by script "Status" of the test "Reply" field of the test
scriptres:Host is alive:1000 ms Host is alive 1000 ms
scriptres:Unknown host: Unknown host
scriptres:Ok:300 Kb Ok 300 Kb
scriptres:Bad:90 % Bad 90 %
=====================================
Regards,
Max
You cannot execute jar file in such simple way because its not an executable file. Its an archive. It cannot be executed directly by Windows like EXE files.C:\Location-of-file\Hello.jar %Params%
You need to install Java software and start application using jre or java tools (may be there are some other useful commands.. I am not Java guru).
I think you may use commands like
jre -cp C:\Location-of-file\Hello.jar MainClassName %Params%
java -jar C:\Location-of-file\Hello.jar %Params%
Probably the following book can be useful
http://java.sun.com/developer/Books/
http://java.sun.com/developer/Books/jav ... AR/basics/
Regards
Alex
Thanks for the help guys, I'm now at the point that the script executes fine (using java -jar file-location\test.jar), but I don't get any results ("no results received" according to HostMonitor).
I tried the 'normal' System.out.println and also via a PrintWriter(OutputStreamWriter).
The (test)string should be correct, I believe: "scriptres:Ok:100"
I'll search some more and try some other things, but if one of you has a brilliant idea, I'm not stopping you
I tried the 'normal' System.out.println and also via a PrintWriter(OutputStreamWriter).
The (test)string should be correct, I believe: "scriptres:Ok:100"
I'll search some more and try some other things, but if one of you has a brilliant idea, I'm not stopping you

-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
Ok, let's start from scratch. Below you can see the source of myfirstjavaprog.java class, that is located in E:\temp\Java\ folder:
===================================
===================================
After you compile myfirstjavaprog.java class, myfirstjavaprog.class should appear in E:\temp\Java\ folder.
Now you can create a "Shell script". In "Script Manager" you should create new script with the following values:
Start cmd: cmd /c %Script% %Params%
Script: "C:\Program Files\Java\jdk1.5.0_05\bin\java" -classpath E:\temp\Java\ myfirstjavaprog
That's it. It works. Of course, it is very simplified example, but using this example you may adjust your java program to work properly with HostMonitor.
Regards,
Max
===================================
Code: Select all
class myfirstjavaprog
{
public static void main(String args[])
{
System.out.println("ScriptRes:Ok:15");
}
}
After you compile myfirstjavaprog.java class, myfirstjavaprog.class should appear in E:\temp\Java\ folder.
Now you can create a "Shell script". In "Script Manager" you should create new script with the following values:
Start cmd: cmd /c %Script% %Params%
Script: "C:\Program Files\Java\jdk1.5.0_05\bin\java" -classpath E:\temp\Java\ myfirstjavaprog
That's it. It works. Of course, it is very simplified example, but using this example you may adjust your java program to work properly with HostMonitor.
Regards,
Max
Hmm, doesn't quite work perfect yet 
%Params% is the problem:
Start cmd: cmd /c %Script% %Params%
Script: java -jar D:\javatest\test.jar param1 param2
Parameters:
That works, but:
Start cmd: cmd /c %Script% %Params%
Script: java -jar D:\javatest\test.jar
Parameters: param1 param2
Doesn't work (java doesn't see the parameters).
It's fixable by creating different 'scripts' for different parameters, but it isn't the nicest solution off course...

%Params% is the problem:
Start cmd: cmd /c %Script% %Params%
Script: java -jar D:\javatest\test.jar param1 param2
Parameters:
That works, but:
Start cmd: cmd /c %Script% %Params%
Script: java -jar D:\javatest\test.jar
Parameters: param1 param2
Doesn't work (java doesn't see the parameters).
It's fixable by creating different 'scripts' for different parameters, but it isn't the nicest solution off course...
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
Ok, I've tested it. To figure it out, you should specify the line belo into "Start cmd" box and leave "Script" box empty:
It works properly with passed params.
Regards,
Max
Code: Select all
cmd /c java -jar C:\file-folder\test.jar %Params%
Regards,
Max
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact: