Abstract

Your iControl REST GET request reports 500 error after a considerable delay. The resource in question is verified present and obtainable at least from the equivalent tmsh command. All other resources can be accessible using the same userID/password but just THIS resource fails (curiouser and curiouser).

This error may occur when the response contains illegal characters. A workaround is to create a bash script that sanitizes the data, and invoke it using /mgmt/tm/util/bash.

Symptom

HTTP response status code 500 (Internal Server Error) is received for a GET request after a considerable delay (say, 30s). For example,

# curl -D - -sku admin:SECRET https://<HOST>/mgmt/tm/ltm/virtual/<VIRTUAL>
HTTP/1.1 500 Internal Server Error
....
{ code: 500,
  message: 'Input length = 1',
  referer: '192.168.226.137',
  restOperationId: 24341,
  kind: ':resterrorresponse' }

Other similar requests work perfectly fine, so you are quite sure that you have used correct userID/password, management port, and curl (HTTP) command. You can get the same data by running the equivallent tmsh command, so you are sure that the target resource is present. For example, for /mgmt/tm/ltm/virtual/vs, tmsh list ltm virtual vs.

The issue here is that the response JSON data contains characters that are not permitted in JSON. To verify, dump the data from tmsh in hexadecimal.

# tmsh list ltm <virtual> | od -t x1c
....
0000040  20  64  65  73  63  72  69  70  74  69  6f  6e  20  54  65  73
              d   e   s   c   r   i   p   t   i   o   n       T   e   s
0000060  74  ff  44  61  74  61  0a  20  20  20  20  64  65  73  74  69
          t 377   D   a   t   a  \n                   d   e   s   t   i
....

The above example indicates that the Description field of the virtual server contains 0xFF (333 in octal). The presence of such illegal character causes the iControl REST framework to discard the data and retry again. This retry is the reason for the "considerable delay".

Workaround

Obviously, first thing to do is to remove any suspicious characters.

If it cannot be done, write a script that obtains the data directly from the equivallent tmsh command and sanitise the data. Then, call the script using the iControl REST node /mgmt/tm/util/bash. For example, one can use iconv to sanitize the output of a tmsh command like the one below:

#!/bin/bash
tmsh list ltm virtual <VIRTUAL> | /usr/bin/iconv -f utf8 -t utf8 -c

Assume that the code is saved as /var/tmp/getVirtual (don't forget chmod +x), invoke the script via the iControl REST as below:

# curl -sku admin:admin -X POST -H "Content-Type: application/json" \
  -d "{\"command\":\"run\", \"utilCmdArgs\":\"-c '/root/getHardware'\"}" \
  https://<HOST>/mgmt/tm/util/bash

Unfortunately, the output is not in JSON format: You need to add a parser function in the script if necessary.

Conclusion

When the response JSON data contains illegal characters, iControl REST request fails after long delay. To workaround it, write a script that sanitises the data first and call it using /mgmt/tm/util/bash. The workaround is handy when you cannot fix the resource data. iControl REST allows you to control multiple remote BIG-IP entities easily. If you are interested in the feature, please read the iControl REST Home.