def __init__(self, host="127.0.0.1", port=9082, log=None, callback=None, polltime=None, blacklist=None, flush_interval=float('inf'), use_numeric=False, debug=False): super(MyGenPush, self).__init__() self.Callback = callback self.UseNumeric = use_numeric self.Debug = debug if polltime == None: self.PollTime = 3 else: self.PollTime = float(polltime) if log != None: self.log = log else: # log errors in this module to a file self.log = mylog.SetupLogger("client", "/var/log/mygenpush.log") self.console = mylog.SetupLogger("mygenpush_console", log_file="", stream=True) self.AccessLock = threading.Lock() self.BlackList = blacklist self.LastValues = {} self.FlushInterval = flush_interval self.LastChange = {} try: startcount = 0 while startcount <= 10: try: self.Generator = myclient.ClientInterface(host=host, log=log) break except Exception as e1: startcount += 1 if startcount >= 10: self.console.info("genmon not loaded.") self.LogError("Unable to connect to genmon.") sys.exit(1) time.sleep(1) continue # start thread to accept incoming sockets for nagios heartbeat self.Threads["PollingThread"] = mythread.MyThread( self.MainPollingThread, Name="PollingThread") except Exception as e1: self.LogErrorLine("Error in mygenpush init: " + str(e1))
if not ValidateFilePresent(file): LogError("Required file missing : startgenmon.sh") sys.exit(1) file = os.path.dirname(os.path.realpath(__file__)) + "/genmonmaint.sh" if not ValidateFilePresent(file): LogError("Required file missing : genmonmaint.sh") sys.exit(1) CacheToolTips() startcount = 0 while startcount <= 4: try: MyClientInterface = myclient.ClientInterface(host=address, port=clientport, log=log) break except Exception as e1: startcount += 1 if startcount >= 4: LogConsole("Error: genmon not loaded.") sys.exit(1) time.sleep(1) continue Start = datetime.datetime.now() while ((datetime.datetime.now() - Start).total_seconds() < 10): data = MyClientInterface.ProcessMonitorCommand("generator: gethealth") if "OK" in data:
sys.exit() elif opt in ("-a", "--address"): address = arg print ('Address is : %s' % address) elif opt in ("-f", "--filename"): fileName = arg print ('Output file is : %s' % fileName) if not len(address): print ("Address is : localhost") address = "localhost" if not len(fileName): print (HelpStr) sys.exit(2) try: log = mylog.SetupLogger("client", "kwlog2csv.log") MyClientInterface = myclient.ClientInterface(host = address, log = log) data = MyClientInterface.ProcessMonitorCommand("generator: power_log_json") data = json.loads(data) for Time, Value in reversed(data): LogToFile(fileName, Time, Value) except Exception as e1: print ("Error (1): " + str(e1))