ºÚÁϺ£½Ç91Èë¿Ú

Use Command Triggers

To use command triggers, enter a trigger name associated with a command that you create in DEVICE MANAGEMENT > Commands, and then save the command.

When ºÚÁϺ£½Ç91Èë¿Ú receives a webhook containing the trigger name, ºÚÁϺ£½Ç91Èë¿Ú will automatically execute any command with that trigger name, in parallel, across all the servers defined in the saved commands.

This lets you automate some very powerful actions on your network, such as:

  • Remotely restart your web servers, all at the same time
  • Integrate with your monitoring solution to join actions with monitoring thresholds, such as disks filling up, or performance issues
  • Remotely start a database backup

… and much, much more.

Basic Trigger Execution

To execute a trigger, form a webhook request as follows (shown below as a curl command, run from bash and as a PowerShell command):

!/bin/bash
jumpCloudAPIKey=""
triggerName="myTriggerName"
curl --silent \
-X 'POST' \
-H "x-api-key: ${jumpCloudAPIKey}" \
"https://console.jumpcloud.com/api/command/trigger/${triggerName}"
PS /PowerShell>
$APIkey = 'jumpCloudAPIKey'
$triggerName = 'myTriggerName'
$TriggerURL = "https://console.jumpcloud.com/api/command/trigger/$triggerName"
$hdrs = @{}
$hdrs.Add("Accept","application/json")
$hdrs.Add("X-API-KEY","$APIkey")
Invoke-RestMethod -Method POST -Uri $TriggerURL -Header $hdrs

Upon receipt of this request, assuming the API key is correct and that one or more commands are set to run based on the trigger name "myTriggerName", ºÚÁϺ£½Ç91Èë¿Ú will start all commands that match the trigger name "myTriggerName".

To obtain your API key, select your user name in the upper right corner of the ºÚÁϺ£½Ç91Èë¿Ú console, and select My API Key.

Sending Data with a Trigger

ºÚÁϺ£½Ç91Èë¿Ú allows you to post a JSON object with a trigger. ºÚÁϺ£½Ç91Èë¿Ú will provide each top level data object as an environment variable to the triggered command. This allows you to do things like:

  • Pass the source IP address of an attack in progress and automatically take action to block it.
  • Pass the name of a service to be restarted
  • Pass a query to script to execute

… and much more.

To send data to a Trigger, you change the webhook call to include as part of the body of the POST request, a well-formatted JSON object.

!/bin/bash
jumpCloudAPIKey="my_user_API_key"
triggerName="myTriggerName"
curl --silent \
-X 'POST' \
-H "x-api-key: ${jumpCloudAPIKey}" \
-H 'Content-Type: application/json' \
-d '{ "srcip":"192.168.2.32" }' \
"https://console.jumpcloud.com/api/command/trigger/${triggerName}"
Remember that only the top level objects are provided to the command, any sub-objects or arrays will be sent as "[object Object]".

For example, sending:

{ "srcip":"192.168.2.32", "test":{ "bob":"1", "jane":"3"} }

Results in the following environment variables in your command:

test="[object Object]"
srcip="192.168.2.32"

Back to Top

List IconIn this Article

Still Have Questions?

If you cannot find an answer to your question in our FAQ, you can always contact us.

Submit a Case