Here is a sample XML file:
************************
Python Code
************************
def get_client_settings (element):
# This function gets client details from XML file
ip_attrib = element.get('ip')
username_attrib = element.get('username')
password_attrib = element.get('password')
email_attrib = element.get ('mail')
for alert in element.findall('alert'):
if alert.get('type').lower() == 'memory':
mem_alert = float(alert.get('limit').replace('%',''))
if alert.get('type').lower() == 'cpu':
cpu_alert = float(alert.get('limit').replace('%',''))
return (ip_attrib, username_attrib, password_attrib, email_attrib, mem_alert, cpu_alert)
for element in root_element.findall('client'):
print ('\nGetting user details')
ip, username, password, email, mem_limit, cpu_limit = get_client_settings (element)
No comments:
Post a Comment