How to understand if host is up or down using API?



  • I’m using VirtualBox 6.0.14 where there is an ubuntu 18:04 machine with FOG server, DHCP server and DNS.

    I need to know when a VM is up or down using API. I see in the host management panel when the host is up a green indicator icon and when I step over it the word FOS appears. It appears after the configuration of DNS.
    I would like to query FOG server and receive an information about its status but if I do this using python:

    r = requests.get(ip_address+'/fog/host', headers=headers)
    
    print('RESPONSE: ',r.content)
    

    I cannot see difference between when the host is down or up.
    Does anyone know how can I do, please?



  • Thank you!


  • Senior Developer

    Also added this to the latest dev-branch.


  • Senior Developer

    @davide1611 To limit how the page needs to present it (attempt to make the api calls more implicit as it is stateless so why not use what we can.

    For working-1.6 I’ve added pingstatuscode and pingstatustext which will present the physical code and the socket_strerror from php.



  • @Tom-Elliott Thanks for your feedback. Everything very clear.
    Last thing, I receive from GET: /fog/host the field pingstatus as an HTML tag:

    "pingstatus": "<i class=\\"icon-ping-fos fa fa-cogs green\\" data-toggle=\\"tooltip\\" data-placement=\\"right\\" title=\\"FOS\\"><\\/i>",
    

    Do you know why it is HTML tag rather than an error code? Thanks.


  • Senior Developer

    To add on,

    Even if FOG provided an on the fly method, it’s no different than doing it programmatically within the API script being called.

    For example:

    On the fly would, when you try to get the host, you’d have to get the names/ids of the host, then call the api to get the on the fly status.

    So:

    1. API call to get host/hosts you want.
    2. API call to get the status on the fly.

    Using the “let’s ping the host ourselves”:

    1. API call to get the host/hosts you want.
    2. Looping through those hosts returned, ping the host to get the status.

    Either way, you’re doing multiple calls.

    Why 2 requests in either way?

    If you were to get an on the fly status of all hosts at the time the API request is made for every host, you’d be blocking the server until all those hosts status’ returned.


  • Senior Developer

    @george1421 The ping status field of the host is updated every 5 minutes.

    If it’s not a 0, it’s unreachable or has some issue one way or the other.

    This field can be retrieved off the host element.

    JSON = hosts[0].pingstatus should work.

    If you’re looking for on the fly up/down status, no, that does not exist. It would be recommended as a part of the api call to do a ping of the host name.

    So:

    API call -> Get hosts and names -> loop through those hosts and ping to determine status on the fly. It’s pretty simple I think.


  • Moderator

    @Tom-Elliott Thank you for the feedback. Do you know if there is a way via the API to see if FOG is reporting if the target system is up or down? I think that is the root of what the OP is looking for. I think a simple yep or nope on a api status call would be good enough (speaking not really knowing the intent of the OP).


  • Senior Developer

    @george1421 The IP field was a remnant of before 0.32 days. It has since been done away with, at least from within the GUI. The field is still present, but does not get populated.

    I believe this was used before DNS capabilities were added to the init’s, and the IP field was likely a required field.

    The IP field has no bearing on up or down status.

    In more recent versions, the PING Status field is an indicator. This is a host field and is updated every 5 minutes (by default).

    It uses error codes to obtain status’ though. https://gist.github.com/gabrielfalcao/4216897


  • Developer

    @davide1611 @george1421 I have this on my list but didn’t get to it yet. Will be soon.


  • Moderator

    @davide1611 said in How to understand if host is up or down using API?:

    When I call GET on /fog/host I receive a JSON with a key-value field “ip”:"" but it’s always empty.

    To answer this we will probably need to get an @Developer to respond. One thing you will need to confirm is that the FOG server can resolve the target computer name to DNS name to IP address properly. A simple way to check is to log into the fog server and try to ping a target computer by the name FOG knows the host as without the FQDN name. So if the computer is known as usnyc002 try to ping with this command ping usnyc002 with no domain name. If the system responds with the correct IP address and a ping is returned then the FOG server is setup correctly.



  • This post is deleted!


  • @george1421 Yes it should be easier but I prefer to work through FOG APIs.
    Make use of ping from my script directly to VM would result to get access to VM from two different point: the script and the FOG server and it may be complicated to manage.

    When I call GET on /fog/host I receive a JSON with a key-value field “ip”:"" but it’s always empty. Resolving this (understanding why it is always empty), I would only receive the IP when the host is up. Or another field?


  • Moderator


Log in to reply
 

253
Online

7.0k
Users

14.2k
Topics

134.4k
Posts