1 """
2 @copyright: 2011 Mark LaPerriere
3
4 @license:
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 U{http://www.apache.org/licenses/LICENSE-2.0}
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 @summary:
18 A processor auditor that should work on most Windows hosts
19
20 @author: Mark LaPerriere
21 @contact: pyhai@mindmind.com
22 @organization: Mind Squared Design / www.mindmind.com
23 @version: 0.1.3
24 @date: Jan 19, 2012
25 """
26 from pyhai.plugins import AuditorPlugin
27 import sys
28 import logging
29
30 win32api = None
31 win32con = None
32
33
34 _logger = logging.getLogger(__name__)
35 _logger.addHandler(logging.NullHandler())
36
37 try:
38 import win32api
39 import win32con
40 except:
41 _logger.exception('%s failed to import required Windows specific modules: %s', __name__, ', '.join('win32api', 'win32con'))
42 raise
43
45 - def run(self, *args, **kwargs):
46 processor_info = {}
47 processor_description_key_path = 'HARDWARE\DESCRIPTION\System\CentralProcessor'
48 system_env_vars_key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, processor_description_key_path)
49 value_index = 0
50 try:
51 while True:
52 cpu_index = win32api.RegEnumKey(system_env_vars_key, value_index)
53 cpu_reg = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, processor_description_key_path + '\\' + cpu_index)
54 processor_info[cpu_index] = {
55 'mhz': win32api.RegQueryValueEx(cpu_reg, '~MHz')[0],
56 'identifier': win32api.RegQueryValueEx(cpu_reg, 'Identifier')[0],
57 'name_string': win32api.RegQueryValueEx(cpu_reg, 'ProcessorNameString')[0],
58 'vendor_identifier': win32api.RegQueryValueEx(cpu_reg, 'VendorIdentifier')[0],
59 }
60 value_index += 1
61 except:
62 exc_id = sys.exc_info()[1][0]
63 if exc_id != 259:
64 raise
65
66 processor_info['count'] = len(processor_info)
67
68 return processor_info
69