Reset IP address(es) of device(s) to the results of a DNS lookup or a manually set address
# For hosts with 'powered off' vsphere redunancy, the below updates the IP immediatly following failovers.
# This transaction is blocking, so minimize additions to list.
if evt.device in ('globalname1','globalname2'):
evt.message = '%s %s' % (evt.message, evt.device)
import socket, sys
DNSIP = socket.gethostbyname(evt.device) # get the IP address from DNS
if (device.manageIp != DNSIP): # if the devices IP doesnt match the DNSIP
from transaction import commit
device.setManageIp(DNSIP) # set the new IP on the device, push and commit.
evt.message += "\nThe IP address was reset to match DNS." #downgrade the event to informational
evt.severity = 2
except Exception as e:
evt.message = "%s %s" % (evt.message, e)