Writing a Script

In order to enable you to understand the basic ingredients of a script, the corrective script for the Service Availability measure of Windows Services test, has been provided below.

@echo off
rem The following is the format of the parameters
rem 1. <User parameters> (Anything that the user gives during test configuration will be here)
rem 2. -info (constant)
rem 3. <the value of the info>
rem We get all the parameters that the test gets
rem 4. -host (constant)
rem 5. <the monitored target, this could be IP or nick)
rem 6. -port (constant)
rem 7. <port number of the monitored target, if any>
rem 8. -serviceName (constant)
rem 9. <whatever is configured for process>
rem 14 -correct
rem 15 true (This will always be true, otherwise we wouldn't have come here)
rem 16 -userparams
rem 17 <whatever the user had configured>
rem 18 -correctivescript
rem 19 WinServiceTest_Availability.bat
rem 12 -rptName (constant)
rem 13 <the rpt name>
rem 14 -egMeasHost (constant)
rem 15 <the measurement host>
rem 16 -site (constant)
rem 17 <site name>
rem 18 -egMeasVals (constant)

rem The actual measures and the state follows
rem For WinServiceTestt, the following are the measures and state
rem 19 -Availability (measure name, constant)
rem 20 <state>

set service=%3
net start %service%

As is evident from the sample script above, a corrective script should include the following:

  • <User parameters>: This will store the value provided in the userparams text box in Figure 3.153.
  • -info <value>: Here -info is a constant, and <value> is the variable that stores the descriptors (if any) that the test takes. A corrective script will run once for every descriptor that has been enabled for the test, based on state changes.

Besides, the script should extract the values of the test parameters provided in the test configuration page of . In case of the Windows Services Test, the parameters are as follows:

  • -host<>: The IP of the component for which the test is being configured
  • -port<>: The port number at which the component listens
  • -serviceName<>: The names of the services that have been configured for monitoring
  • -correct<>: Indicates whether corrective action has been enabled for the test or not. This will always be ‘true’.
  • -userparams<>: The parameters that have been configured by the administrator
  • -correctivescript<>: The name of the corrective script. In the case of the WinServiceTest, to associate the default script with the test, the script name (WinServiceTest_Availability) is explicitly mentioned here. In the test configuration page therefore, leaving the correctivescript parameter as ‘none’, will automatically invoke the default corrective script for the test.
  • -rptName: The reporting name / nick name of the application for which the test is being configured
  • -eGMeasHost<>: The measurement host
  • -site<>: The name of site to which the measure pertains
  • -egMeasVals<>: The constant egMeasVals will be followed by the actual measure values and state. For the WinServiceTest, -Availability is the measure name constant, which will be followed by the variable, <state>, that tracks the state changes.
  • Finally, provide the command that will rectify the problems with the test, if any arise. Since the corrective script WinServiceTest should try to start the configured services if they stop, the command to that effect has been specified in the script file.

    set service=%3
    net start %service%

When an eG manager is installed on a host, a folder named AutoCorrect is created in the EG_INSTALL_DIR/bin directory. The AutoCorrect folder consists of some OS-specific folders (eg., folders named "Windows2003", "Linux", etc.). After building the custom script, save it to the OS-specific sub-folder that corresponds to the operating system on which the script is designed to execute.