what I need to do is , extract hostnames from the weburl which is in csx format , loop through it , extract the first column starting with xyz, assign it to a variable and use the variable in the python script to extract DNS Alias for the host.
format of the csv file is fields separated by delimiter ,
here is my code:
PS : I am unable to insert a code snippet for some reason.
format of the csv file is fields separated by delimiter ,
Quote:example : xyz.python.org,blah1,blah2,blah3
abc.python.org,some1,some2,some3
def.python.org,some1,some2,some3
xyz12.python.org,some1,some2,some3
here is my code:
#!/usr/bin/python3 import requests import json import os res = requests.get('https://myorg.csv') hostName = 'xyz.python.org' gm = "https://mygridmaster.org/" wapi = "wapi/v2.11/" ibobject = "record:host" gm_user = "myuser" gm_pwd ="mypwd" response = requests.get(gm + wapi + ibobject + '?_return_fields%2B=aliases&name=' + hostName, auth=(gm_user, gm_pwd)) members = response.json() for member in members: host = print (member['name'], end=' dns=') dnsAlias = print (member['aliases'], ) print(res.text)The code is working for me to get my output in following format
Output: hostname dns=dnsalias
the last print statement is irrelavant here, as I had it to test if the csv can be read from this code. What I am unable to get to work is, extract the hostname start with xyz from the url and pass it as a variable to hostName. There are several hundred of hostnames in the file that I will need to loop through.PS : I am unable to insert a code snippet for some reason.
Gribouillis write Jan-17-2024, 04:42 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.