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 = SetupLogger("client", "/var/log/mygenpush.log") self.console = 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 = 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(self.MainPollingThread, Name="PollingThread") except Exception as e1: self.LogErrorLine("Error in mygenpush init: " + str(e1))
def __init__(self, host=ProgramDefaults.LocalHost, port=ProgramDefaults.ServerPort, log = None, loglocation = ProgramDefaults.LogPath, onready = None, onexercise = None, onrun = None, onrunmanual = None, onalarm = None, onservice = None, onoff = None, onmanual = None, onutilitychange = None, start = True, console = None): super(GenNotify, self).__init__() self.AccessLock = threading.Lock() self.Threads = {} self.LastEvent = None self.LastOutageStatus = None self.Events = {} # Dict for handling events self.log = log self.console = console try: # init event callbacks if onready != None: self.Events["READY"] = onready if onexercise != None: self.Events["EXERCISING"] = onexercise if onrun != None: self.Events["RUNNING"] = onrun if onrunmanual != None: self.Events["RUNNING-MANUAL"] = onrunmanual if onalarm != None: self.Events["ALARM"] = onalarm if onservice != None: self.Events["SERVICEDUE"] = onservice if onoff != None: self.Events["OFF"] = onoff if onmanual != None: self.Events["MANUAL"] = onmanual if onutilitychange != None: self.Events["OUTAGE"] = onutilitychange self.Generator = ClientInterface(host = host, port = port, log = log, loglocation = loglocation) self.Threads["PollingThread"] = MyThread(self.MainPollingThread, Name = "PollingThread", start = start) self.Started = start except Exception as e1: self.LogErrorLine("Error in mynotify init: " + str(e1))
def __init__(self, host=ProgramDefaults.LocalHost, port=ProgramDefaults.ServerPort, log=None, callback=None, polltime=None, blacklist=None, flush_interval=float('inf'), use_numeric=False, debug=False, loglocation=ProgramDefaults.LogPath, console=None): super(MyGenPush, self).__init__() self.Callback = callback self.UseNumeric = use_numeric self.debug = debug self.Exiting = False 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 = SetupLogger("client", os.path.join(loglocation, "mygenpush.log")) self.console = console self.AccessLock = threading.Lock() self.BlackList = blacklist self.LastValues = {} self.FlushInterval = flush_interval self.LastChange = {} try: self.Generator = ClientInterface(host=host, port=port, log=log) self.GetGeneratorStartInfo() # start thread to accept incoming sockets for nagios heartbeat self.Threads["MainPollingThread"] = MyThread( self.MainPollingThread, Name="MainPollingThread", start=False) self.Threads["MainPollingThread"].Start() except Exception as e1: self.LogErrorLine("Error in mygenpush init: " + str(e1))
except Exception as e1: console.error("Error : " + str(e1)) sys.exit(1) try: port, loglocation = MySupport.GetGenmonInitInfo(ConfigFilePath, log=console) log = SetupLogger("client", loglocation + "gengpio.log") except Exception as e1: console.error("Error : " + str(e1)) sys.exit(1) try: # Set the signal handler signal.signal(signal.SIGINT, signal_handler) MyClientInterface = ClientInterface(host=address, port=port, log=log) #setup GPIO using Board numbering GPIO.setmode(GPIO.BOARD) console.info(GPIO.RPI_INFO) GPIO.setwarnings(False) # These are the GPIP pins numbers on the Raspberry PI GPIO header # https://www.element14.com/community/servlet/JiveServlet/previewBody/73950-102-10-339300/pi3_gpio.png STATUS_READY = 16 # READY GPIO 23 (pin 16) STATUS_ALARM = 18 # ALARM GPIO 24 (pin 18) STATUS_SERVICE = 22 # SERVICE DUE GPIO 25 (pin 22) STATUS_RUNNING = 26 # RUNNING GPIO 7 (pin 26)
def __init__(self, log=None, loglocation=ProgramDefaults.LogPath, ConfigFilePath=MyCommon.DefaultConfPath, host=ProgramDefaults.LocalHost, port=ProgramDefaults.ServerPort, console=None): super(GenTankData, self).__init__() self.LogFileName = os.path.join(loglocation, "gentankdiy.log") self.AccessLock = threading.Lock() self.log = log self.console = console self.MonitorAddress = host configfile = os.path.join(ConfigFilePath, 'gentankdiy.conf') try: if not os.path.isfile(configfile): self.LogConsole("Missing config file : " + configfile) self.LogError("Missing config file : " + configfile) sys.exit(1) self.config = MyConfig(filename=configfile, section='gentankdiy', log=self.log) self.gauge_type = self.config.ReadValue('gauge_type', return_type=int, default=1) if self.MonitorAddress == None or not len(self.MonitorAddress): self.MonitorAddress = ProgramDefaults.LocalHost except Exception as e1: self.LogErrorLine("Error reading " + configfile + ": " + str(e1)) self.LogConsole("Error reading " + configfile + ": " + str(e1)) sys.exit(1) try: if self.gauge_type == 1: self.gauge = GaugeDIY1(self.config, log=self.log, console=self.console) elif self.gauge_type == 2: self.gauge = GaugeDIY2(self.config, log=self.log, console=self.console) else: self.LogError("Invalid guage type: " + str(self.gauge_type)) sys.exit(1) self.debug = self.gauge.debug self.Generator = ClientInterface(host=self.MonitorAddress, port=port, log=self.log) # start thread monitor time for exercise self.Threads["TankCheckThread"] = MyThread(self.TankCheckThread, Name="TankCheckThread", start=False) if not self.gauge.InitADC(): self.LogError("InitADC failed, exiting") sys.exit(1) self.Threads["TankCheckThread"].Start() signal.signal(signal.SIGTERM, self.SignalClose) signal.signal(signal.SIGINT, self.SignalClose) except Exception as e1: self.LogErrorLine("Error in GenTankData init: " + str(e1)) self.console.error("Error in GenTankData init: " + str(e1)) sys.exit(1)
def __init__(self, log = None, loglocation = ProgramDefaults.LogPath, ConfigFilePath = MyCommon.DefaultConfPath, host = ProgramDefaults.LocalHost, port = ProgramDefaults.ServerPort, console = None): super(GenTankData, self).__init__() self.LogFileName = os.path.join(loglocation, "gentankutil.log") self.AccessLock = threading.Lock() self.log = log self.console = console self.MonitorAddress = host self.PollTime = 2 self.TankID = "" self.debug = False configfile = os.path.join(ConfigFilePath, 'gentankutil.conf') try: if not os.path.isfile(configfile): self.LogConsole("Missing config file : " + configfile) self.LogError("Missing config file : " + configfile) sys.exit(1) self.config = MyConfig(filename = configfile, section = 'gentankutil', log = self.log) self.PollTime = self.config.ReadValue('poll_frequency', return_type = float, default = 60) self.debug = self.config.ReadValue('debug', return_type = bool, default = False) self.username = self.config.ReadValue('username', default = "") self.password = self.config.ReadValue('password', default = "") self.tank_name = self.config.ReadValue('tank_name', default = "") if self.MonitorAddress == None or not len(self.MonitorAddress): self.MonitorAddress = ProgramDefaults.LocalHost except Exception as e1: self.LogErrorLine("Error reading " + configfile + ": " + str(e1)) self.LogConsole("Error reading " + configfile + ": " + str(e1)) sys.exit(1) if self.username == "" or self.username == None or self.password == "" or self.password == None: self.LogError("Invalid user name or password, exiting") sys.exit(1) try: self.Generator = ClientInterface(host = self.MonitorAddress, port = port, log = self.log) #if not self.CheckGeneratorRequirement(): # self.LogError("Requirements not met. Exiting.") # sys.exit(1) self.tank = tankutility(self.username, self.password, self.log, debug = self.debug) # start thread monitor time for exercise self.Threads["TankCheckThread"] = MyThread(self.TankCheckThread, Name = "TankCheckThread", start = False) self.Threads["TankCheckThread"].Start() signal.signal(signal.SIGTERM, self.SignalClose) signal.signal(signal.SIGINT, self.SignalClose) except Exception as e1: self.LogErrorLine("Error in GenTankData init: " + str(e1)) self.console.error("Error in GenTankData init: " + str(e1)) sys.exit(1)
def __init__(self, host="127.0.0.1", port=9082, log=None, onready=None, onexercise=None, onrun=None, onrunmanual=None, onalarm=None, onservice=None, onoff=None, onmanual=None, onutilitychange=None): super(GenNotify, self).__init__() self.AccessLock = threading.Lock() self.Threads = {} self.LastEvent = None self.LastOutageStatus = None self.Events = {} # Dict for handling events if log != None: self.log = log else: # log errors in this module to a file self.log = SetupLogger("client", "/var/log/myclient.log") self.console = SetupLogger("notify_console", log_file="", stream=True) try: # init event callbacks if onready != None: self.Events["READY"] = onready if onexercise != None: self.Events["EXERCISING"] = onexercise if onrun != None: self.Events["RUNNING"] = onrun if onrunmanual != None: self.Events["RUNNING-MANUAL"] = onrunmanual if onalarm != None: self.Events["ALARM"] = onalarm if onservice != None: self.Events["SERVICEDUE"] = onservice if onoff != None: self.Events["OFF"] = onoff if onmanual != None: self.Events["MANUAL"] = onmanual if onutilitychange != None: self.Events["OUTAGE"] = onutilitychange startcount = 0 while startcount <= 10: try: self.Generator = ClientInterface(host=host, log=log) break except Exception as e1: startcount += 1 if startcount >= 10: self.console.info("genmon not loaded.") sys.exit(1) time.sleep(1) continue # start thread to accept incoming sockets for nagios heartbeat self.Threads["PollingThread"] = MyThread(self.MainPollingThread, Name="PollingThread") except Exception as e1: self.LogErrorLine("Error in mynotify init: " + str(e1))
def __init__(self, log=None, loglocation=ProgramDefaults.LogPath, ConfigFilePath=MyCommon.DefaultConfPath, host=ProgramDefaults.LocalHost, port=ProgramDefaults.ServerPort, console=None): super(GenCTHat, self).__init__() #https://tutorials-raspberrypi.com/mcp3008-read-out-analog-signals-on-the-raspberry-pi/ #https://forums.raspberrypi.com/viewtopic.php?t=237182 self.LogFileName = os.path.join(loglocation, "gencthat.log") self.AccessLock = threading.Lock() self.log = log self.console = console self.MonitorAddress = host self.PollTime = 2 self.SampleTimeMS = 34 self.debug = False self.ConfigFileName = 'gencthat.conf' configfile = os.path.join(ConfigFilePath, self.ConfigFileName) try: if not os.path.isfile(configfile): self.LogConsole("Missing config file : " + configfile) self.LogError("Missing config file : " + configfile) sys.exit(1) self.config = MyConfig(filename=configfile, section='gencthat', log=self.log) self.Multiplier = self.config.ReadValue('multiplier', return_type=float, default=0.488) # this checks to see if an old version of the conf file is in use and replaces it if self.Multiplier == 0.218: self.ConfPath = os.path.join( os.path.dirname(os.path.realpath(__file__)), "conf") if os.path.isfile( os.path.join(self.ConfPath, self.ConfigFileName)): copyfile(os.path.join(self.ConfPath, self.ConfigFileName), configfile) self.LogError( "Copied " + os.path.join(self.ConfPath, self.ConfigFileName) + " to " + configfile) self.config = MyConfig(filename=configfile, section='gencthat', log=self.log) else: self.LogError( "Error: unable to find config file: " + os.path.join(self.ConfPath, self.ConfigFileName)) self.SampleTimeMS = self.config.ReadValue('sample_time_ms', return_type=int, default=34) self.Multiplier = self.config.ReadValue('multiplier', return_type=float, default=0.488) self.PollTime = self.config.ReadValue('poll_frequency', return_type=float, default=60) self.powerfactor = self.config.ReadValue('powerfactor', return_type=float, default=1.0) self.bus = self.config.ReadValue('bus', return_type=int, default=1) self.device = self.config.ReadValue('device', return_type=int, default=0) self.strict = self.config.ReadValue('strict', return_type=bool, default=False) self.singlelegthreshold = self.config.ReadValue( 'singlelegthreshold', return_type=float, default=0.6) self.debug = self.config.ReadValue('debug', return_type=bool, default=False) self.LogDebug("Multiplier: " + str(self.Multiplier)) if self.MonitorAddress == None or not len(self.MonitorAddress): self.MonitorAddress = ProgramDefaults.LocalHost except Exception as e1: self.LogErrorLine("Error reading " + configfile + ": " + str(e1)) self.LogConsole("Error reading " + configfile + ": " + str(e1)) sys.exit(1) try: self.adc = MCP3008(bus=self.bus, device=self.device, log=self.log) self.adc.open() self.Generator = ClientInterface(host=self.MonitorAddress, port=port, log=self.log) #if not self.CheckGeneratorRequirement(): # self.LogError("Requirements not met. Exiting.") # sys.exit(1) # start thread monitor time for exercise self.Threads["SensorCheckThread"] = MyThread( self.SensorCheckThread, Name="SensorCheckThread", start=False) self.Threads["SensorCheckThread"].Start() signal.signal(signal.SIGTERM, self.SignalClose) signal.signal(signal.SIGINT, self.SignalClose) except Exception as e1: self.LogErrorLine("Error in GenCTHat init: " + str(e1)) self.console.error("Error in GenCTHat init: " + str(e1)) sys.exit(1)
"generator: setremote=starttransfer") except Exception as e1: log.error("Error: " + str(e1)) #------------------- Command-line interface for gengpioin ---------------------- if __name__ == '__main__': # usage program.py [server_address] address = '127.0.0.1' if len(sys.argv) < 2 else sys.argv[1] try: console = SetupLogger("gengpioin_console", log_file="", stream=True) log = SetupLogger("client", "/var/log/gengpioin.log") # Set the signal handler signal.signal(signal.SIGINT, signal_handler) MyClientInterface = ClientInterface(host=address, log=log) #setup GPIO using Board numbering GPIO.setmode(GPIO.BOARD) console.info(GPIO.RPI_INFO) GPIO.setwarnings(True) GPIO.setup( INPUT_STOP, GPIO.IN, pull_up_down=GPIO.PUD_UP) # input, set internal pull up resistor# GPIO.add_event_detect(INPUT_STOP, GPIO.FALLING) # detect falling edge GPIO.add_event_callback(INPUT_STOP, callback=StopCallBack) #, bouncetime=1000)
def __init__(self, log=None, loglocation=ProgramDefaults.LogPath, ConfigFilePath=MyCommon.DefaultConfPath, host=ProgramDefaults.LocalHost, port=ProgramDefaults.ServerPort): super(GenTankData, self).__init__() self.LogFileName = loglocation + "gentankutil.log" self.AccessLock = threading.Lock() # log errors in this module to a file self.log = SetupLogger("gentankutil", self.LogFileName) self.console = SetupLogger("gentankutil_console", log_file="", stream=True) self.MonitorAddress = host self.PollTime = 2 self.TankID = "" self.debug = False configfile = ConfigFilePath + 'gentankutil.conf' try: if not os.path.isfile(configfile): self.LogConsole("Missing config file : " + configfile) self.LogError("Missing config file : " + configfile) sys.exit(1) self.config = MyConfig(filename=configfile, section='gentankutil', log=self.log) self.PollTime = self.config.ReadValue('poll_frequency', return_type=float, default=60) self.debug = self.config.ReadValue('debug', return_type=bool, default=False) self.username = self.config.ReadValue('username', default="") self.password = self.config.ReadValue('password', default="") self.tank_name = self.config.ReadValue('tank_name', default="") if self.MonitorAddress == None or not len(self.MonitorAddress): self.MonitorAddress = ProgramDefaults.LocalHost except Exception as e1: self.LogErrorLine("Error reading " + configfile + ": " + str(e1)) self.LogConsole("Error reading " + configfile + ": " + str(e1)) sys.exit(1) if self.username == "" or self.username == None or self.password == "" or self.password == None: self.LogError("Invalid user name or password, exiting") sys.exit(1) try: try: startcount = 0 while startcount <= 10: try: self.Generator = ClientInterface( host=self.MonitorAddress, port=port, log=self.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 except Exception as e1: self.LogErrorLine("Error in GenTankData init: " + str(e1)) #if not self.CheckGeneratorRequirement(): # self.LogError("Requirements not met. Exiting.") # sys.exit(1) self.tank = tankutility(self.username, self.password, self.log, debug=self.debug) # start thread monitor time for exercise self.Threads["TankCheckThread"] = MyThread(self.TankCheckThread, Name="TankCheckThread", start=False) self.Threads["TankCheckThread"].Start() atexit.register(self.Close) signal.signal(signal.SIGTERM, self.Close) signal.signal(signal.SIGINT, self.Close) except Exception as e1: self.LogErrorLine("Error in GenTankData init: " + str(e1)) self.console.error("Error in GenTankData init: " + str(e1)) sys.exit(1)
def __init__(self, log=None, loglocation=ProgramDefaults.LogPath, ConfigFilePath=MyCommon.DefaultConfPath, host=ProgramDefaults.LocalHost, port=ProgramDefaults.ServerPort, console=None): super(GenExercise, self).__init__() self.AccessLock = threading.Lock() self.log = log self.console = console self.MonitorAddress = host self.PollTime = 2 self.ExerciseActive = False self.Debug = False try: self.config = MyConfig(filename=os.path.join( ConfigFilePath, 'genexercise.conf'), section='genexercise', log=self.log) self.ExerciseType = self.config.ReadValue('exercise_type', default="Normal") self.ExerciseHour = self.config.ReadValue('exercise_hour', return_type=int, default=12) self.ExerciseMinute = self.config.ReadValue('exercise_minute', return_type=int, default=0) self.ExerciseDayOfMonth = self.config.ReadValue( 'exercise_day_of_month', return_type=int, default=1) self.ExerciseDayOfWeek = self.config.ReadValue( 'exercise_day_of_week', default="Monday") self.ExerciseDuration = self.config.ReadValue('exercise_duration', return_type=float, default=12) self.ExerciseWarmup = self.config.ReadValue('exercise_warmup', return_type=float, default=0) self.ExerciseFrequency = self.config.ReadValue( 'exercise_frequency', default="Monthly") self.MonitorAddress = self.config.ReadValue( 'monitor_address', default=ProgramDefaults.LocalHost) self.LastExerciseTime = self.config.ReadValue('last_exercise', default=None) self.UseGeneratorTime = self.config.ReadValue('use_gen_time', return_type=bool, default=False) self.Debug = self.config.ReadValue('debug', return_type=bool, default=False) # Validate settings if not self.ExerciseType.lower() in [ "normal", "quiet", "transfer" ]: self.ExerciseType = "normal" if self.ExerciseHour > 23 or self.ExerciseHour < 0: self.ExerciseHour = 12 if self.ExerciseMinute > 59 or self.ExerciseMinute < 0: self.ExerciseMinute = 0 if not self.ExerciseDayOfWeek.lower() in [ "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" ]: self.ExerciseDayOfWeek = "Monday" if self.ExerciseDayOfMonth > 28 or self.ExerciseDayOfMonth < 1: self.ExerciseDayOfMonth = 1 if self.ExerciseDuration > 60: self.ExerciseDuration = 60 if self.ExerciseDuration < 5: self.ExerciseDuration = 5 if self.ExerciseWarmup > 30: self.ExerciseWarmup = 30 if self.ExerciseWarmup < 0: self.ExerciseWarmup = 0 if not self.ExerciseFrequency.lower() in [ "weekly", "biweekly", "monthly" ]: self.ExerciseFrequency = "Monthly" if self.MonitorAddress == None or not len(self.MonitorAddress): self.MonitorAddress = ProgramDefaults.LocalHost except Exception as e1: self.LogErrorLine( "Error reading " + os.path.join(ConfigFilePath, "genexercise.conf") + ": " + str(e1)) self.console.error( "Error reading " + os.path.join(ConfigFilePath, "genexercise.conf") + ": " + str(e1)) sys.exit(1) try: self.Generator = ClientInterface(host=self.MonitorAddress, port=port, log=self.log) if not self.CheckGeneratorRequirement(): self.LogError("Requirements not met. Exiting.") sys.exit(1) # start thread monitor time for exercise self.Threads["ExerciseThread"] = MyThread(self.ExerciseThread, Name="ExerciseThread", start=False) self.Threads["ExerciseThread"].Start() try: if self.ExerciseFrequency.lower() == "monthly": DayStr = "Day " + str(self.ExerciseDayOfMonth) else: DayStr = str(self.ExerciseDayOfWeek) self.LogError("Execise: " + self.ExerciseType + ", " + self.ExerciseFrequency + " at " + str(self.ExerciseHour) + ":" + str(self.ExerciseMinute) + " on " + DayStr + " for " + str(self.ExerciseDuration) + " min. Warmup: " + str(self.ExerciseWarmup)) self.DebugOutput("Debug Enabled") except Exception as e1: self.LogErrorLine(str(e1)) signal.signal(signal.SIGTERM, self.SignalClose) signal.signal(signal.SIGINT, self.SignalClose) except Exception as e1: self.LogErrorLine("Error in GenExercise init: " + str(e1)) self.console.error("Error in GenExercise init: " + str(e1)) sys.exit(1)
def __init__(self, log=None, loglocation=ProgramDefaults.LogPath, ConfigFilePath=MyCommon.DefaultConfPath, host=ProgramDefaults.LocalHost, port=ProgramDefaults.ServerPort): super(GenTemp, self).__init__() self.LogFileName = os.path.join(loglocation, "gentemp.log") self.AccessLock = threading.Lock() # log errors in this module to a file self.log = SetupLogger("gentemp", self.LogFileName) self.console = SetupLogger("gentemp_console", log_file="", stream=True) self.LastValues = {} self.MonitorAddress = host self.debug = False self.PollTime = 1 self.BlackList = None configfile = os.path.join(ConfigFilePath, 'gentemp.conf') try: if not os.path.isfile(configfile): self.LogConsole("Missing config file : " + configfile) self.LogError("Missing config file : " + configfile) sys.exit(1) self.config = MyConfig(filename=configfile, section='gentemp', log=self.log) self.UseMetric = self.config.ReadValue('use_metric', return_type=bool, default=False) self.PollTime = self.config.ReadValue('poll_frequency', return_type=float, default=1) self.debug = self.config.ReadValue('debug', return_type=bool, default=False) self.DeviceLabels = self.GetParamList( self.config.ReadValue('device_labels', default=None)) self.BlackList = self.GetParamList( self.config.ReadValue('blacklist', default=None)) if self.MonitorAddress == None or not len(self.MonitorAddress): self.MonitorAddress = ProgramDefaults.LocalHost except Exception as e1: self.LogErrorLine("Error reading " + configfile + ": " + str(e1)) self.LogConsole("Error reading " + configfile + ": " + str(e1)) sys.exit(1) try: try: startcount = 0 while startcount <= 10: try: self.Generator = ClientInterface( host=self.MonitorAddress, port=port, log=self.log) break except Exception as e1: startcount += 1 if startcount >= 10: self.LogConsole("genmon not loaded.") self.LogError("Unable to connect to genmon.") sys.exit(1) time.sleep(1) continue except Exception as e1: self.LogErrorLine("Error in GenTempThread init: " + str(e1)) self.DeviceList = self.EnumDevices() if not len(self.DeviceList): self.LogConsole("No sensors found.") self.LogError("No sensors found.") sys.exit(1) # start thread monitor time for exercise self.Threads["GenTempThread"] = MyThread(self.GenTempThread, Name="GenTempThread", start=False) self.Threads["GenTempThread"].Start() atexit.register(self.Close) except Exception as e1: self.LogErrorLine("Error in GenTemp init: " + str(e1)) self.LogConsole("Error in GenTemp init: " + str(e1)) sys.exit(1)
def __init__(self, log=None, loglocation=ProgramDefaults.LogPath, ConfigFilePath=MyCommon.DefaultConfPath, host=ProgramDefaults.LocalHost, port=ProgramDefaults.ServerPort): super(GenTankData, self).__init__() self.LogFileName = os.path.join(loglocation, "gentankdiy.log") self.AccessLock = threading.Lock() # log errors in this module to a file self.log = SetupLogger("gentankdiy", self.LogFileName) self.console = SetupLogger("gentankdiy_console", log_file="", stream=True) self.MonitorAddress = host self.PollTime = 2 self.debug = False configfile = os.path.join(ConfigFilePath, 'gentankdiy.conf') try: if not os.path.isfile(configfile): self.LogConsole("Missing config file : " + configfile) self.LogError("Missing config file : " + configfile) sys.exit(1) self.config = MyConfig(filename=configfile, section='gentankdiy', log=self.log) self.PollTime = self.config.ReadValue('poll_frequency', return_type=float, default=60) self.debug = self.config.ReadValue('debug', return_type=bool, default=False) self.i2c_address = self.config.ReadValue('i2c_address', return_type=int, default=72) self.mv_per_step = self.config.ReadValue('mv_per_step', return_type=int, default=125) self.Multiplier = self.config.ReadValue( 'volts_to_percent_multiplier', return_type=float, default=20.0) # I2C channel 1 is connected to the GPIO pins self.i2c_channel = self.config.ReadValue('i2c_channel', return_type=int, default=1) if self.MonitorAddress == None or not len(self.MonitorAddress): self.MonitorAddress = ProgramDefaults.LocalHost except Exception as e1: self.LogErrorLine("Error reading " + configfile + ": " + str(e1)) self.LogConsole("Error reading " + configfile + ": " + str(e1)) sys.exit(1) try: try: startcount = 0 while startcount <= 10: try: self.Generator = ClientInterface( host=self.MonitorAddress, port=port, log=self.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 except Exception as e1: self.LogErrorLine("Error in GenTankData init: " + str(e1)) # start thread monitor time for exercise self.Threads["TankCheckThread"] = MyThread(self.TankCheckThread, Name="TankCheckThread", start=False) if not self.InitADC(): self.LogError("InitADC failed, exiting") sys.exit(1) self.Threads["TankCheckThread"].Start() atexit.register(self.Close) signal.signal(signal.SIGTERM, self.Close) signal.signal(signal.SIGINT, self.Close) except Exception as e1: self.LogErrorLine("Error in GenTankData init: " + str(e1)) self.console.error("Error in GenTankData init: " + str(e1)) sys.exit(1)
def __init__(self, host=ProgramDefaults.LocalHost, port=ProgramDefaults.ServerPort, log=None, loglocation=ProgramDefaults.LogPath, onready=None, onexercise=None, onrun=None, onrunmanual=None, onalarm=None, onservice=None, onoff=None, onmanual=None, onutilitychange=None, onsoftwareupdate=None, onsystemhealth=None, onfuelstate=None, start=True, console=None, notify_outage=True, notify_error=True, notify_warning=True, notify_info=True, notify_sw_update=True, config=None): super(GenNotify, self).__init__() self.AccessLock = threading.Lock() self.Threads = {} self.LastEvent = None self.LastOutageStatus = None self.LastSoftwareUpdateStatus = None self.LastSystemHealth = None self.LastFuelWarningStatus = True self.Events = {} # Dict for handling events self.notify_outage = notify_outage self.notify_error = notify_error self.notify_warning = notify_warning self.notify_info = notify_info self.notify_sw_update = notify_sw_update self.config = config self.log = log self.console = console try: # get settings from config file if supplied if self.config != None: self.notify_outage = self.config.ReadValue('notify_outage', return_type=bool, default=True) self.notify_error = self.config.ReadValue('notify_error', return_type=bool, default=True) self.notify_warning = self.config.ReadValue('notify_warning', return_type=bool, default=True) self.notify_info = self.config.ReadValue('notify_info', return_type=bool, default=True) self.notify_sw_update = self.config.ReadValue( 'notify_sw_update', return_type=bool, default=True) # init event callbacks if onready != None and self.notify_info: self.Events["READY"] = onready if onexercise != None and self.notify_info: self.Events["EXERCISING"] = onexercise if onrun != None and self.notify_info: self.Events["RUNNING"] = onrun if onrunmanual != None and self.notify_info: self.Events["RUNNING-MANUAL"] = onrunmanual if onalarm != None and self.notify_error: self.Events["ALARM"] = onalarm if onservice != None and self.notify_warning: self.Events["SERVICEDUE"] = onservice if onoff != None and self.notify_info: self.Events["OFF"] = onoff if onmanual != None and self.notify_info: self.Events["MANUAL"] = onmanual if onutilitychange != None and self.notify_outage: self.Events["OUTAGE"] = onutilitychange if onsoftwareupdate != None and self.notify_sw_update: self.Events["SOFTWAREUPDATE"] = onsoftwareupdate if onsystemhealth != None: self.Events["SYSTEMHEALTH"] = onsystemhealth if onfuelstate != None and self.notify_warning: self.Events["FUELWARNING"] = onfuelstate self.Generator = ClientInterface(host=host, port=port, log=log, loglocation=loglocation) self.Threads["PollingThread"] = MyThread(self.MainPollingThread, Name="PollingThread", start=start) self.Started = start except Exception as e1: self.LogErrorLine("Error in mynotify init: " + str(e1))
def __init__(self, host=ProgramDefaults.LocalHost, port=ProgramDefaults.ServerPort, log=None, loglocation=ProgramDefaults.LogPath, onready=None, onexercise=None, onrun=None, onrunmanual=None, onalarm=None, onservice=None, onoff=None, onmanual=None, onutilitychange=None, start=True): super(GenNotify, self).__init__() self.AccessLock = threading.Lock() self.Threads = {} self.LastEvent = None self.LastOutageStatus = None self.Events = {} # Dict for handling events if log != None: self.log = log else: # log errors in this module to a file self.log = SetupLogger("client", os.path.join(loglocation, "myclient.log")) self.console = SetupLogger("notify_console", log_file="", stream=True) try: # init event callbacks if onready != None: self.Events["READY"] = onready if onexercise != None: self.Events["EXERCISING"] = onexercise if onrun != None: self.Events["RUNNING"] = onrun if onrunmanual != None: self.Events["RUNNING-MANUAL"] = onrunmanual if onalarm != None: self.Events["ALARM"] = onalarm if onservice != None: self.Events["SERVICEDUE"] = onservice if onoff != None: self.Events["OFF"] = onoff if onmanual != None: self.Events["MANUAL"] = onmanual if onutilitychange != None: self.Events["OUTAGE"] = onutilitychange startcount = 0 while startcount <= 10: try: self.Generator = ClientInterface(host=host, port=port, log=log, loglocation=loglocation) break except Exception as e1: startcount += 1 if startcount >= 10: self.console.info("genmon not loaded.") sys.exit(1) time.sleep(1) continue self.Threads["PollingThread"] = MyThread(self.MainPollingThread, Name="PollingThread", start=start) self.Started = start except Exception as e1: self.LogErrorLine("Error in mynotify init: " + str(e1))
def __init__(self): super(GenExercise, self).__init__() self.LogFileName = "/var/log/genexercise.log" self.AccessLock = threading.Lock() # log errors in this module to a file self.log = SetupLogger("genexercise", self.LogFileName) self.console = SetupLogger("genexercise_console", log_file = "", stream = True) self.MonitorAddress = "127.0.0.1" self.PollTime = 2 self.ExerciseActive = False self.Debug = False try: self.config = MyConfig(filename = '/etc/genexercise.conf', section = 'genexercise', log = self.log) self.ExerciseType = self.config.ReadValue('exercise_type', default = "Normal") self.ExerciseHour = self.config.ReadValue('exercise_hour', return_type = int, default = 12) self.ExerciseMinute = self.config.ReadValue('exercise_minute', return_type = int, default = 0) self.ExerciseDayOfMonth = self.config.ReadValue('exercise_day_of_month', return_type = int, default = 1) self.ExerciseDayOfWeek = self.config.ReadValue('exercise_day_of_week', default = "Monday") self.ExerciseDuration = self.config.ReadValue('exercise_duration', return_type = float, default = 12) self.ExerciseWarmup = self.config.ReadValue('exercise_warmup', return_type = float, default = 0) self.ExerciseFrequency = self.config.ReadValue('exercise_frequency', default = "Monthly") self.MonitorAddress = self.config.ReadValue('monitor_address', default = "127.0.0.1") self.LastExerciseTime = self.config.ReadValue('last_exercise', default = None) self.UseGeneratorTime = self.config.ReadValue('use_gen_time', return_type = bool, default = False) self.Debug = self.config.ReadValue('debug', return_type = bool, default = False) # Validate settings if not self.ExerciseType.lower() in ["normal","quiet", "transfer"]: self.ExerciseType = "normal" if self.ExerciseHour > 23 or self.ExerciseHour < 0: self.ExerciseHour = 12 if self.ExerciseMinute > 59 or self.ExerciseMinute < 0: self.ExerciseMinute = 0 if not self.ExerciseDayOfWeek.lower() in ["monday", "tuesday", "wednesday","thursday","friday","saturday","sunday"]: self.ExerciseDayOfWeek = "Monday" if self.ExerciseDayOfMonth > 28 or self.ExerciseDayOfMonth < 1: self.ExerciseDayOfMonth = 1 if self.ExerciseDuration > 60: self.ExerciseDuration = 60 if self.ExerciseDuration < 5: self.ExerciseDuration = 5 if self.ExerciseWarmup > 30: self.ExerciseWarmup = 30 if self.ExerciseWarmup < 0: self.ExerciseWarmup = 0 if not self.ExerciseFrequency.lower() in ["weekly","biweekly", "monthly"]: self.ExerciseFrequency = "Monthly" if self.MonitorAddress == None or not len(self.MonitorAddress): self.MonitorAddress = "127.0.0.1" except Exception as e1: self.LogErrorLine("Error reading /etc/genexercise.conf: " + str(e1)) self.console.error("Error reading /etc/genexercise.conf: " + str(e1)) sys.exit(1) try: try: startcount = 0 while startcount <= 10: try: self.Generator = ClientInterface(host = self.MonitorAddress, log = self.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 except Exception as e1: self.LogErrorLine("Error in mygenpush init: " + str(e1)) if not self.CheckGeneratorRequirement(): self.LogError("Requirements not met. Exiting.") sys.exit(1) # start thread monitor time for exercise self.Threads["ExerciseThread"] = MyThread(self.ExerciseThread, Name = "ExerciseThread", start = False) self.Threads["ExerciseThread"].Start() try: if self.ExerciseFrequency.lower() == "monthly": DayStr = "Day " + str(self.ExerciseDayOfMonth) else: DayStr = str(self.ExerciseDayOfWeek) self.LogError("Execise: " + self.ExerciseType + ", " + self.ExerciseFrequency + " at " + str(self.ExerciseHour) + ":" + str(self.ExerciseMinute) + " on " + DayStr + " for " + str(self.ExerciseDuration) + " min. Warmup: " + str(self.ExerciseWarmup)) if self.Debug: self.LogError("Debug Enabled") except Exception as e1: self.LogErrorLine(str(e1)) atexit.register(self.Close) signal.signal(signal.SIGTERM, self.Close) signal.signal(signal.SIGINT, self.Close) except Exception as e1: self.LogErrorLine("Error in GenExercise init: " + str(e1)) self.console.error("Error in GenExercise init: " + str(e1)) sys.exit(1)