def main_loop(): idx = 0 sub_idx = 0 while True: # run gettext for each required module for mod in mods: if mod["countdown"] == 0: if mod[get_text] != None: mod["text"] = mod[get_text]() else: mod["text"] = [] mod["countdown"] = mod[get_update_freq] else: mod["countdown"] = mod["countdown"] - 1 # build the time string msg1 = time.strftime("%d-%b-%Y %H:%M:%S") # if zero-length mods, blank second line if len(mods) == 0: msg2 = "" else: # See if we've exceeded the sub index while sub_idx >= len(mods[idx]["text"]) or mods[idx]["text"][sub_idx] == None: sub_idx = 0 idx = idx + 1 # See if we've exceeded the index if idx >= len(mods): idx = 0 # Load the string msg2 = mods[idx]["text"][sub_idx] # Increment counter for next run sub_idx = sub_idx + 1 ## Display the messages if opts.debug == True: print(msg1) print(msg2) print() else: send_thecus.write_message(msg1 = msg1, msg2 = msg2, port = opts.port) time.sleep(1)
def main_loop(): maintimer = 0 smarttimer = 0 apcaccesstimer = 0 next_info_count = 0 md_info_count = next_info_count next_info_count += 1 if(opts.smartctl): smartctl_info_count = next_info_count next_info_count += 1 if(opts.apcaccess): apcaccess_info_count = next_info_count next_info_count += 1 while True: msg1 = time.strftime("%d-%b-%Y %H:%M:%S") if(opts.smartctl and smarttimer == 0): raid_msg = smartctl_interface.get_smart_info() if(opts.apcaccess and apcaccesstimer == 0): apcaccess_msg = apcaccess_interface.get_apcaccess_info() raid_db = monitor.get_status() try: if opts.rdev is None: my_rdev = raid_db.values().__iter__().__next__() else: my_rdev = raid_db[opts.rdev] if my_rdev.status == "active": msg2 = "RAID: Healthy" else: msg2 = "RAID: " + my_rdev.status except: msg2 = "RAID: not found" if(opts.smartctl and maintimer % next_info_count == smartctl_info_count): msg2 = raid_msg if(opts.apcaccess and maintimer % next_info_count == apcaccess_info_count): msg2 = apcaccess_msg if opts.debug == True: print(msg1) print(msg2) print() else: send_thecus.write_message(msg1 = msg1, msg2 = msg2, port = opts.port) smarttimer += 1 if(smarttimer == opts.smartctldelay): smarttimer = 0 apcaccesstimer += 1 if(apcaccesstimer == opts.apcaccessdelay): apcaccesstimer = 0 maintimer += 1 time.sleep(1)