Platform

Platform

 View Only

Datalink Automation Python Script 

Tue July 26, 2016 04:04 PM

This tool will automate the creation of Datalink connectors (Local or SFTP) based off of a maintained CSV list of files.

 

Installation:

  1. This script is written in Python and so a Python environment is required before utilizing this tool.  Please see Setting up a Python Environment
  2. Download the .ZIP file attached to this document and Unzip the contents
  3. This tool requires only one Python module that does not come as part of the standard library.  In order to install this module, open your command prompt and enter the following command:
    • pip install requests

Tool Contents

The ZIP file contains the following directory structure that houses the tool:

Datalink Automation Tool

| - settings

| - | - metadata.txt

| - | - templateList.csv

| - log

| - | - activityLog.csv

| - | - failureLog.csv

| - main.py

| - rest_utils.py

| - dataload.py

 

The main.py file is the meat of the tool.  The rest_utils.py and dataload.py files house code utilized by the main.py file.

The 'log' subdirectory houses two files that contain information regarding the last run of the tool.

The 'settings' subdirectory houses two files that configure how the tool runs.

    • metadata.txt contains data that will be shared across all connectors created by the script
    • templateList.csv contains the list of connectors to be created or deleted

 

General Usage

Tool Configuration

To configure the tool, you will need to modify the two files within the 'settings' subdirectory.

metadata.txt

This file contains metadata that will be utilized across all connectors created in a single execution of the tool.  The following information will be necessary for the script to run without error.

Datalink General Info

DATALINK_MANAGER - The URL to the Datalink Manager

DATALINK_AGENT - The name of the Datalink Agent

Apptio Destination

INSTANCE_APPTIO - The Apptio instance

NAME_DOMAIN - The Domain within the Apptio instance

NAME_PROJECT - The Project within the Domain

Scheduling Information

SCHEDULE_INTERVAL - Frequency of Schedule.  Expected values: MANUAL, DAILY, WEEKLY

SCHEDULE_WEEKDAY - Day of execution.  Necessary only for WEEKLY interval

SCHEDULE_HOUR - Hour in UTC Time Zone of execution.  Values: 0-23

SCHEDULE_MINUTE - Minute in Hour of execution. Values: 0-59

Apptio Domain Credentials

USERNAME_APPTIO - Username of Apptio Project Credentials

PASSWORD_APPTIO - Password for Apptio Project Credentials

Connector Name Prefix

CONN_PREFIX - Prefix that will be applied to the front of the Connector Name

Connector Type

CONN_TYPE - Type of Connector to be created.  Expected values: LOCAL, SFTP

File Source Information

DIR_FILE - Source directory location of file

DIR_ARCHIVE - Directory location to move uploaded files

SFTP Information (if using SFTP Connector)

SFTP_SERVER - SFTP Instance

SFTP_USERNAME - Username for SFTP Instance

SFTP_PKPATH - Path on SFTP Server to Private Key

SFTP_PASSPHRASE - Passphrase to Private Key stored on SFTP Server

 

templateList.csv

This file contains a list of the connectors to be managed by the script.  There are 3 columns of data that need to be provided:

Filename - The filename pattern to be utilized for the connector.  Date information is expected within the pattern.  For more information please refer to Datalink Filename Patterns

Table Name - The target table within the designated Apptio project

Delete Flag - Binary flag to instruct the tool to delete an existing connector.  Values: 0 = False; 1 = True

 

Connector Creation

  1. Configure the metadata.txt and templateList.csv files under the 'settings' sub-directory
  2. Open Command Prompt and navigate to the directory where the "Datalink Automation Tool" directory where the tool was extracted
  3. Run the following command:
    • python main.py

The script will display the current step along with a time stamp showing how long the script has been running.







#Datalink

Statistics
0 Favorited
11 Views
1 Files
0 Shares
8 Downloads
Attachment(s)
zip file
Datalink Automation Tool_v2.zip   10 KB   1 version
Uploaded - Tue October 29, 2024

Comments

Thu June 11, 2020 04:52 PM

It should also be stated that the creation of these connectors is possible, and at times easier to accomplish, from within the DataLink Manager UI interface.  This script was built to facilitate a use case wherein a customer needed to dynamically create and maintain hundreds of connectors.  But the principles herein could be used to build similar scripts if desired.


#Datalink

Thu June 11, 2020 04:49 PM

Hello Nykolas,

 

DataLink in itself is not a data repository where you can load data.  Rather, DataLink is a data transfer tool that we utilize to transmit data from one source to another - typically this destination is an Apptio project (i.e. Cost Transparency or the like) but there are other fringe cases for alternative destinations.

 

This particular script is utilized to create these data transfer jobs (called "connectors") within DataLink that can then be used to transfer data.  However, the same API can be utilized to run said connectors as well.

 

-Greg


#Datalink

Thu June 11, 2020 03:31 PM

Thanks for the post. Using this library, is it possible to upload files to DataLink from a Python script?

 

Thanks

Nykolas


#Datalink

Fri May 26, 2017 02:17 PM

Hello Prem,

 

To @Ken Haniu's comment - yes you can add multiple files to the templateList.csv file to accommodate as many files as needed in your use case.  One connector would be created for each line (or file) listed in your template list, if it did not exist already.

 

-Greg


#Datalink

Wed May 24, 2017 09:51 AM

Thank you, Ken! 


#Datalink

Wed May 24, 2017 02:41 AM

Greg could probably provide more context, but it looks like you can add multiple entries to the templateList.csv file to process multiple files. If you need it to loop through an arbitrary number of files that match a pattern, you'd have to add the looping logic to the script.

 

We do have plans to add the ability to process multiple files that match a pattern in one connector run, but we need a feature added to the Studio API to allow DataLink to manage the checkout/checkin timing in R12 intelligently before we do.


#Datalink

Tue May 23, 2017 04:13 PM

Thank you for the post. I have one question at this time: does this tool loads multiple files located in a folder?

 

Thanks

Prem


#Datalink