modules/plugins/script/src/main/java/org/rhq/plugins/script/ScriptServerComponent.java |
6 +++---
modules/plugins/script/src/main/resources/META-INF/rhq-plugin.xml |
2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
New commits:
commit 27d664d1c294822a0162711f73decbf03b1ea73a
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Thu Feb 27 09:24:25 2014 -0500
[BZ 1005951] ScriptServer resource availability regular expression matching
fails due to complete string matching being applied to multiline output
Improved description for availabilityOutputRegex config property.
Cherry-Pick master 62cc988c8980a15e00b61fc45370f76c10a3608f
Signed-off-by: Jay Shaughnessy <jshaughn(a)redhat.com>
diff --git a/modules/plugins/script/src/main/resources/META-INF/rhq-plugin.xml
b/modules/plugins/script/src/main/resources/META-INF/rhq-plugin.xml
index e1a96f2..92aded8 100644
--- a/modules/plugins/script/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/script/src/main/resources/META-INF/rhq-plugin.xml
@@ -29,7 +29,7 @@
<c:group name="avail" displayName="Availability
Definition">
<c:simple-property name="availabilityExecuteCheck"
required="false" type="boolean" description="If specified and
true, the ability to successfully execute the executable can determine whether or not the
managed resource is considered up and available. If you set this to true, you normally do
not set the availability regex settings in order to allow availability to be determined
based solely on the successful execution, regardless of the exit code or output. If this
is false, setting one of the avail regex settings will override it as if it were
true."/>
<c:simple-property name="availabilityExitCodeRegex"
required="false" description="If specified, the executable must return an
exit code that matches this regular expression if the managed resource is to be considered
up and available"/>
- <c:simple-property name="availabilityOutputRegex"
required="false" description="If specified, the executable must output text
that matches this regular expression if the managed resource is to be considered up and
available"/>
+ <c:simple-property name="availabilityOutputRegex"
required="false" description="If specified, the executable must output text
that matches this regular expression if the managed resource is to be considered up and
available. Expression is evaluated by Pattern.find() so match actually means first match
found in text. Pattern `OK` matches multiline text `Service status\n is OK`. By default ^$
represent start/end of output text. To match start/end of line add (?m). eg. `(?m)^ is
OK$`. To match whole multi-line output use (?s), eg. `(?s)Service.*OK`."/>
<c:simple-property name="availabilityArguments"
required="false" description="If the executable needs to be executed in
order to determine availability, these are the arguments that will be passed to the
executable. If you do not specify the regex settings and you set the execute check setting
to false, the executable will not be executed and these arguments will not be used - in
this case, availability will be determined by the mere existence of the executable
file."/>
</c:group>
<c:group name="version" displayName="Version
Definition">
commit 26b3ff9c1d544267405804bc4cd72d762a8c0586
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Thu Feb 27 09:21:04 2014 -0500
[BZ 1005951] ScriptServer resource availability regular expression matching
fails due to complete string matching being applied to multiline output
Fixed by changing to Pattern.matcher().find() instead of String.matches.
Users do not need to write long or crazy regexes to find match in multi-line
output. Previously you'd write `(?s).*OK.*` to match 'a\nb\nOK\n' now
just
use `OK`
Signed-off-by: Jay Shaughnessy <jshaughn(a)redhat.com>
diff --git
a/modules/plugins/script/src/main/java/org/rhq/plugins/script/ScriptServerComponent.java
b/modules/plugins/script/src/main/java/org/rhq/plugins/script/ScriptServerComponent.java
index d62f2a1..a440d8e 100644
---
a/modules/plugins/script/src/main/java/org/rhq/plugins/script/ScriptServerComponent.java
+++
b/modules/plugins/script/src/main/java/org/rhq/plugins/script/ScriptServerComponent.java
@@ -442,7 +442,7 @@ public class ScriptServerComponent implements ResourceComponent,
MeasurementFace
boolean availExecuteCheck = false;
String availArgs = null;
String availExitCodeRegex = null;
- String availOutputRegex = null;
+ Pattern availOutputRegex = null;
// determine how we are to consider the CLI available by looking at the plugin
configuration
try {
@@ -471,7 +471,7 @@ public class ScriptServerComponent implements ResourceComponent,
MeasurementFace
}
if (availOutputRegexProp != null &&
availOutputRegexProp.getStringValue() != null) {
- availOutputRegex = availOutputRegexProp.getStringValue();
+ availOutputRegex =
Pattern.compile(availOutputRegexProp.getStringValue());
}
} catch (Exception e) {
throw new InvalidPluginConfigurationException("Cannot get avail plugin
config. Cause: " + e);
@@ -526,7 +526,7 @@ public class ScriptServerComponent implements ResourceComponent,
MeasurementFace
output = output.trim();
}
- boolean outputMatches = output.matches(availOutputRegex);
+ boolean outputMatches = availOutputRegex.matcher(output).find();
if (!outputMatches) {
if (log.isDebugEnabled()) {
logDebug("CLI output [" + truncateString(output) +
"] did not match regex [" + availOutputRegex