Support Center

How to use Command Triggers

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

When JumpCloud receives a webhook containing the trigger name, JumpCloud 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="<my_user_API_key>"
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", JumpCloud 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 JumpCloud console, and select "API Settings".


Sending Data with a Trigger

JumpCloud allows you to post a JSON object with a trigger. JumpCloud 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"
 
 
 

Last Updated: Nov 20, 2017 03:24PM MST

Related Articles
31b11a79e2c94470a66430cfe6d3eecd@jumpcloud.desk-mail.com
https://cdn.desk.com/
false
desk
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete