Bug 613834 - Include script plugin in JON 2.4release
Summary: Include script plugin in JON 2.4release
Alias: None
Product: RHQ Project
Classification: Other
Component: Plugins
Version: unspecified
Hardware: All
OS: All
medium vote
Target Milestone: ---
: ---
Assignee: John Mazzitelli
QA Contact: Sudhir D
Depends On:
Blocks: jon24-alert-scripts 602682
TreeView+ depends on / blocked
Reported: 2010-07-12 22:18 UTC by Charles Crouch
Modified: 2015-02-01 23:26 UTC (History)
2 users (show)

Clone Of:
Last Closed: 2010-08-12 16:54:02 UTC

Attachments (Terms of Use)
test-script.sh (717 bytes, application/x-shellscript)
2010-07-13 18:11 UTC, John Mazzitelli
no flags Details

Description Charles Crouch 2010-07-12 22:18:25 UTC
This is needed in order for 577256 to be complete, i.e. function on platforms where there is no JBAS instance.

Mazz, we also need the basic test cases for inventoring and executing scripts added to this bug so we can test this feature. Testing will also require retesting 602682.

Comment 1 John Mazzitelli 2010-07-13 18:11:01 UTC
Created attachment 431541 [details]

Attaching a test-script.sh that you can use to test the script plugin. It will allow you to test passing in env var as well as arguments and changing its exit code. Read the comments in the script file for more info on how to use it.

Comment 2 John Mazzitelli 2010-07-13 18:11:37 UTC
we can use the same attached script to test bug 602682 as well

Comment 3 John Mazzitelli 2010-07-13 19:16:15 UTC
Remember that the original purpose of this script plugin was to use a CLI script as a management endpoint for resources that might not have a true management interface (for example, apachectl script could be used to obtain status of apache).

But we can use this for any script - anything that has an exit code or output can be used. You can even just use the fact that the scrip ran successfully as a marker that the resource is UP.

How to test this:

0) take the attached test-script.sh and put it somewhere on your file system (the agent needs to be running on this machine)
1) make sure the Script plugin is deployed
2) Go to your platform resource, and go to Inventory tab and manually add a "Script Server"
3) Point to the full absolute path of your script that you stored in step 0

Now you can do one of several things here:

a) add an environment variable "SCRIPT_MSG" and set it to some string. That string will be output as the first line from the script
b) the first argument passed into the script is the # of seconds the script will sleep - default is 0 if no arguments are passed
c) the second argument passed is the exit code the script will exit with. Default is 0 if there is no second argument passed to it.

The availability of the script can be determined in several ways:

1) just by its existence
2) just by the fact that it can be executed successfully
3) by the exit code matching a regular expression (e.g. "0" or "[01]"
4) by its output matching a regular expression (e.g. "(?s).*OK.*")
5) by both 3 and 4 (matching exit code AND output).

Read the descriptions for all the "Availability Definition" plugin configuration properties for explanations on all the properties and how you can do 1-5 above.

For example, you can set the env var plugin configuration so it passes "SCRIPT_MSG" with value "This is OK". You can then set the "Availability Output Regex" plugin configuration property to "(?s).*OK.*". This will check that the script's output has the word "OK" in it somewhere - if it does, the script resource is assumed "UP". You can then pass in arguments "0 2" and set the "Availability Exit Code Regex" to "2" to ensure that the script exits with exit code 2 to be considered up. anytime you change the plugin config for the script resource, just run the agent prompt command "avail" to get the new availability status of the resource sent up to the server.

Similar settings allow you to use the results of script to determine its version and its description text. Again, the plugin configuration property descriptions give more info on how to do this.

Comment 4 John Mazzitelli 2010-07-13 19:18:10 UTC
one note: you should not use this script plugin for scripts that are long-lived. it is assumed the script is a short lived command line interface tool that runs, gathers information, outputs that information and exits.

Comment 5 John Mazzitelli 2010-07-13 19:25:09 UTC
another neat thing we can test using this script plugin is operation timeouts.

Script resources have one operation - "Execute". You give it some arguments to pass to the script and the script is executed.

Since we can now force the script execution to take as long as we want (via the first argument which is the # of seconds the script sleeps before exiting) we can give a large number of seconds to sleep, longer than the operation timeout, and make sure the timeout triggers and fails the operation execution.

Comment 6 Sudhir D 2010-07-14 13:59:52 UTC
I have verified this on jon-server-2.4.0.GA_QA.zip build# 62. 

Marking this bug as verified.

Comment 7 Corey Welton 2010-08-12 16:54:02 UTC
Mass-closure of verified bugs against JON.

Note You need to log in before you can comment on or make changes to this bug.