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 disk auditing plugin that should work on most Windows systems
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 logging
28
29 win32api = None
30
31
32 _logger = logging.getLogger(__name__)
33 _logger.addHandler(logging.NullHandler())
34
35 try:
36 import win32api
37 except:
38 _logger.exception('%s failed to import required Windows specific modules: %s', __name__, ', '.join('win32api'))
39 raise
40
42 - def run(self, *args, **kwargs):
43
44 drive_info = {}
45 drives = win32api.GetLogicalDriveStrings().split('\0')
46
47 for drive in drives:
48 if drive not in drive_info:
49 drive_info[drive] = {}
50
51 try:
52 volume_info = win32api.GetVolumeInformation(drive)
53 except:
54 continue
55
56 drive_info[drive]['label'] = volume_info[0]
57 drive_info[drive]['serial_number'] = volume_info[1]
58 drive_info[drive]['file_system'] = volume_info[4]
59
60 space_info = win32api.GetDiskFreeSpaceEx(drive)
61 drive_info[drive]['available_bytes'] = space_info[0]
62 drive_info[drive]['total_bytes'] = space_info[1]
63
64 return drive_info
65