When used as alert notifications, CLI scripts could not find Remote API entities unless they were declared with their fully qualified name. This was due to the script engine being initialized with an empty list of entity packages.
In a standalone CLI environment, the list of packages was determined by scanning the "lib" directory of the CLI installation, which was not possible with an embedded CLI. As a consequence, the alert notification script execution failed with an error message similar to "javax.script.ScriptException:org.mozilla.javascript.EcmaError: ReferenceError: "ResourceCriteria" is not defined". Modifications to the script engine now initialize the embedded CLI with a list of packages determined by scanning the classpath at runtime. Remote API entities can now be declared with short names in CLI alert notification scripts.
Created attachment 932644[details]
test script with full path
Description of problem:
It appears that when running a CLI Script as an Alert Notification Implicit Variables are not available (org.rhq.core.domain class is not automatically imported)
Version-Release number of selected component (if applicable):
3.2.2
How reproducible:
Always
Steps to Reproduce:
1. Create an Alert Definition on any resource, i.e. Availability goes Down and add a Notification type of CLI Script, use the attached simplelist.js which simply uses var criteria = new ResourceCriteria(); to search for a resource type and print the list.
2. Trigger your Alert, look at the History on that Alert and you'll see the CLI notification fails with:
06:54:59,311 DEBUG [org.rhq.enterprise.server.alert.AlertManagerBean] (Thread-840) SenderResult{state=FAILURE, summary=Ran script simplelist.js in version rhqadmin:1.0 from repo Sample as user rhqadmin., successMessages=[], failureMessages=[javax.script.ScriptException:org.mozilla.javascript.EcmaError: ReferenceError: "ResourceCriteria" is not defined. (<Unknown source>#5) in <Unknown source> at line number 5 in script simplelist.js (rhqadmin:1.0) in repo Sample at line number 5]}
3. Now add another CLI notification to the same alert definition with the attached simplelistfqn.js which uses full path var criteria = new org.rhq.core.domain.criteria.ResourceCriteria(); it works.
Actual results:
Using Implicit variables in notification cli scripts fail.
Expected results:
Implicit variables would work.
Additional info:
Fixed in master
commit daacc1cef59ea804c8a6b373366b00396da1961c
Author: Thomas Segismont <tsegismo>
Date: Tue Sep 23 11:32:26 2014 +0200
Script engine was initialized with an empty list of core domain packages.
In the "real" CLI we can find it by scanning the lib directory. Here, we need to scan the core domain JAR by inspecting the classloader.
Re-used org.jboss.jandex module from the EAP6.3 base instead of importing a new lib or writing our own code.
branch: release/jon3.3.x
link: https://github.com/rhq-project/rhq/commit/c5cc11a6a
time: 2014-09-24 15:05:16 +0200
commit: c5cc11a6a3c5e927cd98f123a00b6c87aa722fda
author: Thomas Segismont - tsegismo
message: Bug 1135473 - Implicit Variables for CLI are not available if the script
is run as notification on an alert
Script engine was initialized with an empty list of core domain
packages.
In the "real" CLI we can find it by scanning the lib directory.
Here, we need to scan the core domain JAR by inspecting the
classloader.
Re-used org.jboss.jandex module from the EAP6.3 base instead of
importing a new lib or writing our own code.
(cherry picked from commit
daacc1cef59ea804c8a6b373366b00396da1961c) Signed-off-by: Libor Zoubek <lzoubek>
Verified on JON3.3 ER04
The alert history notification displays that the script simplelist.js ran successfully. Verified that both scripts does not display any failure in alert history notification.
Created attachment 932644 [details] test script with full path Description of problem: It appears that when running a CLI Script as an Alert Notification Implicit Variables are not available (org.rhq.core.domain class is not automatically imported) Version-Release number of selected component (if applicable): 3.2.2 How reproducible: Always Steps to Reproduce: 1. Create an Alert Definition on any resource, i.e. Availability goes Down and add a Notification type of CLI Script, use the attached simplelist.js which simply uses var criteria = new ResourceCriteria(); to search for a resource type and print the list. 2. Trigger your Alert, look at the History on that Alert and you'll see the CLI notification fails with: 06:54:59,311 DEBUG [org.rhq.enterprise.server.alert.AlertManagerBean] (Thread-840) SenderResult{state=FAILURE, summary=Ran script simplelist.js in version rhqadmin:1.0 from repo Sample as user rhqadmin., successMessages=[], failureMessages=[javax.script.ScriptException:org.mozilla.javascript.EcmaError: ReferenceError: "ResourceCriteria" is not defined. (<Unknown source>#5) in <Unknown source> at line number 5 in script simplelist.js (rhqadmin:1.0) in repo Sample at line number 5]} 3. Now add another CLI notification to the same alert definition with the attached simplelistfqn.js which uses full path var criteria = new org.rhq.core.domain.criteria.ResourceCriteria(); it works. Actual results: Using Implicit variables in notification cli scripts fail. Expected results: Implicit variables would work. Additional info: