Cloud Data Integration - Elastic : 2019 : December Skip navigation
2019

Cloud Data Integration - Elastic

December 2019 Previous month Next month

This article describes a way of automatically downloading, installing and registering a secureagent using IICS REST API.

The script requires only the IICS org username and password and the install_dir is optional. This script auto detects the operating system where its being executed and downloads the appropriate installer.

 

Pre-Requisites for the Script

 

IICS Login Credentials. If you dont have IICS login credentials you can register for a trial here Integration At Scale: Spark Serverless – Preview Registration

 

On the Linux machine make sure you have pip and requests module installed. You can can run the following commands to install pip and requests on linux.

 

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

python get-pip.py
python -m pip install requests



On the windows machine make sure have python and requests module are installed. Python can be download using this link Python Releases for Windows | Python.org

Once python is installed open command prompt and run the command "pip install requests"


Script

"""
## Usage
Check the following parameters
username = IICS username
password = IICS password
install_dir = the target directory to install secure agent
down_load_dir = the download location of secureagent, if not specified the installer will be downloaded to the script location
option = Enter the following values
  1 = Download
  2 = Download and Install
  3 = Download,Install and Register
"""
import os

import requests

import json

import sys

import time

 

######### Parameters Start ##########
username = "iics_username"
password = "iics_password"
install_dir = '/opt/infa_agent'
option = 3
base_url = "https://dm-us.informaticacloud.com/ma/api/v2/user/login"
######### Parameters End ##########

if os.name == 'posix':

  download_dir = 'agent64_install_ng_ext.bin'
if os.name == 'nt':

  download_dir = 'agent64_install_ng_ext.exe'

def get_session_id(un, pw):

   '''Authenticate with username and password and
  retrieve icSessionId and serverUrl that are used for Subsequent API calls'''
   session_id = ''
   data = {'@type': 'login', 'username': un, 'password': pw}

  url = base_url

  headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}

  r = requests.post(url, data=json.dumps(data), headers=headers)

   # print('Session Id API Response Status Code: ' + str(r.status_code))
   if r.status_code == 200:

  session_id = r.json()["icSessionId"]

  server_url = r.json()["serverUrl"]

   # print('Session Id: ' + session_id)
   else:

   print('API call failed:')

   print(r.headers)

   print(r.json())

  sys.exit(1)

 

   return session_id, server_url

 

 

def get_token():

  call_get_session_id = get_session_id(username, password)

  session_id = call_get_session_id[0]

  server_url = call_get_session_id[1]

   url = server_url + "/api/v2/agent/installerInfo/linux64"
   headers = {'Content-Type': 'application/json', 'icSessionId': session_id, 'Accept': 'application/json'}

   payload = {'application': ''}

   if os.name == 'posix':

  platform = 'linux64'
   if os.name == 'nt':

  platform = 'win64'
   r = requests.get(server_url + '/api/v2/agent/installerInfo/' + platform, headers=headers)

   print('Token API Response Status Code: ' + str(r.status_code))

  download_url = r.json()["downloadUrl"]

  install_token = r.json()["installToken"]

   print('Download Url: ' + download_url)

   print('Install Token: ' + install_token)

   return download_url, install_token

 

 

def download_secure_agent(install_download_loc):

   print(30 * '-')

   print("Downloading Secure Agent")

   print(30 * '-')

   with open(install_download_loc, 'wb') as f:

  response = requests.get(get_token()[0], stream=True)

  total = response.headers.get('content-length')

   if total is None:

  f.write(response.content)

   else:

  downloaded = 0
   total = int(total)

   for data in response.iter_content(chunk_size=max(int(total / 1000), 1024 * 1024)):

  downloaded += len(data)

  f.write(data)

  done = int(50 * downloaded / total)

  sys.stdout.write('\r[{}{}]'.format('#' * done, '.' * (50 - done)))

  sys.stdout.flush()

  sys.stdout.write('\n')

 

 

def install_secure_agent(install_loc):

   if os.name == 'posix':

   download_filename = 'agent64_install_ng_ext.bin'
   download_secure_agent(download_dir)

   print(30 * '-')

   print("Installing Linux Secure Agent")

   print(30 * '-')

  os.chmod(download_dir, 0o777)

  final_install_dir = lambda install_final_loc: "$HOME" if (not install_loc) else install_loc
   os.system('sh ' + download_dir + ' -i silent -DUSER_INSTALL_DIR=' + final_install_dir(''))

   if os.name == 'nt':

   download_filename = 'agent64_install_ng_ext.exe'
   download_secure_agent(download_dir)

   print(30 * '-')

   print("Installing Windows Secure Agent")

   print(30 * '-')

  os.chmod(download_dir, 0o777)

  final_install_dir = lambda install_final_loc: "$HOME" if (not install_loc) else install_loc
   os.system(download_dir + ' -i silent -DUSER_INSTALL_DIR=' + final_install_dir(''))

 

 

def register_secure_agent():

  install_secure_agent(install_dir)

   print(30 * '-')

   print("Registering Secure Agent")

   print(30 * '-')

  os.chdir(install_dir + "/apps/agentcore")

   if os.name == 'posix':

   start_agent = os.system("./infaagent startup")

  time.sleep(10)

  register_agent = os.system("./consoleAgentManager.sh configureToken '" + username + "' '" + get_token()[1] + "'")

   print(register_agent)

   if os.name == 'nt':

  time.sleep(10)

   register_agent = os.system('consoleAgentManager.bat configureToken ' + username + ' "' + get_token()[1] + '"')

 

 

 

if option == 1:

  download_secure_agent(download_dir)

 

if option == 2:

  install_secure_agent(install_dir)

 

if option == 3:

  register_secure_agent()

 

Script Execution

 

Save the script to a file with .py extension and run the command "python <script_name>.py"

This article describes a way to run IICS secure agent inside a Linux based docker container.

Download the attachment in the article.There are two files inside the zip file, a docker file and a script to download, install and register the secure agent.

 

The docker file downloads the centos 7 image and installs pip, python requests module and copies the script described in my previous blog Download, Install and Register Secure Agent using IICS Rest API into the image. When the image is started as a container the script is triggered which will download, install and register the secure agent.

 

 

Pre-Requisites

Docker Engine is installed and running.

 

IICS Login Credentials. If you don't have IICS login credentials you can register for a trial here Integration At Scale: Spark Serverless – Preview Registration

 

Update the secure_agent_silent_install.py script with your IICS login credentials on line 20 and 21.

 

Creating the docker Image

 

On the machine where docker engine is running download the attachment and extract the files to a directory.

Run the following command to create the base image.

 

docker build -t secure_agent:latest .

Check if the image is created successully using the command

 

docker images secure_agent

Starting the docker Image as container

 

Run the following command to start the docker image as a container, you can adjust the hostname as per your need.

 

docker run -i -d -t --hostname=sa_docker secure_agent

 

The command will start the containers and execute the secure_agent_silent_install.py script inside the container. Depending on the internet speed it should take 2-3 mins to download,install and register the agent with the IICS org.