def OneTimeMaint(ConfigFilePath, log): FileList = { "feedback.json" : os.path.dirname(os.path.realpath(__file__)) + "/", "outage.txt" : os.path.dirname(os.path.realpath(__file__)) + "/", "kwlog.txt" : os.path.dirname(os.path.realpath(__file__)) + "/", "maintlog.json" : os.path.dirname(os.path.realpath(__file__)) + "/", "Feedback_dat" : os.path.dirname(os.path.realpath(__file__)) + "/genmonlib/", "Message_dat" : os.path.dirname(os.path.realpath(__file__)) + "/genmonlib/", 'genmon.conf' : "/etc/", 'genserv.conf': "/etc/", 'gengpio.conf' : "/etc/", 'gengpioin.conf': "/etc/", 'genlog.conf' : "/etc/", 'gensms.conf' : "/etc/", 'gensms_modem.conf': "/etc/", 'genpushover.conf': "/etc/", 'gensyslog.conf' : "/etc/", 'genmqtt.conf' : "/etc/", 'genslack.conf': "/etc/", 'genexercise.conf' : "/etc/", 'genemail2sms.conf' : "/etc/", 'genloader.conf' : "/etc/", 'mymail.conf' : "/etc/", 'mymodem.conf' : "/etc/" } try: # Check to see if we have done this already by checking files in the genmon source directory if (not os.path.isfile(os.path.dirname(os.path.realpath(__file__)) + "/genmonlib/Message_dat") and not os.path.isfile(os.path.dirname(os.path.realpath(__file__)) + "/maintlog.json") and not os.path.isfile(os.path.dirname(os.path.realpath(__file__)) + "/outage.txt") and not os.path.isfile(os.path.dirname(os.path.realpath(__file__)) + "/kwlog.txt") and not os.path.isfile("/etc/genmon.conf")): return False # validate target directory if not os.path.isdir(ConfigFilePath): try: os.mkdir(ConfigFilePath) if not os.access(ConfigFilePath + File, os.R_OK): pass except Exception as e1: log.error("Error validating target directory: " + str(e1), LogLine = True) # move files for File, Path in FileList.items(): try: SourceFile = Path + File if os.path.isfile(SourceFile): log.error("Moving " + SourceFile + " to " + ConfigFilePath ) if not MySupport.CopyFile(SourceFile, ConfigFilePath + File, move = True, log = log): log.error("Error: using alternate move method") move(SourceFile , ConfigFilePath + File) if not os.access(ConfigFilePath + File, os.R_OK): pass except Exception as e1: log.error("Error moving " + SourceFile) except Exception as e1: log.error("Error moving files: " + str(e1), LogLine = True) return True
def StartModules(self): self.LogConsole("Starting....") if not len(self.LoadOrder): self.LogInfo("Error, nothing to start.") return False ErrorOccured = False for Module in reversed(self.LoadOrder): try: if self.CachedConfig[Module]["enable"]: if not multi_instance: # check that module is not loaded already, if it is then force it (hard) to unload attempts = 0 while True: if MySupport.IsRunning( prog_name=self.CachedConfig[Module] ["module"], log=self.log, multi_instance=multi_instance): # if loaded then kill it if attempts >= 4: # kill it if not self.UnloadModule( self.ModulePath, self.CachedConfig[Module] ["module"], pid=None, HardStop=True, UsePID=False): self.LogInfo("Error killing " + self.CachedConfig[Module] ["module"]) else: attempts += 1 time.sleep(1) else: break if not self.LoadModule( self.ModulePath, self.CachedConfig[Module]["module"], args=self.CachedConfig[Module]["args"]): self.LogInfo("Error starting " + Module) ErrorOccured = True if not self.CachedConfig[Module][ "postloaddelay"] == None and self.CachedConfig[ Module]["postloaddelay"] > 0: time.sleep(self.CachedConfig[Module]["postloaddelay"]) except Exception as e1: self.LogInfo("Error starting module " + Module + " : " + str(e1), LogLine=True) return False return not ErrorOccured
try: syslog.openlog("genmon") syslog.syslog("%s" % Message) syslog.closelog() except Exception as e1: log.error("Error: " + str(e1)) console.error("Error: " + str(e1)) #------------------- Command-line interface for gengpio ------------------------ if __name__ == '__main__': # console, ConfigFilePath, address, port, loglocation, log = MySupport.SetupAddOnProgram( "gensyslog") # Set the signal handler signal.signal(signal.SIGINT, signal_handler) try: GenNotify = GenNotify(host=address, port=port, onready=OnReady, onexercise=OnExercise, onrun=OnRun, onrunmanual=OnRunManual, onalarm=OnAlarm, onservice=OnService, onoff=OnOff,
for opt, arg in opts: if opt == '-h': console.error(HelpStr) sys.exit() elif opt in ("-a", "--address"): address = arg elif opt in ("-c", "--configpath"): ConfigFilePath = arg ConfigFilePath = ConfigFilePath.strip() 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)
time.sleep(1) GPIO.output(pin, GPIO.LOW) time.sleep(1) for i in range(nfast): GPIO.output(pin, GPIO.HIGH) time.sleep(blinkdelay) GPIO.output(pin, GPIO.LOW) time.sleep(blinkdelay) #------------------- Command-line interface for gengpioledblink ---------------- if __name__ == '__main__': # usage program.py [server_address] try: console, ConfigFilePath, address, port, loglocation, log = MySupport.SetupAddOnProgram( "gengpioledblink") # Set the signal handler signal.signal(signal.SIGINT, signal_handler) conf_file = os.path.join(ConfigFilePath, 'gengpioledblink.conf') if os.path.isfile(conf_file): config = MyConfig(filename=conf_file, section='gengpioledblink', log=log) led_pin = config.ReadValue('ledpin', return_type=int, default=12) MyClientInterface = ClientInterface(host=address, port=port, log=log) #setup GPIO using Board numbering GPIO.setmode(GPIO.BOARD)
LogFile.flush() #------------------- Command-line interface for genlog ------------------------- if __name__ == '__main__': address = ProgramDefaults.LocalHost fileName = "" HelpStr = '\npython genlog.py -a <IP Address or localhost> -f <outputfile> -c <config file path>\n' try: ConfigFilePath = ProgramDefaults.ConfPath console = SetupLogger("genlog_console", log_file="", stream=True) port, loglocation, multi_instance = MySupport.GetGenmonInitInfo( ConfigFilePath, log=console) if not MySupport.PermissionsOK(): console.error( "You need to have root privileges to run this script.\nPlease try again, this time using 'sudo'. Exiting." ) sys.exit(2) if MySupport.IsRunning(os.path.basename(__file__), multi_instance=multi_instance): console.error("The program %s is already loaded" % os.path.basename(__file__)) sys.exit(2) opts, args = getopt.getopt( sys.argv[1:], "ha:f:c:",