<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Post Execution Script - synthetic HTTP in Synthetic Monitoring</title>
    <link>https://community.dynatrace.com/t5/Synthetic-Monitoring/Use-Post-Execution-Scripts-in-Dynatrace-Synthetic-HTTP-Monitors/m-p/275084#M3033</link>
    <description>&lt;P class=""&gt;Hello &lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/26392"&gt;@SofiaPersia&lt;/a&gt;&lt;/P&gt;&lt;P class=""&gt;Below is a short script snippet you can copy and paste into your HTTP monitor’s post-execution script. It will help you quickly pinpoint whether there’s an issue with an empty response body, invalid JSON, or a missing db array. Just replace any relevant variable names as needed:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var responseBody = response.getResponseBody();

// 1. Check if the response body is empty
if (!responseBody) {
    api.fail("Response body is empty!");
}

try {
    // 2. Try parsing the JSON
    var obj = JSON.parse(responseBody);
    api.info("Successfully parsed JSON.");
} catch (e) {
    api.fail("Failed to parse JSON: " + e.message);
}

// 3. Check if the 'db' array exists
if (!obj.db || !Array.isArray(obj.db)) {
    api.fail("No 'db' array found in the JSON structure.");
}

// 4. Log basic debug info
api.info("Response seems valid. Proceed with further checks...");&lt;/LI-CODE&gt;&lt;P&gt;This should help you identify where the script might be failing:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P class=""&gt;&lt;STRONG&gt;Empty body&lt;/STRONG&gt; if nothing is returned.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;&lt;STRONG&gt;Parsing errors&lt;/STRONG&gt; if the response isn’t valid JSON.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;&lt;STRONG&gt;Missing structure&lt;/STRONG&gt; if db isn’t present or isn’t an array.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;From there, you can add your logic to check status === "DOWN" and report accordingly. Good luck!&lt;/P&gt;</description>
    <pubDate>Mon, 14 Apr 2025 12:37:07 GMT</pubDate>
    <dc:creator>JeanBlanc</dc:creator>
    <dc:date>2025-04-14T12:37:07Z</dc:date>
    <item>
      <title>Use Post‑Execution Scripts in Dynatrace Synthetic HTTP Monitors</title>
      <link>https://community.dynatrace.com/t5/Synthetic-Monitoring/Use-Post-Execution-Scripts-in-Dynatrace-Synthetic-HTTP-Monitors/m-p/272185#M2993</link>
      <description>&lt;P&gt;&lt;EM&gt;Summary:&amp;nbsp;This post explains how post‑execution scripts work in Dynatrace synthetic HTTP monitors. It provides instructions on where to define the script, what data can be accessed, and supported use cases.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;I'm encountering an issue with my Synthetic HTTP post-execution script and could use some help troubleshooting.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I have the following script where I define the &lt;FONT color="#FF0000"&gt;responseBody&lt;/FONT&gt; directly within the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;var responseBody = {
    "db": [
        {
            "status": "UP",
            "details": {
                "db_name": "apig_otk",
                "jdbc_name": "OAuth",
                "metric_name": "count otk_sessionstore",
                "metric_value": 61956,
                "threshold": 2000000
            }
        },
        {
            "status": "UP",
            "details": {
                "db_name": "apig_ssg",
                "jdbc_name": "SSG",
                "metric_name": "count ssg_certificates",
                "metric_value": 378,
                "threshold": 490
            }
        },
        {
            "status": "DOWN",
            "details": {
                "db_name": "sm_SessionStore",
                "jdbc_name": "SM_SessionStore",
                "metric_name": "count sm_sessionspec5",
                "metric_value": 79,
                "threshold": 1000
            }
        },
        {
            "status": "UP",
            "details": {
                "db_name": "sm_SessionStore",
                "jdbc_name": "SM_SessionStore",
                "metric_name": "count sm_sessionvar5",
                "metric_value": 155,
                "threshold": 2000
            }
        }
    ]
};&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With the above, the script works as expected, and I receive a failure message if the status is DOWN.&lt;BR /&gt;&lt;BR /&gt;However, when I modify the script to dynamically retrieve the responseBody using the following lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;//var responseBody = response.getResponseBody()
//var obj = JSON.parse(responseBody);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;And replace the direct reference to &lt;FONT color="#FF0000"&gt;responseBody&lt;/FONT&gt; with the parsed object &lt;FONT color="#FF0000"&gt;obj&lt;/FONT&gt;, the script doesn't seem to generate any output. No failure message appears, and I can't figure out what's going wrong.&lt;/P&gt;
&lt;P&gt;Here's what I'm trying:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;var db_array = [];
var metric_name = [];
var metric_value = [];

// First loop to collect data
for (var i = 0; i &amp;lt; obj.db.length; i++) {
    var db_var = obj.db[i];
    var stato = db_var.status;
    var dbName = db_var.details.db_name;
    var metricName = db_var.details.metric_name;
    var metricValue = db_var.details.metric_value;

    // If status is DOWN, push data to arrays
    if (stato === "DOWN") {
        db_array.push(dbName);
        metric_name.push(metricName);
        metric_value.push(metricValue);
    }
}

// If there are any DOWN dbs, signal the error
if (db_array.length &amp;gt; 0) {
    api.fail("The following DBs have status 'DOWN': " + db_array.join() + " with '" + metric_name.join() + "' = " + metric_value.join());
} else {
    api.info("All DBs are healthy!");
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this doesn't seem to be working. I don't get any failure message, and I’m unable to determine the root cause. Has anyone encountered this issue before, or can anyone point me in the right direction to fix it?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Thank you for any help!&lt;/P&gt;
&lt;P&gt;Sofia&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jan 2026 10:46:25 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Synthetic-Monitoring/Use-Post-Execution-Scripts-in-Dynatrace-Synthetic-HTTP-Monitors/m-p/272185#M2993</guid>
      <dc:creator>SofiaPersia</dc:creator>
      <dc:date>2026-01-26T10:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Post Execution Script - synthetic HTTP</title>
      <link>https://community.dynatrace.com/t5/Synthetic-Monitoring/Use-Post-Execution-Scripts-in-Dynatrace-Synthetic-HTTP-Monitors/m-p/275084#M3033</link>
      <description>&lt;P class=""&gt;Hello &lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/26392"&gt;@SofiaPersia&lt;/a&gt;&lt;/P&gt;&lt;P class=""&gt;Below is a short script snippet you can copy and paste into your HTTP monitor’s post-execution script. It will help you quickly pinpoint whether there’s an issue with an empty response body, invalid JSON, or a missing db array. Just replace any relevant variable names as needed:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var responseBody = response.getResponseBody();

// 1. Check if the response body is empty
if (!responseBody) {
    api.fail("Response body is empty!");
}

try {
    // 2. Try parsing the JSON
    var obj = JSON.parse(responseBody);
    api.info("Successfully parsed JSON.");
} catch (e) {
    api.fail("Failed to parse JSON: " + e.message);
}

// 3. Check if the 'db' array exists
if (!obj.db || !Array.isArray(obj.db)) {
    api.fail("No 'db' array found in the JSON structure.");
}

// 4. Log basic debug info
api.info("Response seems valid. Proceed with further checks...");&lt;/LI-CODE&gt;&lt;P&gt;This should help you identify where the script might be failing:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P class=""&gt;&lt;STRONG&gt;Empty body&lt;/STRONG&gt; if nothing is returned.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;&lt;STRONG&gt;Parsing errors&lt;/STRONG&gt; if the response isn’t valid JSON.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;&lt;STRONG&gt;Missing structure&lt;/STRONG&gt; if db isn’t present or isn’t an array.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;From there, you can add your logic to check status === "DOWN" and report accordingly. Good luck!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2025 12:37:07 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Synthetic-Monitoring/Use-Post-Execution-Scripts-in-Dynatrace-Synthetic-HTTP-Monitors/m-p/275084#M3033</guid>
      <dc:creator>JeanBlanc</dc:creator>
      <dc:date>2025-04-14T12:37:07Z</dc:date>
    </item>
  </channel>
</rss>

