sensor = PingWatchdogSensor() # these options are needed by the server to # differentiate between the registered sensors sensor.id = int(item.find("general").attrib["id"]) sensor.description = str( item.find("general").attrib["description"]) sensor.alertDelay = int(item.find("general").attrib["alertDelay"]) sensor.triggerAlert = (str( item.find("general").attrib["triggerAlert"]).upper() == "TRUE") sensor.triggerAlertNormal = (str( item.find("general").attrib["triggerAlertNormal"]).upper() == "TRUE") sensor.triggerState = 1 sensor.alertLevels = list() for alertLevelXml in item.iterfind("alertLevel"): sensor.alertLevels.append(int(alertLevelXml.text)) # ping specific options sensor.timeout = int(item.find("ping").attrib["timeout"]) sensor.intervalToCheck = int( item.find("ping").attrib["intervalToCheck"]) sensor.host = str(item.find("ping").attrib["host"]) sensor.execute = makePath(str(item.find("ping").attrib["execute"])) # check if description is empty if len(sensor.description) == 0: raise ValueError("Description of sensor %d is empty." % sensor.id)
for item in configRoot.find("sensors").iterfind("sensor"): sensor = PingWatchdogSensor() # these options are needed by the server to # differentiate between the registered sensors sensor.id = int(item.find("general").attrib["id"]) sensor.description = str(item.find("general").attrib[ "description"]) sensor.alertDelay = int(item.find("general").attrib["alertDelay"]) sensor.triggerAlert = (str(item.find("general").attrib[ "triggerAlert"]).upper() == "TRUE") sensor.triggerState = int(item.find("general").attrib[ "triggerState"]) sensor.alertLevels = list() for alertLevelXml in item.iterfind("alertLevel"): sensor.alertLevels.append(int(alertLevelXml.text)) # ping specific options sensor.timeout = int(item.find("ping").attrib[ "timeout"]) sensor.intervalToCheck = int(item.find("ping").attrib[ "intervalToCheck"]) sensor.host = str(item.find("ping").attrib[ "host"]) sensor.execute = str(item.find("ping").attrib[ "execute"]) # check if description is empty if len(sensor.description) == 0: