tag:blogger.com,1999:blog-5236867476487043111.post7778691652986918483..comments2024-03-11T07:55:47.104-04:00Comments on Corey Goldberg: Python - Monitor Windows Remotely With WMICorey Goldberghttp://www.blogger.com/profile/06219872951977664560noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-5236867476487043111.post-847567523775389272011-02-17T05:25:22.857-05:002011-02-17T05:25:22.857-05:00Hey, nice tutorial. Thanks!
I wonder if the '...Hey, nice tutorial. Thanks!<br /><br />I wonder if the 'get_cpu' function could be used to check for remote server's crashes/BSOD/freezes/hangs?<br />How would one check that?sivahttp://siva_rocks@yahoo.comnoreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-65251313726561959432009-04-26T23:20:00.000-04:002009-04-26T23:20:00.000-04:00Thanks Corey. I've been doing similar things with ...Thanks Corey. I've been doing similar things with PHP and a mix of VBScript and SNMP, but want to go cross platform.<br /><br />Don't suppose you'd like to share the multi-thread manager or point a Python beginner to somewhere? This is obviously key to getting some scale in any monitoring system.<br /><br />http://www.wekadesign.co.nz/overview.htmlMikehttp://www.wekadesign.co.nznoreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-35716047003572344362009-04-14T03:00:00.000-04:002009-04-14T03:00:00.000-04:00Thanks for this postThanks for this postweb design companyhttp://www.vijayinfo.innoreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-20043643907475457022008-12-27T09:22:00.000-05:002008-12-27T09:22:00.000-05:00The wmi lib I believe only works via Windows right...The wmi lib I believe only works via Windows right ? But there is a way to do it on Linux :-)<BR/><BR/>http://felimwhiteley.wordpress.com/2008/10/01/using-python-to-retrieve-wmi-data-using-wmic/<BR/><BR/>wmic is actually a library, I didn't realise it was Python initially.. oops. Uses Samba4 pre-release code to implement the WMI.<BR/><BR/>- FĂ©limAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-80759859386622860972008-12-18T15:54:00.000-05:002008-12-18T15:54:00.000-05:00Ah!Excellent post! I have been trying to figure o...Ah!<BR/><BR/>Excellent post! I have been trying to figure out how to use WMI to see if my Python app is taking up too much RAM. <BR/><BR/>I've been pulling out hair trying to figure out the syntax to get at the data in this class....<BR/><BR/>Thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-33400618769168412492008-12-15T18:17:00.000-05:002008-12-15T18:17:00.000-05:00@Anon,I am not using Nagios. See my comment above...@Anon,<BR/>I am not using Nagios. See my comment above.Corey Goldberghttps://www.blogger.com/profile/06219872951977664560noreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-32961582969320891122008-12-15T18:15:00.000-05:002008-12-15T18:15:00.000-05:00Why not use one of the windows clients for nagios ...Why not use one of the windows clients for nagios http://nagios.sourceforge.net/docs/3_0/monitoring-windows.html ? <BR/><BR/>Then you can still call python scripts that are called on either the local machine or remotely using any Windows box as a WMI proxy.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-19707084681378142772008-12-13T15:34:00.000-05:002008-12-13T15:34:00.000-05:00w00t, Doug Heffernan uses python too!w00t, Doug Heffernan uses python too!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-86281140222726173782008-12-13T11:16:00.000-05:002008-12-13T11:16:00.000-05:00@etankthanks for the code.If you have any more cod...@etank<BR/><BR/>thanks for the code.<BR/><BR/>If you have any more code for metrics, paste it in!Corey Goldberghttps://www.blogger.com/profile/06219872951977664560noreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-89643980306392849372008-12-13T11:15:00.000-05:002008-12-13T11:15:00.000-05:00> Home grown? Ouch. > Just install GroundWor...> Home grown? Ouch. <BR/>> Just install GroundWork Monitor<BR/><BR/>I'm actually the author of the Web Plugin for GroundWork and Nagios, so I looked there first.<BR/><BR/>I'm building my own.. new wheel or not :)Corey Goldberghttps://www.blogger.com/profile/06219872951977664560noreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-52943073115727135282008-12-13T09:04:00.000-05:002008-12-13T09:04:00.000-05:00man that mangled the tabs. oh well you can get the...man that mangled the tabs. oh well you can get the idea.Anonymoushttps://www.blogger.com/profile/07065049503301822169noreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-77209544377706636972008-12-13T09:03:00.000-05:002008-12-13T09:03:00.000-05:00One of the things that we have to keep a close wat...One of the things that we have to keep a close watch on is the amount of free disk space for all attached drives. You could add to and improve this:<BR/><BR/>import string<BR/>import wmi<BR/><BR/>class SysInfo(object):<BR/> def __init__(self, hostname=''):<BR/> if hostname == '':<BR/> self.host = 'localhost'<BR/> else:<BR/> self.host = hostname<BR/> try:<BR/> self.server = wmi.WMI(self.host)<BR/> except wmi.x_wmi:<BR/> print "%s is not available" % self.host<BR/> <BR/> def GetLocalDrives(self):<BR/> driveList = []<BR/> for disk in self.server.Win32_LogicalDisk():<BR/> if disk.DriveType == 3:<BR/> driveList.append(str(disk.Name))<BR/> return driveList<BR/><BR/> def GetTotalDiskSpace(self, drive):<BR/> self.drive = drive<BR/> try:<BR/> for disk in self.server.Win32_LogicalDisk(Name=self.drive):<BR/> total = long(disk.Size) /1073741824.0<BR/> return total<BR/> except UnboundLocalError:<BR/> raise 'Drive Not Found'<BR/><BR/> def GetFreeDiskSpace(self, drive):<BR/> self.drive = drive<BR/> try:<BR/> for disk in self.server.Win32_LogicalDisk(Name=self.drive):<BR/> free = long(disk.FreeSpace) /1073741824.0<BR/> return total<BR/> except UnboundLocalError:<BR/> return 'Drive Not Found'<BR/><BR/> def GetUsedDiskSpace(self, drive):<BR/> self.drive = drive<BR/> total = self.GetTotalDiskSpace(self.drive)<BR/> free = self.GetFreeDiskSpace(self.drive)<BR/> used = (total - free)<BR/> return used<BR/><BR/> def GetPercentDiskUsage(self, drive):<BR/> self.drive = drive<BR/> total = self.GetTotalDiskSpace(self.drive)<BR/> used = self.GetUsedDiskSpace(self.drive)<BR/> per_used = (used * 100) / total<BR/> return per_used <BR/><BR/> def GetCpuList(self):<BR/> '''<BR/> Attempt to get a list containing the names of the CPUs in<BR/> the system. This should be one name per physical CPU but<BR/> it seems that hyperthreading seems to make it show 2x the<BR/> actual number.<BR/> '''<BR/> cpulist = []<BR/> cpudict = {}<BR/> for cpu in self.server.Win32_Processor():<BR/> name = string.strip(str(cpu.Name))<BR/> deviceid = str(cpu.DeviceID)<BR/> cpudict = {deviceid:name}<BR/> cpulist.append(cpudict)<BR/> return cpulist<BR/><BR/> def GetNumCpu(self):<BR/> '''<BR/> Call GetCpuList and then return the number of items in the list.<BR/> '''<BR/> cpus = self.GetCpuList()<BR/> return len(cpus)<BR/><BR/> def GetServiceStatus(self, caption):<BR/> self.caption = caption<BR/> for svc in self.server.Win32_Service(Caption=self.caption):<BR/> state = svc.State<BR/> return str(state)<BR/><BR/> def GetNodeName(self):<BR/> '''<BR/> This is for when you are looking at a clustered env and<BR/> want to know who the active node is.<BR/> '''<BR/> for os in self.server.Win32_OperatingSystem():<BR/> activeNode = os.CSName<BR/> return str(activeNode)Anonymoushttps://www.blogger.com/profile/07065049503301822169noreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-84196794136517249492008-12-13T08:43:00.000-05:002008-12-13T08:43:00.000-05:00ActivePython could be interpreted via WScript.exe ...ActivePython could be interpreted via WScript.exe with a .pys extension filename, which could invoke WMI without install pywin32 stuff, I guessesthttps://www.blogger.com/profile/14946233761031510690noreply@blogger.comtag:blogger.com,1999:blog-5236867476487043111.post-83585674505613880802008-12-13T02:23:00.000-05:002008-12-13T02:23:00.000-05:00Home grown? Ouch. Just install GroundWork Monitor....Home grown? Ouch. Just install GroundWork Monitor. http://www.groundworkopensource.com/Anonymousnoreply@blogger.com