ironpython script to Monitor Servers internal CPU temprature using WMI MSAcpi_ThermalZoneTemperature with e-mail alerting capability RRS feed

  • General discussion

  • '''
    Created on feb 15, 2010
    this IronPython script reads servers from a txt file C:\\servers.txt , connects to each server with the function RemoteConnect
    Remoteconnect function reads the internal CPU TEMP from the WMI class MSAcpi_ThermalZoneTemperature located in namespace \root\WMI
    if internal CPU temp exceeds a certian Threshold , the function sends an alerting e-mail , it can also send an alerting SMS using a modem (not included)
    *settings crtcltemp depnds on your environmnet
    *servers.txt contains a server name per line 
    *Smtp server must support open relay from the sender ip address machine
    @author: Mohamed Garrana
    import clr,time,os.smtplib  
    from System.Management import  ManagementScope, ManagementObjectSearcher , WqlObjectQuery , ConnectionOptions
    crtcltemp = 3000 # set the critical temprature here , converting from Celcuis to Tenth of kelvin , 15 c * 10 + 2732 = 2882   
    #Remote connect function connects to a computer name with a username and password and reads "MSAcpi_ThermalZoneTemperature" from WMI
    #if the Cpu temp exceeds a certian Threshold, an alerting e-mail is sent 	
    def RemoteConnect(computername):
    	options = ConnectionOptions()
    	options.EnablePrivileges = True
    	options.Username = "Administrator" #set your username here
    	options.Password = "Password" #set your password here
    	network_scope = r"\\%s\root\WMI" %computername
    	print network_scope
    	scope =  ManagementScope(network_scope, options)
    	query = "Select * from  MSAcpi_ThermalZoneTemperature"
    	searcher = ManagementObjectSearcher(scope, WqlObjectQuery(query), None)
    	for cpu in searcher.Get():
    		nowtemp = int(cpu["CurrentTemperature"])
    		print nowtemp
    		if nowtemp >= crtcltemp:
    			print " critical temprature on %s" %(computername,)
    			#command= "python c:\\ %s" %(computername,) # calling another script with cpython for pyserial extension to work (alert by sms)
    			sender = ''  #set the sender e-mail address
    			receivers = ['']	#set the receiver e-mail address
    			# setting the e-mail Message (from,to,Subject,body)
    			message = """From: From Person <> 
    			To: To Person <''>
    			Subject: Spider Temperature Control Alerting System
    			Temparature is critical on server %s .
    			""" %computername
    			#trying to send an e-mail
    			try :
    				mailobj=smtplib.SMTP("mailserver") #set the ip address of the SMTP mail server supporting open relay
    				mailobj.sendmail(sender, receivers, message)         
    				print "Alert E-mail sent Successfully "
    			except :
    				print "Error: unable to send Alert using e-mail"
    			print command
    			print "Temperature normal on %s" %(computername,)	
    #opening a txt file with server names to monitor			
    #infinite loop going through the servers one by one to the RemoteConnect function
    while 1:
    	server = listofservers[j].strip()
    	print server
    	if  j == numberofservers: 

    • Moved by Bill_Stewart Monday, July 28, 2014 5:24 PM Off-topic
    Friday, March 12, 2010 2:26 PM