def setUp(self): super(WriteReadTest, self).setUp() win32evtlogutil.AddSourceToRegistry( self.applicationName, "%systemroot%\\system32\\EventCreate.exe", self.providerName) win32evtlogutil.AddSourceToRegistry( self.otherAppName, "%systemroot%\\system32\\EventCreate.exe", self.providerName)
def setUp(self): super(WriteReadTest, self).setUp() # Every test will use its own event log and application names to ensure # isolation. self.testSuffix = "_" + hashlib.sha256(self.api + self._testMethodName).hexdigest()[:5] self.providerName = PROVIDER + self.testSuffix self.applicationName = APP_NAME + self.testSuffix self.otherAppName = OTHER_APP_NAME + self.testSuffix win32evtlogutil.AddSourceToRegistry(self.applicationName, "%systemroot%\\system32\\EventCreate.exe", self.providerName) win32evtlogutil.AddSourceToRegistry(self.otherAppName, "%systemroot%\\system32\\EventCreate.exe", self.providerName)
def __init__(self, args): win32evtlogutil.AddSourceToRegistry(self._svc_display_name_, sys.executable, "Application") win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self.server = AsyncXMLRPCServer(('0.0.0.0', 11110), SimpleXMLRPCRequestHandler)
def SvcDoRun(self): win32evtlogutil.AddSourceToRegistry(self._svc_name_, servicemanager.__file__) # Write a 'started' event to the event log... win32evtlogutil.ReportEvent( self._svc_name_, servicemanager.PYS_SERVICE_STARTED, 0, # category servicemanager.EVENTLOG_INFORMATION_TYPE, (self._svc_name_, ""), ) try: return_code = self.run_connectivity_tool() if return_code != 0: # raise Exception("Authentication Proxy Configuration has an error.") # We're choosing not to prevent auth proxy startup if there are # config errors for now, but once the configuration validation # proves to be stable we can go back to preventing startup. message = ("Your configuration is not valid. Check the output " "at {conn_tool_logs} for errors.".format( conn_tool_logs=self.conn_tool_logs)) self.log_error_during_startup(message) application = duoauthproxy.proxy.create_application() app.startApplication(application, 0) reactor.run(installSignalHandlers=0) except Exception: # service did not shut down cleanly message = traceback.format_exc() win32evtlogutil.ReportEvent( self._svc_name_, servicemanager.PYS_SERVICE_STOPPED, 0, # category servicemanager.EVENTLOG_ERROR_TYPE, ( self._svc_name_, " due to a failure:\n\n%s\n" "We could not start your Authentication Proxy due to an error. Likely this is a configuration error. To view the error output check the logs located at %s \n" "After fixing the errors you can run a test of your configuration using our validator located at %s" % (message, self.conn_tool_logs, self.conn_tool_path), ), ) else: # service shut down cleanly win32evtlogutil.ReportEvent( self._svc_name_, servicemanager.PYS_SERVICE_STOPPED, 0, # category servicemanager.EVENTLOG_INFORMATION_TYPE, (self._svc_name_, ""), ) win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self): self.Start_MaayService() import servicemanager win32evtlogutil.AddSourceToRegistry(self._svc_name_, servicemanager.__file__) servicemanager.Initialize(self._svc_name_, servicemanager.__file__) servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, (self._svc_name_, ''))
def register(self, msg_dll=WIN_EVT_CFG.get('msg_dll')): """ register the event source in the windows registry This will create the registry needed for creating events for this particular combination of log type and application """ win32evtlogutil.AddSourceToRegistry(self.app_name, msgDLL=msg_dll, eventLogType=self.log_type)
def create(cls, name, log_name=DEFAULT_LOG_NAME): """Call the convenience functions to add a simple event source to the registry against a named event log (usually Application). Return the event source so you can log against it. :param name: name of the new event source :param log_name: name of the associated event log """ win32evtlogutil.AddSourceToRegistry(appName=name, eventLogType=log_name) return cls("", log_name, name)
def __init__(self, args): """Prepares the instance to be startable, but does not start the service.""" self.rpcserver = None self.service_methods = None self.service_methods_class = None self.LoadSettings() win32evtlogutil.AddSourceToRegistry(self._svc_display_name_, sys.executable, 'Application') win32serviceutil.ServiceFramework.__init__(self, args) self.h_wait_stop = win32event.CreateEvent(None, 0, 0, None) self.h_sock_event = win32event.CreateEvent(None, 0, 0, None)
def __init__(self, args): # The exe-file has messages for the Event Log Viewer. # Register the exe-file as event source. # # Probably it would be better if this is done at installation time, # so that it also could be removed if the service is uninstalled. # Unfortunately it cannot be done in the 'if __name__ == "__main__"' # block below, because the 'frozen' exe-file does not run this code. # win32evtlogutil.AddSourceToRegistry(self._svc_display_name_, servicemanager.__file__, "Application") win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self.WAIT_TIME = 1000 # in milliseconds
def __init__(self, args): logmsg("init") try: # The exe-file has messages for the Event Log Viewer. # Register the exe-file as event source. # # Probably it would be better if this is done at installation time, # so that it also could be removed if the service is uninstalled. # Unfortunately it cannot be done in the 'if __name__ == "__main__"' # block below, because the 'frozen' exe-file does not run this code. # logmsg("service start") win32evtlogutil.AddSourceToRegistry(self._svc_display_name_, sys.executable, "Application") win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) except: try: logmsg("exception") traceback.print_exc(None, logfilehandle) logfilehandle.flush() logfilehandle.close() except: os.abort()
class SyslogUDPHandler(SocketServer.BaseRequestHandler): def handle(self): data = bytes.decode(self.request[0].strip()) socket = self.request[1] print() win32evtlogutil.ReportEvent( logger_name, # Application name 1001, # Event ID 0, # Event category win32evtlog.EVENTLOG_INFORMATION_TYPE, (self.client_address[0], str(data))) if __name__ == "__main__": try: win32evtlogutil.AddSourceToRegistry(logger_name) win32evtlogutil.ReportEvent( logger_name, # Application name 1001, # Event ID 0, # Event category win32evtlog.EVENTLOG_INFORMATION_TYPE, (logger_name, "Started.")) server = SocketServer.UDPServer((HOST, PORT), SyslogUDPHandler) server.serve_forever(poll_interval=0.5) except (IOError, SystemExit): raise except KeyboardInterrupt: print("Crtl+C Pressed. Shutting down.")
servicemanager.LogInfoMsg(G_program_filename + ': ' + msg) # do additional work needed after installation (i.e. register event message file) if len(sys.argv) > 1 and sys.argv[1] in ("install", "update"): try: servicemanager.SetEventSourceName(G_service_name, True) except Exception as e: msg = 'Failed to SetEventSourceName: {}'.format(e) servicemanager.LogErrorMsg(G_program_filename + ': ' + msg) print(msg) try: win32evtlogutil.AddSourceToRegistry(SERVICE_NAME_PREFIX + G_program_name, msgDLL=G_program_directory + MESSAGE_FILE_DLL, eventLogType="Application", eventLogFlags=None) # note: At one time I was having problems with win32evtlogutil.AddSourceToRegistry and so # I wrote my own function RegisterEventLogMessage which is preserved above in a doc string # for reference. It is no longer needed at present. # RegisterEventLogMessage(SERVICE_NAME_PREFIX + G_program_name, G_program_directory) except Exception as e: msg = 'Failed to RegisterEventLogMessage: {}'.format(e) servicemanager.LogErrorMsg(G_program_filename + ': ' + msg) print(msg) pass