KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Possible to use Java?

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting
View previous topic :: View next topic  
Author Message
bbackx



Joined: 07 May 2009
Posts: 46

PostPosted: Fri May 15, 2009 9:16 am    Post subject: Possible to use Java? Reply with quote

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.)
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Fri May 15, 2009 9:28 am    Post subject: Reply with quote

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/mframe.htm#tests.htm#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/mframe.htm#tests.htm#chkShell

Regards,
Max
Back to top
View user's profile Send private message Send e-mail Visit poster's website
bbackx



Joined: 07 May 2009
Posts: 46

PostPosted: Fri May 15, 2009 9:56 am    Post subject: Reply with quote

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:
Code:

[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
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Fri May 15, 2009 10:19 am    Post subject: Reply with quote

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/tests.htm#mframe.htm#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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
KS-Soft



Joined: 03 Apr 2002
Posts: 12795
Location: USA

PostPosted: Fri May 15, 2009 10:34 am    Post subject: Reply with quote

Quote:
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/javaprogramming/JAR/basics/

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
bbackx



Joined: 07 May 2009
Posts: 46

PostPosted: Mon May 18, 2009 2:32 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Mon May 18, 2009 3:04 am    Post subject: Reply with quote

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:
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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
bbackx



Joined: 07 May 2009
Posts: 46

PostPosted: Mon May 18, 2009 3:52 am    Post subject: Reply with quote

It works

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
Back to top
View user's profile Send private message
bbackx



Joined: 07 May 2009
Posts: 46

PostPosted: Tue May 19, 2009 12:55 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Tue May 19, 2009 1:27 am    Post subject: Reply with quote

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:
cmd /c java -jar C:\file-folder\test.jar %Params%


It works properly with passed params.

Regards,
Max
Back to top
View user's profile Send private message Send e-mail Visit poster's website
bbackx



Joined: 07 May 2009
Posts: 46

PostPosted: Tue May 19, 2009 3:46 am    Post subject: Reply with quote

Yes, indeed.
Thanks, still have to see another company with this level of support
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Tue May 19, 2009 4:52 am    Post subject: Reply with quote

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

Thank you.
You are welcome.

Regards,
Max
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index