Custom Collector Package files are uploaded by the user through the below POST API. The package uploaded is validated, verified and persisted in the HDFS repository.

The validation involves extraction of the Collector Package, validating the extension and the Syntax of Python script file present as part of the Collector Package using Flake8. The name, file and type fields are mandatory, where type refers to package type and can be ‘snmp’, ‘rest’, ‘kafka’.

 POST: {{TCO_URL}}/dcc/v1/packages

Use below curl command to upload the custom collector package.

curl -X POST ":/dcc/v1/PACKAGES" -u 'user:password' --form 'name="{package_name}"' \ --form 'description="{package_description}"' \ --form 'file=@"/{file_path}"' \ --form 'type="{package_type}"'

@custom_collector_v1.route('/packages', methods=['POST'])
def upload_collector_package():
…………
file = request.files['file']
if file.filename == '':    
raise Exception("file not selected for uploading, File is a mandatory")
if file and allowed_file(file.filename):    
filename = secure_filename(file.filename)    
if not os.path.exists(temp_folder_name):        os.makedirs(temp_folder_name)    
file.save(os.path.join(temp_folder_name, filename))    
resp = jsonify({'name': name, 'description': description, 'message': 'File successfully uploaded'})    
resp.status_code = 200    
validate_status = validate_package(temp_folder_name, filename)