API v2.0 POST Response

HungrySkeltal

Dabbler
Joined
Apr 17, 2020
Messages
11
Hi all,

I'm attempting to use the REST API v2.0 to get the current state of the unbound service running in my unbound jail.

By SSHing into FreeNAS, I can type:
Code:
iocage exec unbound 'service unbound status'
and receive the response
Code:
unbound is running as pid 50903.

So I'm attempting to replicate this behaviour via curl, however my best attempts only return an integer value (e.g. '5880'), not the actual 'unbound is running' text.

This is my curl command (user and password redacted of course):
Code:
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST http://192.168.1.5/api/v2.0/jail/exec -u USERNAME:PASSWORD -d "{ \"jail\": \"unbound\", \"command\": [ \"service unbound status\" ]}"

Is there something I'm missing here that will allow me to get the text response?

Any help would be awesome - thanks :)
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
I did some poking around in /usr/local/lib/python3.7/site-packages/middlewared/plugins/jail.py. Lines 1340-1370 contain the logic for the jail exec API call. The integer value you're getting is the process ID of the wrapped shell invocation in line 1359. Any output from the command is lost when the invoked shell exits.
 

HungrySkeltal

Dabbler
Joined
Apr 17, 2020
Messages
11
Thanks for looking into it @Samuel Tai :)

Is there anyway to get the output beyond just the process ID (extract the command output before the shell exits)? I've been trying a bunch of different -options for curl but haven't found anything so far... I'm a hobbyist, not a pro, so my skills are rather limited :eek:
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
I don't believe so. You may want to try a different tack. Perhaps a cronjob running a shell script to run the iocage exec command, ending with a non-zero return value to trigger the system alert service, which would then e-mail you the text output?
 

HungrySkeltal

Dabbler
Joined
Apr 17, 2020
Messages
11
hmm, well I was planning to use a direct REST API call in my home assistant to update a sensor showing if unbound was running (I use this for many other things such as jail status, FreeNAS system health, etc). Disappointing it can't be done directly via the API, but such is life! Back to the drawing board :tongue:

Thanks for the help :smile:
 
Top