Service-now MID Server

I recently needed to know the IP address of the MID Server that would be connecting to a third-party service provider for one of my integrations. The MID Server is in a data center that I don’t have access to, and I didn’t know how to easily find out the IP Address that external systems would see when it makes its FTP or other connections to the service. Yes, I could have called the operations people, but that would take the fun out of the exercise. I also wanted a chance to learn more about MID Server Script Includes, which I ended up using in this exercise.

For this solution, I decided I would reuse the script that I created for determining the connectivity information on a Service-now.com Instance.

After doing a little code-digging, I found that a MID Server Script include works very much like a typical script include for Service-now. However, if you make a change to your script, you have to restart the MID Server service so that it knows to re-cache the script in it’s system.

In order for me to execute my MID Server Script Include, I found that I needed to utilize the “JavascriptProbe”. I also found out that I could return the script output via a “paramater” to the Javascript Probe. The code for this is: “probe.setParameter({param_name}, {param_value});”

The modified connectivity script that has been placed into my MID Server Script Include looks like this:

Name: GetSourceConnectionInfo
Script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var GetSourceConnectionInfo = Class.create();

GetSourceConnectionInfo.prototype = {
   initialize: function() {
      var url = new Packages.java.net.URL("https://john-james-andersen.com/tools/connection.php");
      var isr = new Packages.java.io.InputStreamReader(url.openStream());
      var inp = new Packages.java.io.BufferedReader(isr);
      var inputLine = "";
      var result = "";
      while (inputLine = inp.readLine()) {
        ms.log(inputLine);
        result += inputLine;
      }
      inp.close();
      probe.setParameter("Output", result);
      return result;
   }
}

Now to get the MID Server to run this code, you need to create a new record on the ECC Queue. Here is what my record looks like:

Agent: mid.server.my_mid_server
Topic: JavascriptProbe
Name: GetSourceConnectionInfo
Queue: output
State: ready
Payload:

1
2
3
4
5
<?xml version="1.0" encoding="UTF-8"?>
<parameters>
  <parameter name="script" value="var req = new GetSourceConnectionInfo();">
  </parameter>
</parameters>

When I submit that output record on the ECC Queue, I get a response that looks somewhat like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="UTF-8"?>
<results probe_time="844">
    <result>
        <output>org.mozilla.javascript.Undefined@aa3518</output>
    </result>
    <parameters>
        <parameter name="topic" value="JavascriptProbe"/>
        <parameter name="queue" value="output"/>
        <parameter name="sys_id" value="37311074c0a8016b00a83d033e819674"/>
        <parameter name="state" value="ready"/>
        <parameter name="Output" value="&lt;BR&gt;&lt;H1&gt;Source Connectivity Checker&lt;/H1&gt;&lt;i&gt;&lt;center&gt;John-James-Andersen.com sees your connection information as: &lt;/center&gt;&lt;/i&gt;&lt;br&gt;&lt;B&gt;UNIQUE_ID&lt;/B&gt;: TNrtvUPNN98AADN4RCsAAAAF&lt;BR&gt;&lt;B&gt;SCRIPT_URI&lt;/B&gt;: https://john-james-andersen.com/tools/connection.php&lt;BR&gt;&lt;B&gt;HTTP_USER_AGENT&lt;/B&gt;: Java/1.6.0_14&lt;BR&gt;&lt;B&gt;HTTP_CONNECTION&lt;/B&gt;: close&lt;BR&gt;&lt;B&gt;REMOTE_ADDR&lt;/B&gt;: 215.185.69.123&lt;BR&gt;&lt;B&gt;REMOTE_PORT&lt;/B&gt;: 1613&lt;BR&gt;&lt;B&gt;REQUEST_METHOD&lt;/B&gt;: GET&lt;BR&gt;&lt;B&gt;QUERY_STRING&lt;/B&gt;: &lt;BR&gt;&lt;B&gt;REQUEST_TIME&lt;/B&gt;: 1289416125&lt;BR&gt;"/>
        <parameter name="script" value="var req = new GetSourceConnectionInfo();"/>
        <parameter name="agent" value="mid.server.RadRoadTrips.com"/>
        <parameter name="ecc_queue" value="37311074c0a8016b00a83d033e819674"/>
        <parameter name="sequence" value="12c373110940000001"/>
        <parameter name="name" value="GetSourceConnectionInfo"/>
        <parameter name="table_name" value="ecc_queue"/>
    </parameters>
</results>

You’ll notice that my parameter named, “Output” holds the HTML response (escaped) that it returned from the URL that I had it reach. If I wanted to do something fancy I could create a business rule to watch for that message and have it unescape and parse the HTML response to give me the information that I need.