[python-win32] Writing event to event log...
Larry Bates
lbates at syscononline.com
Mon Aug 9 15:26:26 CEST 2004
If you don't already have it, pick up a copy of Mark Hammond's
excellent Python Programming on Win32. It has good examples
of writing to event log along with a bunch of other Windows
"specific" information that is difficult to find anywhere else.
HTH,
Larry Bates
Syscon, Inc.
------------------------------------------------------------------
Message: 1
Date: Sun, 8 Aug 2004 08:24:19 -0400 (EDT)
From: fmml at cedval.org
Subject: [python-win32] Writing event to event log...
To: python-win32 at python.org
Message-ID:
<4143.192.168.41.52.1091967859.squirrel at whoami3.cedval.org>
Content-Type: text/plain;charset=iso-8859-1
Hi all,
I am looking for a way to write to the windows event log, abritrary
events. For example, I have written a script that check the presense of
certain processes, if one of them is not present, I want to write an
event.
How can I do that, can someone show me an example...
Thanks in advance,
Francois
------------------------------
Message: 2
Date: Mon, 9 Aug 2004 03:39:34 +0200
From: Imre Andr?s R?bert <beast at ludens.elte.hu>
Subject: Re: [python-win32] Writing event to event log...
To: fmml at cedval.org, python-win32 at python.org
Message-ID: <1212480976.20040809033934 at ludens.elte.hu>
Content-Type: text/plain; charset=ISO-8859-1
Hello fmml,
The ReportEvent method is a decent one to try,
you may find in in win32evtlogutil.py.
The servicemanager module contains some simple
methods for this as well:
LogMsg
Write an specific message to the log.
LogInfoMsg
Write an informational message to the log.
LogErrorMsg
Write an error message to the log.
LogWarningMsg
Logs a generic warning message to the event log.
Supposed you installed pywin32, you could have a look at
these in use in demos under <python home>\Lib\site-packages\win32\Demos
directory. Especially eventLogDemo.py and service\pipeTestService.py.
That's a good starting point. Should you need to define your own
categories and event IDs, things will get harder. If still interested,
you may find an ongoing discussion on this topic in the following thread
here: [Windows service features and Python]
Hope this helps,
Andras
Sunday, August 8, 2004, 2:24:19 PM, you wrote:
> Hi all,
> I am looking for a way to write to the windows event log, abritrary
> events. For example, I have written a script that check the presense of
> certain processes, if one of them is not present, I want to write an
> event.
> How can I do that, can someone show me an example...
> Thanks in advance,
> Francois
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
------------------------------
Message: 3
Date: Mon, 9 Aug 2004 04:24:16 +0200
From: Imre Andr?s R?bert <beast at ludens.elte.hu>
Subject: Re[2]: [python-win32] Re: Windows service features and Python
To: "Mark Hammond" <mhammond at skippinet.com.au>
Cc: python-win32 at python.org
Message-ID: <1086682785.20040809042416 at ludens.elte.hu>
Content-Type: text/plain; charset=ISO-8859-15
Hello Mark,
Friday, August 6, 2004, 2:16:06 AM, you wrote:
>> > I'm transforming some Python code into a Windows
>> > service. I started with pywin32-202.win32-py2.2.exe,
>> > and investigated the demo pipeTestService. This
>> > worked fine, so I started converting my code, with
>> > no paticular Windows system programming experience.
> I'm afraid your problems relate to this lack of Windows experience more than
> to Python itself. "Python Programming on Win32" does cover alot of this
> stuff in some detail, but general overviews of Windows services would be
> useful.
I studied PPWin32 and MSDN too. Now I'm a bit brighter...
>> > Q1) How can I make my Python service support pause/
>> > continue? Implementing SvcPause() and SvcContinue()
>> > seems to be not enough, as I get 'Could not pause
>> > ... service on Local Computer. The service did not
>> > return an error. ...' dialog despite that the
>> > SvcPause() method is executed. After this dialog
>> > I found that the service was stopped, ending within
>> > SvcDoRun(). Please refer to the attached code.
> You need to report a status of PAUSED to the service control manager, in the
> same way that RUNNING, START_PENDING, STOP_PENDING and STOPPED are alreay
> reported. Indeed, if your pause takes some time, you must periodically
> report PAUSE_PENDING, until you actually enter the PAUSED state.
My error was that in SvcPause I used to set PAUSE_PENDING and then
SetEvent(self.hWaitStop), and sent no periodic reports. Now I set
status to PAUSED immediately, and omitted that SetEvent. Similarly,
SvcContinue sets status to RUNNING immediately. This works.
I also realized that its me who have to manage the periodic reporting
in pending states. I haven't tried this yet, but I think I see the
picture.
> What "pause" means is up to you and your code. One strategy would be to use
> an event, much in the same way that "stop" is handled in the samples.
>> > Q2) How can I register my own event IDs/categories? I don't
>> > know where/how to define my own IDs/cats. The demo seems
>> > to support two IDs, servicemanager.PYS_SERVICE_STARTED and
>> > servicemanager.PYS_SERVICE_STOPPED.
> See PPWin32 - in a nutshell, there are a number of predefined messages, and
> unfortunately you need to look in win32\src\PythonServiceMessages.mc in the
> source distribution (or via the CVS viewer). These .mc files are compiled
> using MSVC6 tools, so there is currently no easy to to define your own. You
> are free to use the various "general" ones in PythonServiceMessages.mc.
Based on the downloaded source, I created a dll with MSVC, and managed
to write events with IDs from that dll. However, for custom categories
I had to create the registry keys by hand, because I found no method for
this in PyWin32.
Now I'm trying to figure out how can I make these IDs visible by
symbolic name in my Python source, like pipeTestService uses
servicemanager.pyd. I don't want to define these twice, and
keep in sync all the time...
>> > Q3) How can I add counters to the Python service? Looking at
>> > the files perf_install.ini and perf_install.h, this
>> > could be possible, but after install I do not see these
>> > counters in PerfMon. I do not see the way these files
>> > are connected to the service demo source code... Maybe
>> > these are already installed as the readme indicates,
>> > but where should I look?
> Sorry, but I can't recall exactly. perfmon counters are not for the feint
> hearted. Again, PPWin32 covers that.
PPWin32's examples contains PipeService2.py, and this matches
with its ini files, as uses IDs defined there. (PyWin32 source
example does not use any counters.) But this only works if the
service is installed with the --perfmonini switch. Once installed
this way, I can see all those counters in PerfMon.
I found this out only by looking at the source, as its help does
not mention this switch. It would also be nice if this would
support pause and continue functions.
Thanks for the help so far.
It seems that now I got all the answers, except for one new question:
Q4) I can't make my service interactive. I never get a console
window despite that I use the --interactive flag, and I can
see it set under the logon tab of service properties. What
did I get wrong?
--
Thanks,
Andras
> Mark.
------------------------------
_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
End of Python-win32 Digest, Vol 17, Issue 8
*******************************************
More information about the Python-win32
mailing list