27 lines
		
	
	
	
		
			693 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
	
		
			693 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import json
 | |
| import logging
 | |
| 
 | |
| import requests
 | |
| 
 | |
| 
 | |
| def send_to_server(url, data):
 | |
|     requests.post(url, data=data)
 | |
| 
 | |
| 
 | |
| def create_sd_file(jobs, labels, url=None, filename=None):
 | |
|     file_discovery_data = json.dumps([
 | |
|         {
 | |
|             "labels": dict(**job.labels, **labels),
 | |
|             "targets": job.targets,
 | |
|         }
 | |
|         for job in jobs
 | |
|     ], indent=4, sort_keys=True)
 | |
| 
 | |
|     if url is not None:
 | |
|         logging.info('Sending discovery data to %s', url)
 | |
|         send_to_server(url, file_discovery_data)
 | |
| 
 | |
|     if filename is not None:
 | |
|         logging.info('Writing discovery file at %s', filename)
 | |
|         with open(filename, 'w') as outfile:
 | |
|             outfile.write(file_discovery_data)
 |