Rest interface issues

I am finding gigs of errors in my logs. Have a lot of rest processes in HA that started failing about a month ago but they do work. So for example

If I run manually:

curl --insecure -u admin https://192.168.0.2:9999/api/v1/queries/check_cpu/commands/execute

Then I enter my password for the call and it returns

{“command”:“check_cpu”,“lines”:[{“message”:“OK: CPU load is ok.”,“perf”:{“total 1m”:{“critical”:90,“maximum”:0,“minimum”:0,“unit”:“%”,“value”:0,“warning”:80},“total 5m”:{“critical”:90,“maximum”:0,“minimum”:0,“unit”:“%”,“value”:0,“warning”:80},“total 5s”:{“critical”:90,“maximum”:0,“minimum”:0,“unit”:“%”,“value”:1,“warning”:80}}}],“result”:0}

The entry in my yaml file is

- platform: rest
  resource: 'https://192.168.0.2:9999/api/v1/queries/check_cpu/commands/execute'
  method: GET
  username: admin
  password: <password removed>
  name: MediaCenter CPU Used
  authentication: basic
  verify_ssl: false
  json_attributes_path: "$.[0].perf['total 5m']"
  json_attributes:
    - critical
    - maximum
    - minimum
    - warning
  value_template: "{{ value_json.lines[0].perf['total 5m'].value }}"
  unit_of_measurement: '%'

Error in the logs for this one and have loads of others with the same errors:

2021-11-28 21:34:42 WARNING (MainThread) [homeassistant.components.rest.sensor] Empty reply found when expecting JSON data
2021-11-28 21:34:42 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: https://192.168.0.2:9999/api/v1/queries/check_cpu/commands/execute failed with
2021-11-28 21:34:42 WARNING (MainThread) [homeassistant.components.rest.sensor] Empty reply found when expecting JSON data

So I’m not sure if the fact that it’s saying things like “failed with” and nothing after it or Empty reply found is a problem as this was working and I haven’t touched these yaml files in a long time but do update HA all the time.

Thoughts?

There should be an actual error message right after “failed with …”, but the next message “Empty reply…” is just an inherited error because fetching the data failed in the first place.

Not sure if it helps, but I would try increasing logging. The httpx entry is related to the underlying library used to fetch data, and the second line may tell you if there is something wrong with processing the configuration.

logger:
  default: info
  logs:
    httpx: debug
    homeassistant.components.rest: debug

Thanks for the reply. I don’t think I got anything more useable but won’t be the judge of that. Wasn’t sure what all would be important so including the whole block where it checks all the rest calls. Wish you could set the frequency of these checks to more than every 30 seconds though but probably not relevant.

2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.8:9999/api/v1/queries/check_drivesize/commands/execute?drive=c
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.8:9999/api/v1/queries/check_drivesize/commands/execute?drive=d
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.8:9999/api/v1/queries/check_memory/commands/execute
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.8:9999/api/v1/queries/check_cpu/commands/execute
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.8:9999/api/v1/queries/check_uptime/commands/execute
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.8:9999/api/v1/queries/check_ping/commands/execute?hosts=www.google.com
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.1:9999/api/v1/queries/check_drivesize/commands/execute?drive=c
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.1:9999/api/v1/queries/check_drivesize/commands/execute?drive=d
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.1:9999/api/v1/queries/check_drivesize/commands/execute?drive=e
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.1:9999/api/v1/queries/check_drivesize/commands/execute?drive=f
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.1:9999/api/v1/queries/check_memory/commands/execute
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.1:9999/api/v1/queries/check_cpu/commands/execute
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.1:9999/api/v1/queries/check_uptime/commands/execute
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.1:9999/api/v1/queries/check_ping/commands/execute?hosts=www.google.com
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.2:9999/api/v1/queries/check_drivesize/commands/execute?drive=c
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.2:9999/api/v1/queries/check_drivesize/commands/execute?drive=d
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.2:9999/api/v1/queries/check_memory/commands/execute
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.2:9999/api/v1/queries/check_cpu/commands/execute
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.2:9999/api/v1/queries/check_uptime/commands/execute
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://192.168.0.2:9999/api/v1/queries/check_ping/commands/execute?hosts=www.google.com
2021-11-30 21:02:03 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.8:9999/api/v1/queries/check_drivesize/commands/execute?drive=d "HTTP/1.1 200 "
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_drivesize","lines":[{"message":"OK All 1 drive(s) are ok","perf":{"d: used":{"critical":1.4726048436014025,"maximum":1.6362276040017605,"minimum":0.00000000000000000,"unit":"TB","value":1.1119843125343323,"warning":1.3089820832010446},"d: used %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":68.000000000000000,"warning":80.000000000000000}}}],"result":0}
2021-11-30 21:02:03 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.8:9999/api/v1/queries/check_memory/commands/execute "HTTP/1.1 200 "
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_memory","lines":[{"message":"OK: committed = 31.517GB, physical = 30.809GB","perf":{"committed":{"critical":98.997871398925781,"maximum":109.99763488769531,"minimum":0.00000000000000000,"unit":"GB","value":31.517158508300781,"warning":87.998107910156250},"committed %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":29.000000000000000,"warning":80.000000000000000},"physical":{"critical":86.397871398366988,"maximum":95.997634887695312,"minimum":0.00000000000000000,"unit":"GB","value":30.808963775634766,"warning":76.798107909969985},"physical %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":32.000000000000000,"warning":80.000000000000000}}}],"result":0}
2021-11-30 21:02:03 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.8:9999/api/v1/queries/check_cpu/commands/execute "HTTP/1.1 200 "
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_cpu","lines":[{"message":"OK: CPU load is ok.","perf":{"total 1m":{"critical":90,"maximum":0,"minimum":0,"unit":"%","value":80,"warning":80},"total 5m":{"critical":90,"maximum":0,"minimum":0,"unit":"%","value":80,"warning":80},"total 5s":{"critical":90,"maximum":0,"minimum":0,"unit":"%","value":64,"warning":80}}}],"result":0}
2021-11-30 21:02:03 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.8:9999/api/v1/queries/check_uptime/commands/execute "HTTP/1.1 200 "
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_uptime","lines":[{"message":"OK: uptime: 3w 0d 11:20h, boot: 2021-11-09 15:41:25 (UTC)","perf":{"uptime":{"critical":86400,"maximum":0,"minimum":0,"unit":"s","value":1855239,"warning":172800}}}],"result":0}
2021-11-30 21:02:03 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.1:9999/api/v1/queries/check_drivesize/commands/execute?drive=c "HTTP/1.1 200 "
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_drivesize","lines":[{"message":"OK All 1 drive(s) are ok","perf":{"c: used":{"critical":199.99687156639993,"maximum":222.21874618530273,"minimum":0.00000000000000000,"unit":"GB","value":69.991840362548828,"warning":177.77499694749713},"c: used %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":31.000000000000000,"warning":80.000000000000000}}}],"result":0}
2021-11-30 21:02:03 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.1:9999/api/v1/queries/check_drivesize/commands/execute?drive=d "HTTP/1.1 200 "
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_drivesize","lines":[{"message":"OK All 1 drive(s) are ok","perf":{"d: used":{"critical":1.4726048436014025,"maximum":1.6362276040017605,"minimum":0.00000000000000000,"unit":"TB","value":0.59854124113917351,"warning":1.3089820832010446},"d: used %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":37.000000000000000,"warning":80.000000000000000}}}],"result":0}
2021-11-30 21:02:03 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.1:9999/api/v1/queries/check_drivesize/commands/execute?drive=e "HTTP/1.1 200 "
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_drivesize","lines":[{"message":"WARNING e:: 15.821TB/18.19TB used","perf":{"e: used":{"critical":16.371275125443390,"maximum":18.190305694937706,"minimum":0.00000000000000000,"unit":"TB","value":15.820944875478745,"warning":14.552244555949983},"e: used %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":87.000000000000000,"warning":80.000000000000000}}}],"result":1}
2021-11-30 21:02:03 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.1:9999/api/v1/queries/check_drivesize/commands/execute?drive=f "HTTP/1.1 200 "
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_drivesize","lines":[{"message":"WARNING f:: 15.227TB/18.19TB used","perf":{"f: used":{"critical":16.371275085210073,"maximum":18.190305650234222,"minimum":0.00000000000000000,"unit":"TB","value":15.227194130420685,"warning":14.552244520186832},"f: used %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":84.000000000000000,"warning":80.000000000000000}}}],"result":1}
2021-11-30 21:02:03 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.8:9999/api/v1/queries/check_ping/commands/execute?hosts=www.google.com "HTTP/1.1 200 "
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_ping","lines":[{"message":"OK: All 1 hosts are ok","perf":{"www.google.com_loss":{"critical":10,"maximum":0,"minimum":0,"unit":"","value":0,"warning":5},"www.google.com_time":{"critical":100,"maximum":0,"minimum":0,"unit":"","value":12,"warning":60}}}],"result":0}
2021-11-30 21:02:03 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.1:9999/api/v1/queries/check_memory/commands/execute "HTTP/1.1 200 "
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_memory","lines":[{"message":"OK: committed = 8.256GB, physical = 6.648GB","perf":{"committed":{"critical":37.122867965139449,"maximum":41.247631072998047,"minimum":0.00000000000000000,"unit":"GB","value":8.2557792663574219,"warning":32.998104858212173},"committed %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":20.000000000000000,"warning":80.000000000000000},"physical":{"critical":32.397867965511978,"maximum":35.997631072998047,"minimum":0.00000000000000000,"unit":"GB","value":6.6483039855957031,"warning":28.798104858025908},"physical %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":18.000000000000000,"warning":80.000000000000000}}}],"result":0}
2021-11-30 21:02:03 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.1:9999/api/v1/queries/check_cpu/commands/execute "HTTP/1.1 200 "
2021-11-30 21:02:03 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_cpu","lines":[{"message":"OK: CPU load is ok.","perf":{"total 1m":{"critical":90,"maximum":0,"minimum":0,"unit":"%","value":0,"warning":80},"total 5m":{"critical":90,"maximum":0,"minimum":0,"unit":"%","value":0,"warning":80},"total 5s":{"critical":90,"maximum":0,"minimum":0,"unit":"%","value":0,"warning":80}}}],"result":0}
2021-11-30 21:02:04 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.1:9999/api/v1/queries/check_uptime/commands/execute "HTTP/1.1 200 "
2021-11-30 21:02:04 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_uptime","lines":[{"message":"OK: uptime: 2d 10:20h, boot: 2021-11-28 16:41:16 (UTC)","perf":{"uptime":{"critical":86400,"maximum":0,"minimum":0,"unit":"s","value":210053,"warning":172800}}}],"result":0}
2021-11-30 21:02:04 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.1:9999/api/v1/queries/check_ping/commands/execute?hosts=www.google.com "HTTP/1.1 200 "
2021-11-30 21:02:04 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_ping","lines":[{"message":"OK: All 1 hosts are ok","perf":{"www.google.com_loss":{"critical":10,"maximum":0,"minimum":0,"unit":"","value":0,"warning":5},"www.google.com_time":{"critical":100,"maximum":0,"minimum":0,"unit":"","value":14,"warning":60}}}],"result":0}
2021-11-30 21:02:04 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.2:9999/api/v1/queries/check_drivesize/commands/execute?drive=c "HTTP/1.1 200 "
2021-11-30 21:02:04 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_drivesize","lines":[{"message":"OK All 1 drive(s) are ok","perf":{"c: used":{"critical":419.00712547264993,"maximum":465.56347274780273,"minimum":0.00000000000000000,"unit":"GB","value":153.08797073364258,"warning":372.45077819749713},"c: used %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":33.000000000000000,"warning":80.000000000000000}}}],"result":0}
2021-11-30 21:02:04 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.2:9999/api/v1/queries/check_memory/commands/execute "HTTP/1.1 200 "
2021-11-30 21:02:04 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_memory","lines":[{"message":"OK: committed = 2.937GB, physical = 3.521GB","perf":{"committed":{"critical":32.382741164416075,"maximum":35.980823516845703,"minimum":0.00000000000000000,"unit":"GB","value":2.9365158081054687,"warning":28.784658812917769},"committed %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":8.0000000000000000,"warning":80.000000000000000},"physical":{"critical":16.192185973748565,"maximum":17.991317749023438,"minimum":0.00000000000000000,"unit":"GB","value":3.5211410522460938,"warning":14.393054198473692},"physical %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":20.000000000000000,"warning":80.000000000000000}}}],"result":0}
2021-11-30 21:02:04 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.2:9999/api/v1/queries/check_cpu/commands/execute "HTTP/1.1 200 "
2021-11-30 21:02:04 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_cpu","lines":[{"message":"OK: CPU load is ok.","perf":{"total 1m":{"critical":90,"maximum":0,"minimum":0,"unit":"%","value":10,"warning":80},"total 5m":{"critical":90,"maximum":0,"minimum":0,"unit":"%","value":1,"warning":80},"total 5s":{"critical":90,"maximum":0,"minimum":0,"unit":"%","value":13,"warning":80}}}],"result":0}
2021-11-30 21:02:04 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.2:9999/api/v1/queries/check_uptime/commands/execute "HTTP/1.1 200 "
2021-11-30 21:02:04 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_uptime","lines":[{"message":"OK: uptime: 4w 1d 03:44h, boot: 2021-11-01 23:17:09 (UTC)","perf":{"uptime":{"critical":86400,"maximum":0,"minimum":0,"unit":"s","value":2519095,"warning":172800}}}],"result":0}
2021-11-30 21:02:04 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.2:9999/api/v1/queries/check_ping/commands/execute?hosts=www.google.com "HTTP/1.1 200 "
2021-11-30 21:02:04 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_ping","lines":[{"message":"OK: All 1 hosts are ok","perf":{"www.google.com_loss":{"critical":10,"maximum":0,"minimum":0,"unit":"","value":0,"warning":5},"www.google.com_time":{"critical":100,"maximum":0,"minimum":0,"unit":"","value":11,"warning":60}}}],"result":0}
2021-11-30 21:02:04 DEBUG (MainThread) [httpx._client] HTTP Request: GET https://192.168.0.8:9999/api/v1/queries/check_drivesize/commands/execute?drive=c "HTTP/1.1 200 "
2021-11-30 21:02:04 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"command":"check_drivesize","lines":[{"message":"OK All 1 drive(s) are ok","perf":{"c: used":{"critical":200.18935203552246,"maximum":222.43261337280273,"minimum":0.00000000000000000,"unit":"GB","value":64.615943908691406,"warning":177.94609069824219},"c: used %":{"critical":90.000000000000000,"maximum":100.00000000000000,"minimum":0.00000000000000000,"unit":"%","value":29.000000000000000,"warning":80.000000000000000}}}],"result":0}
2021-11-30 21:02:09 DEBUG (MainThread) [httpx._client] HTTP Request: POST http://192.168.0.20/goform/AppCommand.xml "HTTP/1.0 200 OK"
2021-11-30 21:02:13 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.mediacenter_d_drive_used is taking over 10 seconds
2021-11-30 21:02:14 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: https://192.168.0.2:9999/api/v1/queries/check_drivesize/commands/execute?drive=d failed with
2021-11-30 21:02:14 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: None
2021-11-30 21:02:14 WARNING (MainThread) [homeassistant.components.rest.sensor] Empty reply found when expecting JSON data

If I run this manually telnetted into HA I get:

curl --insecure -u admin https://192.168.0.2:9999/api/v1/queries/check_drivesize/commands/execute?drive=d
Enter host password for user ‘admin’:
{“command”:“check_drivesize”,“lines”:[{“message”:“OK All 1 drive(s) are ok”,“perf”:{“d: used”:{“critical”:4.9112165417518554,“maximum”:5.4569072686135769,“minimum”:0.00000000000000000,“unit”:“TB”,“value”:0.97120798751711845,“warning”:4.3655258148901339},“d: used %”:{“critical”:90.000000000000000,“maximum”:100.00000000000000,“minimum”:0.00000000000000000,“unit”:"%",“value”:18.000000000000000,“warning”:80.000000000000000}}}],“result”:0}homeassistant@

I guess the interesting bit here is that you are not executing a single request, but many requests at the same time. Is there a chance that the device/server you are querying is unable to cope with the amount of concurrent requests?

This may indicate that HA is about to just give up, which results in an empty result.
You could try migrating your configuration to the new rest integration which allows you to configure the timeout.

Thanks. Isn’t this rest integration what I’m already using? I can try changing the timeout, but was really trying to slow down the frequency of the rest calls. Once every 30 seconds with no configuration seems to much for my use right now. Not sure how the timeout would work. Since these are fast servers, if it hasn’t returned in 10 seconds it isn’t going to. So the question then comes down to is it waiting or retrying during those 10 seconds as the call takes milliseconds?

Sorry, just realised that you can actually configure a timeout for a rest sensor.

Yes, you are using the rest integration, but there are two different ways to set up sensors - either set up each sensor separately with its dedicated URL, or - if supported by your device - use one rest call to retrieve data for multiple sensors and binary sensors.
This second option allows you to configure the scan_interval which is the frequency of making the rest call.

Waiting and not retrying.