Possible to use Java?

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
bbackx
Posts: 46
Joined: Thu May 07, 2009 9:15 am

Possible to use Java?

Post by bbackx »

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.)
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

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
bbackx
Posts: 46
Joined: Thu May 07, 2009 9:15 am

Post by bbackx »

Thanks, fast answer :D

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
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 ;)
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

bbackx wrote:The location of the file, should it be on the server that monitors or on the server that has the agent running?
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:If the file should be located on the server with the agent, can HM automate the distribution?
No. HostMonitor is not responsible for external files.
bbackx wrote:How do I fix the 301 - Error ;)
You program should suit requirements. Quote from the manual: http://www.ks-soft.net/hostmon.eng/test ... m#shellmng
=====================================
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
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

C:\Location-of-file\Hello.jar %Params%
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.

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
bbackx
Posts: 46
Joined: Thu May 07, 2009 9:15 am

Post by bbackx »

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 :-)
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Ok, let's start from scratch. Below you can see the source of myfirstjavaprog.java class, that is located in E:\temp\Java\ folder:
===================================

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
bbackx
Posts: 46
Joined: Thu May 07, 2009 9:15 am

Post by bbackx »

It works :D

Start cmd is "cmd /c %Script% %Params%" and Script is: java -jar C:\file-folder\test.jar

Thanks for the help, yet another problem tackled :)
bbackx
Posts: 46
Joined: Thu May 07, 2009 9:15 am

Post by bbackx »

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...
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Ok, I've tested it. To figure it out, you should specify the line belo into "Start cmd" box and leave "Script" box empty:

Code: Select all

cmd /c java -jar C:\file-folder\test.jar %Params%
It works properly with passed params.

Regards,
Max
bbackx
Posts: 46
Joined: Thu May 07, 2009 9:15 am

Post by bbackx »

Yes, indeed.
Thanks, still have to see another company with this level of support :)
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

bbackx wrote:Thanks, still have to see another company with this level of support :)

Thank you. :-)
You are welcome.

Regards,
Max
Post Reply