Introduction

Users who want to import scheduling objects to the JOC Cockpit inventory find a number of options:

Import Inventory Script

The script is provided for download and can be used to automate export of Agents.

  • The script is available for Linux and MacOS® using bash, ksz, zsh, dash shell.
  • The script is intended as a baseline example for customization by JS7 users and by SOS within the scope of professional services.

Download

Download: import-inventory.sh


Sample how to export the JOC Cockpit inventory
#!/bin/sh

# ----------------------------------------
# Protocol, host and port of JOC Cockpit
JS_URL="http://localhost:4247"

# Folder that should be exported
JS_IMPORT_FOLDER="/"

# Import file
JS_IMPORT_FILE=export.zip

# Authentication (default account)
JS_USER=root
JS_PASSWORD=root
# -----------------------------------------


# -----------------------------------------
# Perform login
echo ""
echo "PERFORMING LOGIN"
JS_JSON=$(curl -k -L -s -S -X POST -m 15 --user "$JS_USER:$JS_PASSWORD" -H "Accept: application/json" -H "Content-Type: application/json" $JS_URL/joc/api/authentication/login)
JS_ACCESS_TOKEN=$(echo "$JS_JSON" | grep -Po '"accessToken":.*?[^\\]"' | awk -F ':' '{print $2}' | tr -d \" )
# -----------------------------------------


# -----------------------------------------
# Import archive
echo ""
echo "Import inventory folder: $JS_IMPORT_FOLDER"
echo "curl -v -k -L -s -S -X POST -m 15 -F \"file=@$JS_IMPORT_FILE\" -F \"format=ZIP\" -F \"overwrite=true\" -F \"targetFolder=$JS_IMPORT_FOLDER\" -H \"X-Access-Token: $JS_ACCESS_TOKEN\" -H \"Accept: */*\" $JS_URL/joc/api/inventory/import"
curl -v -k -L -s -S -X POST -m 15 -F "file=@$JS_IMPORT_FILE" -F "format=ZIP" -F "overwrite=true" -F "targetFolder=$JS_IMPORT_FOLDER" -H "X-Access-Token: $JS_ACCESS_TOKEN" -H "Accept: */*" $JS_URL/joc/api/inventory/import
# -----------------------------------------


# -----------------------------------------
# Perform logout
echo ""
echo "PERFORMING LOGOUT"
curl -k -L -s -S -X POST -m 15 -H "X-Access-Token: $JS_ACCESS_TOKEN" -H "Accept: application/json" -H "Content-Type: application/json" $JS_URL/joc/api/authentication/logout
# -----------------------------------------
echo ""