WIN32 Performance Data Helper problem

Mark Gash mgash at trisystems.co.uk
Thu Mar 28 09:23:40 EST 2002


Platform: 		Windows NT 4 (server and workstation)
Dev Environment: 	PythonWin 2.2
			win32all-146


I have written a script which monitors the disk space for Windows NT
machines. If the counter exceeds a set limit, then an email message is sent
to the administrator stating which machine and local disk is 'getting full'.
Once the comparisons have completed, the script sleeps for 2 hours then
re-enters the performance data collection/checking, sleeps for 2 hours....
ad infinitum

The problem is that the script does not work on NT 4 Servers, although it
works on NT4 clients. When the script is run on an NT 4 Server, the script
enters the while loop and fails at the performance collection phase. The
more serious issue is that there is no apparent errors thrown either by
Python or by NT itself. The script prints the line "Entering the while loop"
(as included in the extracted script) but then does nothing else.

I have attempted to research into the problem, and found that the script
failed on some workstations in a similar manner. I pinpointed this problem
down to being a missing pdh.dll from the %WINNT%/system32 directory. Once
this file was added, the clients worked ok.

Although I have attempted this resolution with the Servers, they are still
failing.

A brief extract of the script is contained below, [PS I am a newbie to
Python, so please try not to be too harsh about by coding ;-) ] .Also
detailed is the log created when the Server ran the script. If required, the
full script can be posted.

Any assistance in this matter would be gratefully received.

import sys
import os
import string                # required for string manipulation
import smtplib               # required for the emailing bits
import win32pdhutil          # for the Performance Data  Helper(utils)
methods
import win32pdh          # for the Performance Data Helper methods
import time                  # guess what? needed for time functions (sleep
and now)
import ConfigParser          # needed to read/write the ini files
import socket                # needed for the gethostname function
import win32api              # Two Win32 API's that are needed to query what
drives
import win32file             # are both fixed and on the local machine

def machinename():
    #get the hostname of the local machine
    return socket.gethostname()

def main(): 
    machinename = machinename()
    # analyse what drives are local HDD
    drives = [drive for drive in
win32api.GetLogicalDriveStrings().split('\x00')[:-1] if
win32file.GetDriveType(drive) == win32file.DRIVE_FIXED]
    #prepare the dictionary, depending on number of local drives
    for drive in drives:
        drive = drive[0]
        drive = drive + ":"
        counter[drive] = 0
    while 1:
        spam.logfile.write(now() + "     Entering while loop " + "\n")
        #read in performance data
        #compare values from performance data with the preset hwm
        # if the perf. data exceeds the hwm, then send an email alert
        for drive in drives:
            drive = drive[0]
            drive = drive + ":"
       # THIS IS THE LINE CAUSING PROBLEMS WITH NT SERVERS
            perfdata =
win32pdhutil.GetPerformanceAttributes("LogicalDisk","% Free Space",
"0/"+drive, -1, 256, machinename )
       # END - THIS IS THE LINE CAUSING PROBLEMS WITH NT SERVERS
            if perfdata <= setup.freelwmpercentage:
                counter[drive] += 1
            else:
                #do nothing
                pass
            if perfdata > setup.freelwmpercentage and counter[drive] > 0:
                #gradually return the counter back to zero as everything is
rosy...
                counter[drive] -= 1
            else:
                #do nothing
                pass
            if counter[drive] == 0:
                #do nothing as everything is 'hunky doory'
                pass
            elif counter[drive] > 11:
                spam.logfile.write(now() + "     Disk usage exceeds LWM
(minor)" + "\n")
                dcsend.send(drive, machinename, "LWM")
            elif perfdata < setup.freehwmpercentage:
                spam.logfile.write(now() + "     Disk usage exceeds HWM
(MAJOR)" + "\n")
                dcsend.send(drive, machinename, "HWM")
        time.sleep(7200) #wait for 2 hours then go back to the while
loop....
    #tidy up and close all open files
    spam.resultsclose()
    
if __name__ == '__main__':
    global strDirName 
    strDirName = ((os.path.dirname(os.path.abspath(sys.argv[0]))) + "\\")
    main()


The output from the log looks like this:-

*****************Start of Disk Checker Log File*****************
Wed Mar 27 11:02:36 2002     License Checker started
Wed Mar 27 11:02:37 2002     Entering while loop 



Kind Regards,

Mark Gash
Consultant
TriSystems Ltd.
020 7264 0440
mgash at trisystems.co.uk







-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list