How to debug error at hms scripts

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
grzchr15
Posts: 3
Joined: Wed Dec 12, 2007 2:35 am

How to debug error at hms scripts

Post by grzchr15 »

We have a hms script like:
Example

Code: Select all

ExecuteProgram 1000 wget http://webserver/cms_ip_tab?rma=%CommentLine1% -O "C:\Program Files\HostMonitor6\Lists\cms_ip_tab-%CommentLine1%.txt"
ImportFromFile  cms_ip_tab-%CommentLine1%.txt  SkipDuplicates  WriteLog
SaveTestList   servername.hml
This test files contains at minimum a test like

%CommentLine1%=agentservernameXXX

Code: Select all

ImportMode = Replace 

DefaultFolder = Root\rma-agentservername\
; ------- Test #1 -------
	Method      = HTTP
;--- Common properties ---
DestFolder  = Root\rma-agentservernameXXX\
Title       = http://home.andritz.com/cms_ip_tab?rma=agentservernameXXX
Comment     =agentservernameXXX
RelatedURL  = http://home.andritz.com/cms_ip_tab?rma=agentservernameXXX
ScheduleMode= OneTestPerDay
ScheduleTime= 02:00:00
Alerts      = reload-cms_ip_tab-reload
ReverseAlert= No
UnknownIsBad= Yes
WarningIsBad= Yes
UseCommonLog= Yes
PrivLogMode = Default
CommLogMode = Default
SyncCounters= Yes
SyncAlerts  = No
DependsOn   = list
;--- Test specific properties ---
URL         = http://home.andritz.com/cms_ip_tab?rma=agentservernameXXX
Request     = GET
Redirect    = Yes
PostData    = 
Agent       = KSHostMonitor:/1.0
Timeout     = 50000
AllowCookies= No
OtherHeaders= 
AuthMethod  = None
CheckContents= mustcontain
CExpression = SERIAL=2008213
CMatchCase  = No
CWholeWord  = No
UseFrames   = No
UseImages   = No

...Some more tests
The action for bad result ( It compares the SERIAL=2008213 ) is to run the action for so long as the test is bad.

But when there is a script error in the hms script , it will never change.

So again
  • How to debug error at hms scripts
    How to see the error like "Folder in Hostmonitor does not exist"
and maybe a feature request: It would be nice to run hms scripts also at RCC (Remote console)
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Re: How to debug error at hms scripts

Post by KS-Soft Europe »

grzchr15 wrote:How to debug error at hms scripts
Hm. In fact there is no well known principles to debug "HMS Script". However, you may "echo" each line of the script into particular file to check macro variables are properly resolved. You just should duplicate each string in a script file with "ExecuteProgram" command in order to start "cmd /c echo" system command. E.g.:

Code: Select all

ExecuteProgram 1000 wget http://webserver/cms_ip_tab?rma=%CommentLine1% -O "C:\Program Files\HostMonitor6\Lists\cms_ip_tab-%CommentLine1%.txt" 
ExecuteProgram 10000 cmd /c echo  ExecuteProgram 1000 wget http://webserver/cms_ip_tab?rma=%CommentLine1% -O "C:\Program Files\HostMonitor6\Lists\cms_ip_tab-%CommentLine1%.txt" > c:\script_debug.log

ImportFromFile  cms_ip_tab-%CommentLine1%.txt  SkipDuplicates  WriteLog 
ExecuteProgram  10000 cmd /c echo  ImportFromFile  cms_ip_tab-%CommentLine1%.txt  SkipDuplicates  WriteLog  >> c:\script_debug.log

SaveTestList   servername.hml
As you may see, foregoing script will save all lines into c:\script_debug.log file.
grzchr15 wrote:How to see the error like "Folder in Hostmonitor does not exist"
"ImportFromFile" command has optional "WriteLog" parameter, that tells HostMonitor to record to the system log file information about all errors and warnings during the import process. System log is specified in "Options" -> "System Log" tab.

On the other hand, you may use "CreateFolder" commands into import file. This helps you to avoid "Folder in Hostmonitor does not exist" errors. Quote from the manual:
http://www.ks-soft.net/hostmon.eng/examples/import1.htm
===================================
CreateFolder = Root\USA Branch\Support\part2\
; creates new folder(s). The value of this parameter should specify the full
; path to the folder that you want to create.
; E.g. CreateFolder = Root\USA Branch\Support\part2\ will successively create
; folders USA Branch (in the Root folder), Support (in USA Branch subfolder)
; and part2 (in Support subfolder). Of course if some (or all) of specified
; folders already exist, HostMonitor will not create second copy of them.
===================================
grzchr15 wrote:and maybe a feature request: It would be nice to run hms scripts also at RCC (Remote console)
Need to think about it...

Regards,
Max
grzchr15
Posts: 3
Joined: Wed Dec 12, 2007 2:35 am

'%DateTime%' gets split into multiply strings in HMS?

Post by grzchr15 »

How to avoid broken macro parameters?
HMS Code

Code: Select all

ExecuteProgram 10000 cmd /c echo  ExecuteProgram 1000 "C:\jobs\hostmonitor\set.cmd" OK  '%DateTime%' '%TestName%'  '%Status%'  '%Reply_CStyle%' '%TestMethod%' ""%LastTestTime%"" '%StatusID%' '%SimpleStatus%' '%Agent%' '%AckComment%' '%LastStatus%' '%PreviousStatus%' '%TaskComment%' '%TestID%' '%CommentLine1%' >>"C:\jobs\hostmonitor\hmslog.log"
Batch File

Code: Select all

type "C:\Program Files\HostMonitor6\Lists\set.log" >"C:\Program Files\HostMonitor6\Lists\setall.log"
set >"C:\Program Files\HostMonitor6\Lists\set.log"
echo 1:  (%1) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 2:  (%2) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 3:  (%3) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 4:  (%4) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 5:  (%5) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 6:  (%6) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 7:  (%7) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 8:  (%8) >>"C:\Program Files\HostMonitor6\Lists\set.log"
shift 
shift 
shift 
shift 
shift 
shift 
shift 
shift 
echo 9:  (%1) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 10: (%2) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 11: (%3) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 12: (%4) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 13: (%5) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 14: (%6) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 15: (%7) >>"C:\Program Files\HostMonitor6\Lists\set.log"
echo 16: (%8) >>"C:\Program Files\HostMonitor6\Lists\set.log"
type set.log
Broken output:

Code: Select all

1:  (OK) 
2:  ('3/13/2008) <- Broken Date
3:  (7:20:38) <- Broken Date
4:  (PM') <- Broken Date
5:  ('http://servername/cms_ip_tab?rma) 
6:  (vaxsms001') 
7:  ('Host) <- Broken Status
8:  (is) <- Broken Status
9:  (alive') <- Broken Status
10: ('532)  <- Broken Time
11: (ms') <-  Broken Time
12: ('HTTP) 
13: (test) 
14: ((servername)') 
15: ('3/13/2008) 
16: (7:20:22) 
How to avoid broken macro parameters?

Thanks again for support and quick responsees
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Re: '%DateTime%' gets split into multiply strings in HMS?

Post by KS-Soft Europe »

grzchr15 wrote:How to avoid broken macro parameters?
As you know, command line parser recognizes the batch parameters, separated by space. So, %DateTime%, represented by '3/13/2008 7:20:38 PM' value, is recognized as 3 parameters. If you want to pass a parameter, that contains spaces, you should enclose it into quotation marks , e.g. "%DateTime%". In this case you will see the date time as a single parameter in your oputput file: ("03/13/2008 21:19:01"). To get rid of surrounding quotation marks , you should use ~ sign, e.g %~1%, %~2%, etc. According to the microsoft:

Code: Select all

%~I - Expands %I which removes any surrounding quotation marks ("").
So, in your HMS code you should enclose all variables into quotation marks ("%DateTime%" "%TestName%" "%Status%", etc.) and in batch file add the ~ sign to the parameters variable:

Code: Select all

type "C:\Program Files\HostMonitor6\Lists\set.log" >"C:\Program Files\HostMonitor6\Lists\setall.log" 
set >"C:\Program Files\HostMonitor6\Lists\set.log" 
echo 1:  (%~1) >>"C:\Program Files\HostMonitor6\Lists\set.log" 
echo 2:  (%~2) >>"C:\Program Files\HostMonitor6\Lists\set.log" 
echo 3:  (%~3) >>"C:\Program Files\HostMonitor6\Lists\set.log" 
echo 4:  (%~4) >>"C:\Program Files\HostMonitor6\Lists\set.log" 
...
echo 16: (%~8) >>"C:\Program Files\HostMonitor6\Lists\set.log" 
type set.log
Regards,
Max
Post Reply