Create a service check job

Create a service check job

POST api/jobs/service_check

Starts a service check job. A service check job executes the following Docker requests to one or more nodes.

Docker commandDescription and Remote Job Execution (RJE) behavior
docker psLists the running containers. For clusters, it lists the running containers on the primary node.
docker image lsLists the available container images. The output lists all available images on the node.

In order to perform this action, the following conditions must be met:

  • Must have the Docker Service Check feature turned on at the site level.
  • The user must have the following capabilities:
    • Create and Update a ServiceCheck job

Request syntax

The target for a service check job can be specified using a list of node hostnames, a node group name, a node group ID, a saved filter name, or a saved filter ID. Only one target parameter can be used per request.

Target nodes using a list of hostnames.

post api/jobs/service_check '{"hostnames":["<node_hostname>"]}'

Target nodes using a node group name.

post api/jobs/service_check '{"node_group_name":"<node_group_name>"}'

Target nodes using a node group ID.

post api/jobs/service_check '{"node_group_id":<node_group_id>}'

Target nodes using a saved filter name.

post api/jobs/service_check '{"saved_filter_name":"<saved_filter_name>"}'

Target nodes using a saved filter ID.

post api/jobs/service_check '{"saved_filter_id":<saved_filter_id>}'

Request parameters

The request accepts the following data in JSON format.

ParameterTypeDescriptionRequiredDefault value
hostnamesString arrayThe list of nodes on which to run the service check.Dependent. Only if no node group or saved filter is provided.N/A
node_group_nameStringThe name of the node group on which to run the service check. The service check will run on all nodes that are members of the node group.Dependent. Only if no hostnames or saved filter is provided.N/A
node_group_idIntegerThe ID of the node group on which to run the service check. The service check will run on all nodes that are members of the node group.Dependent. Only if no hostnames or saved filter is provided.N/A
saved_filter_nameStringThe name of the saved filter on which to run the service check. The service check will run on all nodes that match the saved filter.Dependent. Only if no hostnames or node group is provided.N/A
saved_filter_idIntegerThe ID of the saved filter on which to run the service check. The service check will run on all nodes that match the saved filter.Dependent. Only if no hostnames or node group is provided.N/A

Response syntax

When the hostnames request parameter is used, the following response syntax is received.

{
    "id": integer,
    "type": "Service Check",
    "status": "string",
    "message": "string",
    "trigged_by": "string",
    "parameters": {
        "hostnames": [
            "string",
            "string"
        ]
    },
    "time_started": "timestamp"
}

When the node group or saved filter request parameters are used, the following response syntax is received.

{
    "id": integer,
    "type": "Service Check",
    "status": "string",
    "message": "string",
    "trigged_by": "string",
    "parameters": {
        "node_group_name": "string",
        "node_group_id": integer,
        "saved_filter_name": "string",
        "saved_filter_id": integer
    },
    "time_started": "timestamp"
}

Response parameters

If the action is successful, an HTTP 200 response is returned. The following data is returned in JSON format.

FieldTypeDescription
idIntegerThe ID of the service check job.
typeStringThe type of job. For service checks, it is Service Check.
statusStringThe status of the job.
messageStringThis field is reserved for internal use.
trigged_byStringThe username of the person who initiated the job.
parametersStringThe request parameters indicating the hostnames, node groups, or saved filters the service check job ran on.
time_startedTimestampThe timestamp indicating when the service check job started. The timestamp is given in ISO 8601 UTC datetime format.

The following data is returned if you include the payload.

ParameterDescription
errorAny errors received from the service check.
outputThe output from the service check. This includes data from the Docker commands.
exitcodeThe exit code returned from the service check.

Errors

The following are common errors returned by this API. For a list of additional common errors, see Common errors.

CodeMessageCause
400The job target is missing, please specify targets using the fields: hostnames, node_group_id, node_group_name, saved_filter_id or saved_filter_name.The request didn't include a target. Edit the request and include at least one target and try again.
400Please use only one target parameterThe request included multiple target parameters. Verify the request only specifies a single target and try again.
400Hostnames <hostnames> does not exist.The request specified a hostname that doesn't exist. Verify the request and try again.
400The node group name <node_group_name> does not exist.The request specified a node group name that doesn't exist. Verify the request and try again.
400Node group id <node_group_id> does not exist.The request specified a node group ID that doesn't exist. Verify the request and try again.
400Filter title <filter_name> does not exist.The request specified a saved filter name that doesn't exist. Verify the request and try again.
400Filter id <filter_id> does not exist.The request specified a saved filter ID that doesn't exist. Verify the request and try again.
403Service Check feature disabled!The Docker Service Check feature is turned off at the site level. Have an Administrator turn it on and try again.
422An unfinished job was found with the same type, parameters and username (id: <existent job id>).A similar job is already running. Wait until that job completes before starting a new job.
500An unexpected error happened. Please contact support!An unexpected error, such as an internal error occurred. Contact support.

Examples

Example 1: Start a service check job using a list of hostnames.

This example starts a service check job for nodes with hostnames sit0016red0 and sit0016red1.

ruby api.rb <customer_code> post api/jobs/service_check '{"hostnames":["sit0016red0","sit0016red1"]}'

Response

{
    "id": 1541246,
    "type": "Service Check",
    "status": "pending",
    "message": null,
    "trigged_by": "test.user",
    "parameters": {
        "hostnames": [
            "sit0016red0",
            "sit0016red1"
        ]
    },
    "time_started": "2024-09-03T18:47:57Z"
}

Example 2: Start a service check job using a node group name.

This example starts a service check job for all nodes in the node group Test Node Group.

ruby api.rb <customer_code> post api/jobs/service_check '{"node_group_name":"Test Node Group"}'

Response

{
    "id": 1541258,
    "type": "Service Check",
    "status": "pending",
    "message": null,
    "trigged_by": "test.user",
    "parameters": {
        "node_group_name": "Test Node Group"
    },
    "time_started": "2024-09-03T19:05:12Z"
}

Example 3: Start a service check job using a node group ID.

This example starts a service check job for all nodes in node group ID 42.

ruby api.rb <customer_code> post api/jobs/service_check '{"node_group_id":42}'

Response

{
    "id": 1541251,
    "type": "Service Check",
    "status": "pending",
    "message": null,
    "trigged_by": "test.user",
    "parameters": {
        "node_group_id": 42
    },
    "time_started": "2024-09-03T19:16:04Z"
}

Example 4: Start a service check job using a saved filter name.

This example starts a service check job for nodes included in the saved filter named Test nodes. The filter name is case sensitive.

ruby api.rb <customer_code> post api/jobs/service_check '{"saved_filter_name":"Test nodes"}'

Response

{
    "id": 1541275,
    "type": "Service Check",
    "status": "pending",
    "message": null,
    "trigged_by": "test.user",
    "parameters": {
        "saved_filter_name": "Test nodes"
    },
    "time_started": "2024-09-03T19:22:38Z"
}

Example 5: Start a service check job using a saved filter ID.

This example starts a service check job for all nodes that match saved filter ID 17.

ruby api.rb <customer_code> post api/jobs/service_check '{"saved_filter_id":17}'

Response

{
    "id": 1541285,
    "type": "Service Check",
    "status": "pending",
    "message": null,
    "trigged_by": "test.user",
    "parameters": {
        "saved_filter_id": 17
    },
    "time_started": "2024-09-03T19:28:15Z"
}

Retrieve the payload from a service check job.

This example retrieves the payload from service check job with ID 1541246.

ruby api.rb <customer_code> get api/jobs/1541246\?include_payload=true

Response

{
    "id": 1541246,
    "type": "Service Check",
    "status": "finished",
    "message": null,
    "payload": {
        "success_nodes": {
            "sit0016red0": [
                {
                    "error": "",
                    "output": [],
                    "exitcode": 0
                },
                {
                    "error": "",
                    "output": [
                        {
                            "ID": "e376bb7e6bde",
                            "Tag": "latest",
                            "Size": "148MB",
                            "Digest": "<none>",
                            "CreatedAt": "2024-07-17 19:31:14 -0400 EDT",
                            "Containers": "N/A",
                            "Repository": "httpd",
                            "SharedSize": "N/A",
                            "UniqueSize": "N/A",
                            "VirtualSize": "148.2MB",
                            "CreatedSince": "7 weeks ago"
                        }
                    ],
                    "exitcode": 0
                }
            ]
        }
    },
    "trigged_by": "test.user",
    "success_nodes_count": 1,
    "failed_nodes_count": 0,
    "total_nodes_count": 1,
    "parameters": {
        "hostnames": [
            "sit0016red0"
        ]
    },
    "time_started": "2024-09-05T02:37:13Z",
    "time_finished": "2024-09-05T02:37:15Z"
}