Skip to content

Commit 9e59b6d

Browse files
committed
Include simple content match checking
1 parent b3ca601 commit 9e59b6d

5 files changed

Lines changed: 61 additions & 1 deletion

File tree

META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-SymbolicName: com.realdolmen.dynatrace.restmonitor;singleton:=t
33
rue
44
Bundle-Name: REST Monitor
5-
Bundle-Version: 1.2.1
5+
Bundle-Version: 1.2.2
66
Implementation-Version: 6.5.0.1289
77
Bundle-ClassPath: .,lib/slf4j-api-1.7.16.jar,lib/httpclient-cache-4.3.
88
6.jar,lib/json-smart-2.2.1.jar,lib/json-path-2.2.0.jar,lib/json-simpl

plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
<rule key="useHeader" value="true" />
5858
</visibility>
5959
</property>
60+
<property key="matchContent" label="Match content" type="boolean" description="If enabled, the specified string will be searched in the retrieved page." default="false" />
61+
<property key="searchString" label="Search string" type="string" description="Enter a case-sensitive string to search for in the retrieved result. If the result contains the string, the measure will yield 1, otherwise 0." default="" multiline="true">
62+
<visibility>
63+
<rule key="matchContent" value="true" />
64+
</visibility>
65+
</property>
6066
<property key="serverAuth" label="Server authorization" type="list" description="Specify the authentication type to be used." default="Disabled">
6167
<list>
6268
<item value="Disabled" />
@@ -135,6 +141,7 @@
135141
<metric defaultrate="none" description="%METRIC_RESPONSE_SIZE_DESCRIPTION" displayname="%METRIC_RESPONSE_SIZE_LABEL" name="ResponseSize" unit="bytes" />
136142
<metric defaultrate="sec" description="%METRIC_THROUGHPUT_DESCRIPTION" displayname="%METRIC_THROUGHPUT_LABEL" hidedisplayaggregation="sum count" name="Throughput" unit="kilobytes" />
137143
<metric defaultrate="none" description="%METRIC_HTTP_STATUS_CODE_DESCRIPTION" displayname="%METRIC_HTTP_STATUS_CODE_LABEL" hidedisplayaggregation="sum count" name="HttpStatusCode" unit="number" />
144+
<metric defaultrate="none" description="%METRIC_CONTENT_VERIFIED_DESCRIPTION" displayname="%METRIC_CONTENT_VERIFIED_LABEL" hidedisplayaggregation="sum count" name="ContentVerified" unit="number" />
138145
<metric defaultrate="none" description="%METRIC_CONNECTION_CLOSE_DELAY_DESCRIPTION" displayname="%METRIC_CONNECTION_CLOSE_DELAY_LABEL" hidedisplayaggregation="sum count" name="ConnectionCloseDelay" unit="ms" />
139146
<metric defaultrate="none" description="%METRIC_SOCKET_TIMEDOUT_DESCRIPTION" displayname="%METRIC_SOCKET_TIMEDOUT_LABEL" hidedisplayaggregation="sum count" name="SocketTimedOut" unit="number" />
140147
<metric defaultrate="none" description="%METRIC_CONNECTION_TIMEDOUT_DESCRIPTION" displayname="%METRIC_CONNECTION_TIMEDOUT_LABEL" hidedisplayaggregation="sum count" name="ConnectionTimedOut" unit="number" />

src/com/realdolmen/dynatrace/restmonitor/Config.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class Config implements Migrator {
4545

4646
protected static final String CONFIG_USE_HEADER = "useHeader";
4747
protected static final String CONFIG_HEADER = "header";
48+
49+
protected static final String CONFIG_MATCH_CONTENT = "matchContent";
50+
protected static final String CONFIG_SEARCH_STRING = "searchString";
4851

4952
protected static final String CONFIG_USE_PROXY = "useProxy";
5053
protected static final String CONFIG_PROXY_HOST = "proxyHost";
@@ -83,6 +86,10 @@ public class Config implements Migrator {
8386
boolean useHeader;
8487
String header;
8588

89+
// match content
90+
boolean matchContent;
91+
String searchString;
92+
8693
// proxy
8794
boolean useProxy;
8895
String proxyHost;
@@ -157,6 +164,11 @@ public Config() {
157164
header = env.getConfigString(CONFIG_HEADER);
158165
}
159166

167+
matchContent = env.getConfigBoolean(CONFIG_MATCH_CONTENT) == null ? false : env.getConfigBoolean(CONFIG_MATCH_CONTENT);
168+
if (matchContent) {
169+
searchString = env.getConfigString(CONFIG_SEARCH_STRING);
170+
}
171+
160172
useProxy = env.getConfigBoolean(CONFIG_USE_PROXY) == null ? false : env.getConfigBoolean(CONFIG_USE_PROXY);
161173
if (useProxy) {
162174
proxyHost = env.getConfigString(CONFIG_PROXY_HOST);

src/com/realdolmen/dynatrace/restmonitor/MeasureConnection.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class MeasureConnection {
2323
static final String MSR_CONN_CLOSE_DELAY = "ConnectionCloseDelay";
2424
static final String MSR_SOCKET_TIMEOUT = "SocketTimedOut";
2525
static final String MSR_CONNECT_TIMEOUT = "ConnectionTimedOut";
26+
static final String MSR_CONTENT_VERIFIED = "ContentVerified";
2627

2728
private static final double MILLIS = 0.000001;
2829
private static final double SECS = 0.000000001;
@@ -36,6 +37,7 @@ public class MeasureConnection {
3637
private int inputSize = 0;
3738
private boolean socketTimedOut = false;
3839
private boolean connectionTimedOut = false;
40+
private boolean contentVerified = false;
3941

4042
private MonitorEnvironment monitorEnvironment;
4143

@@ -69,6 +71,12 @@ final void applyBinaryMeasuresToEnvironment() {
6971
for (MonitorMeasure measure : measures)
7072
measure.setValue(socketTimedOut ? 1 : 0);
7173
}
74+
75+
// set content verified
76+
if ((measures = monitorEnvironment.getMonitorMeasures(METRIC_GROUP, MSR_CONTENT_VERIFIED)) != null) {
77+
for (MonitorMeasure measure : measures)
78+
measure.setValue(contentVerified ? 1 : 0);
79+
}
7280
}
7381

7482
/**
@@ -176,4 +184,9 @@ void setConnectionTimedOut()
176184
{
177185
this.connectionTimedOut = true;
178186
}
187+
188+
void setContentVerified()
189+
{
190+
this.contentVerified = true;
191+
}
179192
}

src/com/realdolmen/dynatrace/restmonitor/RestMonitor.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ public Status execute(MonitorEnvironment env) throws Exception {
173173
if (log.isLoggable(Level.FINE)){
174174
messageBuffer.append("content: \n" + resultContent.toString());
175175
}
176+
177+
// check if content matches
178+
if (matchContent(resultContent.toString()))
179+
{
180+
measureConnection.setContentVerified();
181+
}
182+
176183
final MeasureCapturedValues measureCapturedValues = new MeasureCapturedValues(env);
177184
measureCapturedValues.applyMeasuresToEnvironment(resultContent.toString(), config.format);
178185
}
@@ -327,6 +334,27 @@ private void setupHeader(DynaTraceHttpClient httpClient) {
327334
httpClient.addRequestHeader(headerSplit[0], headerSplit[1]);
328335
}
329336
}
337+
338+
private boolean matchContent(String resultContent) {
339+
if (!config.matchContent) {
340+
log.fine("Not checking for file content.");
341+
return false;
342+
}
343+
if (config.searchString.isEmpty()) {
344+
log.warning("Search String is empty");
345+
return false;
346+
} else {
347+
log.finer("Checking if: " + config.searchString.toString() + "is on");
348+
log.finer("response: " + resultContent);
349+
if(resultContent.contains(config.searchString.toString()))
350+
{
351+
log.finer("content match!");
352+
return true;
353+
}
354+
}
355+
log.fine("Bailing out content matching");
356+
return false;
357+
}
330358

331359
private void setupHttpClient() {
332360
DynaTraceHttpClientBuilder builder = new DynaTraceHttpClientBuilder();

0 commit comments

Comments
 (0)