manageiq-smartstate 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +4 -0
- data/.rspec_ci +4 -0
- data/.travis.yml +15 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +202 -0
- data/README.md +45 -0
- data/Rakefile +23 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/MiqContainerGroup/MiqContainerGroup.rb +31 -0
- data/lib/MiqVm/MiqLocalVm.rb +50 -0
- data/lib/MiqVm/MiqRhevmVm.rb +179 -0
- data/lib/MiqVm/MiqVm.rb +355 -0
- data/lib/MiqVm/miq_azure_vm.rb +96 -0
- data/lib/MiqVm/miq_scvmm_vm.rb +38 -0
- data/lib/MiqVm/test/camcorder_fleece_test.rb +60 -0
- data/lib/MiqVm/test/localVm.rb +45 -0
- data/lib/MiqVm/test/partitionAlignmentCheck.rb +76 -0
- data/lib/MiqVm/test/remoteVm.rb +65 -0
- data/lib/MiqVm/test/rhevmNfsTest.rb +62 -0
- data/lib/MiqVm/test/rhevmNfsTest2.rb +66 -0
- data/lib/MiqVm/test/rhevmTest.rb +70 -0
- data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackCommon.rb +107 -0
- data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackImage.rb +67 -0
- data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackInstance.rb +182 -0
- data/lib/Scvmm/miq_hyperv_disk.rb +273 -0
- data/lib/Scvmm/miq_scvmm_parse_powershell.rb +75 -0
- data/lib/Scvmm/miq_scvmm_vm_ssa_info.rb +135 -0
- data/lib/Scvmm/test/miq_hyperv_disk_test.rb +33 -0
- data/lib/Scvmm/test/miq_scvmm_vm_ssa_info_test.rb +41 -0
- data/lib/VmLocalDiskAccess/test/localCfg.rb +97 -0
- data/lib/VolumeManager/LVM/logical_volume.rb +75 -0
- data/lib/VolumeManager/LVM/lv_segment.rb +43 -0
- data/lib/VolumeManager/LVM/lvm2disk.rb +158 -0
- data/lib/VolumeManager/LVM/parser.rb +138 -0
- data/lib/VolumeManager/LVM/physical_volume.rb +19 -0
- data/lib/VolumeManager/LVM/scanner.rb +156 -0
- data/lib/VolumeManager/LVM/thin/btree.rb +83 -0
- data/lib/VolumeManager/LVM/thin/constants.rb +86 -0
- data/lib/VolumeManager/LVM/thin/data_map.rb +44 -0
- data/lib/VolumeManager/LVM/thin/mapping_tree.rb +19 -0
- data/lib/VolumeManager/LVM/thin/space_maps.rb +58 -0
- data/lib/VolumeManager/LVM/thin/superblock.rb +136 -0
- data/lib/VolumeManager/LVM/thin.rb +6 -0
- data/lib/VolumeManager/LVM/volume_group.rb +97 -0
- data/lib/VolumeManager/LVM.rb +8 -0
- data/lib/VolumeManager/MiqLdm.rb +546 -0
- data/lib/VolumeManager/MiqLvm.rb +17 -0
- data/lib/VolumeManager/MiqNativeVolumeManager.rb +150 -0
- data/lib/VolumeManager/MiqVolumeManager.rb +277 -0
- data/lib/VolumeManager/VolMgrPlatformSupport.rb +18 -0
- data/lib/VolumeManager/VolMgrPlatformSupportLinux.rb +77 -0
- data/lib/VolumeManager/VolMgrPlatformSupportWin.rb +17 -0
- data/lib/VolumeManager/test/blockDevTest.rb +40 -0
- data/lib/VolumeManager/test/ldm.rb +97 -0
- data/lib/blackbox/VmBlackBox.rb +103 -0
- data/lib/blackbox/xmlStorage.rb +180 -0
- data/lib/db/MiqBdb/MiqBdb.rb +309 -0
- data/lib/db/MiqBdb/MiqBdbBtree.rb +219 -0
- data/lib/db/MiqBdb/MiqBdbHash.rb +199 -0
- data/lib/db/MiqBdb/MiqBdbPage.rb +159 -0
- data/lib/db/MiqBdb/MiqBdbUtil.rb +18 -0
- data/lib/db/MiqSqlite/MiqSqlite3.rb +330 -0
- data/lib/db/MiqSqlite/MiqSqlite3Cell.rb +167 -0
- data/lib/db/MiqSqlite/MiqSqlite3Page.rb +151 -0
- data/lib/db/MiqSqlite/MiqSqlite3Table.rb +124 -0
- data/lib/db/MiqSqlite/MiqSqlite3Util.rb +32 -0
- data/lib/disk/DiskProbe.rb +68 -0
- data/lib/disk/MiqDisk.rb +317 -0
- data/lib/disk/camcorder_test.rb +90 -0
- data/lib/disk/dos_mbr.img +0 -0
- data/lib/disk/modules/AzureBlobDisk.rb +101 -0
- data/lib/disk/modules/LocalDevMod.rb +47 -0
- data/lib/disk/modules/LocalDevProbe.rb +6 -0
- data/lib/disk/modules/MSCommon.rb +352 -0
- data/lib/disk/modules/MSVSDiffDisk.rb +91 -0
- data/lib/disk/modules/MSVSDiskProbe.rb +61 -0
- data/lib/disk/modules/MSVSDynamicDisk.rb +42 -0
- data/lib/disk/modules/MSVSFixedDisk.rb +45 -0
- data/lib/disk/modules/MiqLargeFile.rb +63 -0
- data/lib/disk/modules/MiqLargeFileWin32.rb +107 -0
- data/lib/disk/modules/QcowDisk.rb +692 -0
- data/lib/disk/modules/QcowDiskProbe.rb +34 -0
- data/lib/disk/modules/RawBlockIO.rb +116 -0
- data/lib/disk/modules/RawDisk.rb +45 -0
- data/lib/disk/modules/RawDiskProbe.rb +7 -0
- data/lib/disk/modules/RhevmDescriptor.rb +167 -0
- data/lib/disk/modules/RhevmDiskProbe.rb +52 -0
- data/lib/disk/modules/VMWareCowdDisk.rb +207 -0
- data/lib/disk/modules/VMWareDescriptor.rb +214 -0
- data/lib/disk/modules/VMWareDiskProbe.rb +74 -0
- data/lib/disk/modules/VMWareSparseDisk.rb +189 -0
- data/lib/disk/modules/VhdxDisk.rb +625 -0
- data/lib/disk/modules/VhdxDiskProbe.rb +46 -0
- data/lib/disk/modules/VixDiskMod.rb +54 -0
- data/lib/disk/modules/VixDiskProbe.rb +6 -0
- data/lib/disk/modules/miq_disk_cache.rb +135 -0
- data/lib/disk/modules/miq_dummy_disk.rb +41 -0
- data/lib/disk/modules/vhdx_bat_entry.rb +10 -0
- data/lib/disk/test.rb +66 -0
- data/lib/fs/MetakitFS/MetakitFS.rb +530 -0
- data/lib/fs/MetakitFS/test/Makefile +14 -0
- data/lib/fs/MetakitFS/test/MkCollectFiles.rb +165 -0
- data/lib/fs/MetakitFS/test/MkSelectFiles.rb +30 -0
- data/lib/fs/MetakitFS/test/collect_files.yaml +70 -0
- data/lib/fs/MetakitFS/test/init.rb +3 -0
- data/lib/fs/MetakitFS/test/mk2vmdk.rb +64 -0
- data/lib/fs/MetakitFS/test/mk4test.c +92 -0
- data/lib/fs/MetakitFS/test/mkFsTest.rb +113 -0
- data/lib/fs/MetakitFS/test/proto.rb +97 -0
- data/lib/fs/MiqFS/FsProbe.rb +39 -0
- data/lib/fs/MiqFS/MiqFS.rb +515 -0
- data/lib/fs/MiqFS/modules/AUFSProbe.rb +26 -0
- data/lib/fs/MiqFS/modules/Ext3.rb +305 -0
- data/lib/fs/MiqFS/modules/Ext3Probe.rb +25 -0
- data/lib/fs/MiqFS/modules/Ext4.rb +304 -0
- data/lib/fs/MiqFS/modules/Ext4Probe.rb +25 -0
- data/lib/fs/MiqFS/modules/Fat32.rb +318 -0
- data/lib/fs/MiqFS/modules/Fat32Probe.rb +30 -0
- data/lib/fs/MiqFS/modules/HFSProbe.rb +18 -0
- data/lib/fs/MiqFS/modules/Iso9660.rb +293 -0
- data/lib/fs/MiqFS/modules/Iso9660Probe.rb +18 -0
- data/lib/fs/MiqFS/modules/LocalFS.rb +105 -0
- data/lib/fs/MiqFS/modules/NTFS.rb +287 -0
- data/lib/fs/MiqFS/modules/NTFSProbe.rb +21 -0
- data/lib/fs/MiqFS/modules/NativeFS.rb +155 -0
- data/lib/fs/MiqFS/modules/ReFSProbe.rb +17 -0
- data/lib/fs/MiqFS/modules/RealFS.rb +79 -0
- data/lib/fs/MiqFS/modules/RealFSProbe.rb +6 -0
- data/lib/fs/MiqFS/modules/Reiser4Probe.rb +18 -0
- data/lib/fs/MiqFS/modules/ReiserFS.rb +315 -0
- data/lib/fs/MiqFS/modules/ReiserFSProbe.rb +42 -0
- data/lib/fs/MiqFS/modules/UnionFSProbe.rb +18 -0
- data/lib/fs/MiqFS/modules/WebDAV.rb +127 -0
- data/lib/fs/MiqFS/modules/WebDAVFile.rb +68 -0
- data/lib/fs/MiqFS/modules/XFS.rb +300 -0
- data/lib/fs/MiqFS/modules/XFSProbe.rb +26 -0
- data/lib/fs/MiqFS/modules/ZFSProbe.rb +18 -0
- data/lib/fs/MiqFS/test.rb +59 -0
- data/lib/fs/MiqFsUtil.rb +383 -0
- data/lib/fs/MiqMountManager.rb +209 -0
- data/lib/fs/MiqNativeMountManager.rb +101 -0
- data/lib/fs/MountManagerProbe.rb +29 -0
- data/lib/fs/ReiserFS/block.rb +209 -0
- data/lib/fs/ReiserFS/directory.rb +136 -0
- data/lib/fs/ReiserFS/directory_entry.rb +140 -0
- data/lib/fs/ReiserFS/file_data.rb +111 -0
- data/lib/fs/ReiserFS/superblock.rb +140 -0
- data/lib/fs/ReiserFS/utils.rb +95 -0
- data/lib/fs/VimDatastoreFS/VimDatastoreFS.rb +192 -0
- data/lib/fs/ext3/alloc_bitmap.rb +38 -0
- data/lib/fs/ext3/block_pointers_path.rb +130 -0
- data/lib/fs/ext3/directory.rb +51 -0
- data/lib/fs/ext3/directory_entry.rb +67 -0
- data/lib/fs/ext3/ex_attrib_header.rb +14 -0
- data/lib/fs/ext3/ex_attrib_name.rb +23 -0
- data/lib/fs/ext3/file_data.rb +130 -0
- data/lib/fs/ext3/group_descriptor_entry.rb +65 -0
- data/lib/fs/ext3/group_descriptor_table.rb +54 -0
- data/lib/fs/ext3/hash_tree_entry.rb +18 -0
- data/lib/fs/ext3/hash_tree_header.rb +15 -0
- data/lib/fs/ext3/inode.rb +228 -0
- data/lib/fs/ext3/posix_acl_entry.rb +29 -0
- data/lib/fs/ext3/posix_acl_header.rb +11 -0
- data/lib/fs/ext3/superblock.rb +406 -0
- data/lib/fs/ext3/test/tc_Ext3BlockPointersPath.rb +74 -0
- data/lib/fs/ext4/alloc_bitmap.rb +38 -0
- data/lib/fs/ext4/directory.rb +87 -0
- data/lib/fs/ext4/directory_entry.rb +77 -0
- data/lib/fs/ext4/ex_attrib_header.rb +14 -0
- data/lib/fs/ext4/ex_attrib_name.rb +23 -0
- data/lib/fs/ext4/extent.rb +35 -0
- data/lib/fs/ext4/extent_header.rb +40 -0
- data/lib/fs/ext4/extent_index.rb +33 -0
- data/lib/fs/ext4/group_descriptor_entry.rb +69 -0
- data/lib/fs/ext4/group_descriptor_table.rb +54 -0
- data/lib/fs/ext4/hash_tree_entry.rb +58 -0
- data/lib/fs/ext4/hash_tree_header.rb +35 -0
- data/lib/fs/ext4/inode.rb +465 -0
- data/lib/fs/ext4/posix_acl_entry.rb +29 -0
- data/lib/fs/ext4/posix_acl_header.rb +11 -0
- data/lib/fs/ext4/superblock.rb +412 -0
- data/lib/fs/fat32/boot_sect.rb +379 -0
- data/lib/fs/fat32/directory.rb +222 -0
- data/lib/fs/fat32/directory_entry.rb +540 -0
- data/lib/fs/fat32/file_data.rb +128 -0
- data/lib/fs/iso9660/boot_sector.rb +170 -0
- data/lib/fs/iso9660/directory.rb +90 -0
- data/lib/fs/iso9660/directory_entry.rb +147 -0
- data/lib/fs/iso9660/file_data.rb +78 -0
- data/lib/fs/iso9660/rock_ridge.rb +329 -0
- data/lib/fs/iso9660/util.rb +57 -0
- data/lib/fs/modules/LinuxMount.rb +300 -0
- data/lib/fs/modules/LinuxMountProbe.rb +29 -0
- data/lib/fs/modules/WinMount.rb +97 -0
- data/lib/fs/modules/WinMountProbe.rb +24 -0
- data/lib/fs/ntfs/attrib_attribute_list.rb +131 -0
- data/lib/fs/ntfs/attrib_bitmap.rb +26 -0
- data/lib/fs/ntfs/attrib_data.rb +74 -0
- data/lib/fs/ntfs/attrib_file_name.rb +110 -0
- data/lib/fs/ntfs/attrib_header.rb +194 -0
- data/lib/fs/ntfs/attrib_index_allocation.rb +19 -0
- data/lib/fs/ntfs/attrib_index_root.rb +247 -0
- data/lib/fs/ntfs/attrib_object_id.rb +40 -0
- data/lib/fs/ntfs/attrib_standard_information.rb +107 -0
- data/lib/fs/ntfs/attrib_type.rb +49 -0
- data/lib/fs/ntfs/attrib_volume_information.rb +53 -0
- data/lib/fs/ntfs/attrib_volume_name.rb +31 -0
- data/lib/fs/ntfs/boot_sect.rb +253 -0
- data/lib/fs/ntfs/data_run.rb +358 -0
- data/lib/fs/ntfs/directory_index_node.rb +114 -0
- data/lib/fs/ntfs/index_node_header.rb +69 -0
- data/lib/fs/ntfs/index_record_header.rb +85 -0
- data/lib/fs/ntfs/mft_entry.rb +288 -0
- data/lib/fs/ntfs/utils.rb +43 -0
- data/lib/fs/test/camcorder_fs_test.rb +108 -0
- data/lib/fs/test/collect_files_direct.yaml +22 -0
- data/lib/fs/test/collect_files_in.yaml +24 -0
- data/lib/fs/test/collect_files_in_nc.yaml +22 -0
- data/lib/fs/test/collect_files_out.yaml +6 -0
- data/lib/fs/test/collect_files_rm.yaml +6 -0
- data/lib/fs/test/copyTest.rb +126 -0
- data/lib/fs/test/fsTest.rb +87 -0
- data/lib/fs/test/updateTest.rb +184 -0
- data/lib/fs/xfs/allocation_group.rb +160 -0
- data/lib/fs/xfs/bmap_btree_block.rb +125 -0
- data/lib/fs/xfs/bmap_btree_record.rb +80 -0
- data/lib/fs/xfs/bmap_btree_root_node.rb +72 -0
- data/lib/fs/xfs/directory.rb +133 -0
- data/lib/fs/xfs/directory2_data_header.rb +27 -0
- data/lib/fs/xfs/directory3_data_header.rb +34 -0
- data/lib/fs/xfs/directory_block_tail.rb +22 -0
- data/lib/fs/xfs/directory_data_header.rb +46 -0
- data/lib/fs/xfs/directory_entry.rb +106 -0
- data/lib/fs/xfs/inode.rb +532 -0
- data/lib/fs/xfs/inode_map.rb +100 -0
- data/lib/fs/xfs/short_form_directory_entry.rb +91 -0
- data/lib/fs/xfs/short_form_header.rb +44 -0
- data/lib/fs/xfs/superblock.rb +556 -0
- data/lib/lib/tasks/azure.rake +52 -0
- data/lib/manageiq/smartstate/version.rb +5 -0
- data/lib/manageiq/smartstate.rb +7 -0
- data/lib/manageiq-smartstate.rb +1 -0
- data/lib/metadata/MIQExtract/MIQExtract.rb +297 -0
- data/lib/metadata/MIQExtract/test/extractTest.rb +41 -0
- data/lib/metadata/MIQExtract/test/full_extract_test.rb +68 -0
- data/lib/metadata/ScanProfile/HostScanItem.rb +4 -0
- data/lib/metadata/ScanProfile/HostScanProfile.rb +4 -0
- data/lib/metadata/ScanProfile/HostScanProfiles.rb +41 -0
- data/lib/metadata/ScanProfile/ScanItemBase.rb +63 -0
- data/lib/metadata/ScanProfile/ScanProfileBase.rb +51 -0
- data/lib/metadata/ScanProfile/ScanProfilesBase.rb +60 -0
- data/lib/metadata/ScanProfile/VmScanItem.rb +4 -0
- data/lib/metadata/ScanProfile/VmScanProfile.rb +4 -0
- data/lib/metadata/ScanProfile/VmScanProfiles.rb +38 -0
- data/lib/metadata/ScanProfile/modules/HostScanItemFile.rb +51 -0
- data/lib/metadata/ScanProfile/modules/HostScanItemNteventlog.rb +84 -0
- data/lib/metadata/ScanProfile/modules/VmScanItemFile.rb +39 -0
- data/lib/metadata/ScanProfile/modules/VmScanItemNteventlog.rb +34 -0
- data/lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb +64 -0
- data/lib/metadata/VMMount/VMMount.rb +81 -0
- data/lib/metadata/VMMount/VMPlatformMount.rb +18 -0
- data/lib/metadata/VMMount/VMPlatformMountLinux.rb +75 -0
- data/lib/metadata/VMMount/VMPlatformMountWin.rb +13 -0
- data/lib/metadata/VmConfig/GetNativeCfg.rb +45 -0
- data/lib/metadata/VmConfig/VmConfig.rb +947 -0
- data/lib/metadata/VmConfig/cfgConfig.rb +45 -0
- data/lib/metadata/VmConfig/ovfConfig.rb +99 -0
- data/lib/metadata/VmConfig/test/GetVMwareCfgTest.rb +40 -0
- data/lib/metadata/VmConfig/vmcConfig.rb +116 -0
- data/lib/metadata/VmConfig/vmtxConfig.rb +4 -0
- data/lib/metadata/VmConfig/vmxConfig.rb +162 -0
- data/lib/metadata/VmConfig/xmlConfig.rb +79 -0
- data/lib/metadata/VmConfig/xmlMsHyperVConfig.rb +41 -0
- data/lib/metadata/linux/InitProcHash.rb +632 -0
- data/lib/metadata/linux/LinuxInitProcs.rb +142 -0
- data/lib/metadata/linux/LinuxOSInfo.rb +237 -0
- data/lib/metadata/linux/LinuxPackages.rb +209 -0
- data/lib/metadata/linux/LinuxSystemd.rb +130 -0
- data/lib/metadata/linux/LinuxUsers.rb +289 -0
- data/lib/metadata/linux/LinuxUtils.rb +197 -0
- data/lib/metadata/linux/MiqConaryPackages.rb +41 -0
- data/lib/metadata/linux/MiqRpmPackages.rb +160 -0
- data/lib/metadata/linux/test/Name +0 -0
- data/lib/metadata/linux/test/Packages +0 -0
- data/lib/metadata/linux/test/rpoTest.rb +5 -0
- data/lib/metadata/linux/test/tc_LinuxUtils.rb +4157 -0
- data/lib/metadata/util/event_log_filter.rb +61 -0
- data/lib/metadata/util/md5deep.rb +280 -0
- data/lib/metadata/util/win32/Win32Accounts.rb +764 -0
- data/lib/metadata/util/win32/Win32EventLog.rb +743 -0
- data/lib/metadata/util/win32/Win32Services.rb +86 -0
- data/lib/metadata/util/win32/Win32Software.rb +326 -0
- data/lib/metadata/util/win32/Win32System.rb +333 -0
- data/lib/metadata/util/win32/boot_info_win.rb +59 -0
- data/lib/metadata/util/win32/fleece_hives.rb +220 -0
- data/lib/metadata/util/win32/ms-registry.rb +650 -0
- data/lib/metadata/util/win32/peheader.rb +868 -0
- data/lib/metadata/util/win32/remote-registry.rb +142 -0
- data/lib/metadata/util/win32/system_path_win.rb +103 -0
- data/lib/metadata/util/win32/versioninfo.rb +17 -0
- data/manageiq-smartstate.gemspec +35 -0
- metadata +486 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
module EventLogFilter
|
2
|
+
def self.prepare_filter!(filter)
|
3
|
+
raise ArgumentError, "filter must be a Hash" unless filter.kind_of?(Hash)
|
4
|
+
|
5
|
+
filter[:rec_count] = 0 if filter[:rec_count].nil?
|
6
|
+
|
7
|
+
filter[:num_days] = 0 if filter[:num_days].nil?
|
8
|
+
filter[:generated] = (Time.now.utc - filter[:num_days] * 86400).iso8601 unless filter[:num_days] == 0
|
9
|
+
|
10
|
+
filter[:level] = filter[:level].to_s.strip.downcase
|
11
|
+
filter[:level] = filter[:level].empty? ? :warn : filter[:level].to_sym
|
12
|
+
filter[:level] = :warn unless [:error, :warn, :info].include?(filter[:level])
|
13
|
+
|
14
|
+
[:message, :source].each do |k|
|
15
|
+
filter[k].strip! unless filter[k].nil?
|
16
|
+
filter[k] = nil if filter[k] == ''
|
17
|
+
unless filter[k].nil?
|
18
|
+
first = filter[k][0, 1]
|
19
|
+
last = filter[k][-1, 1]
|
20
|
+
|
21
|
+
filter[k] = if first == '"' && last == '"'
|
22
|
+
# Double quotes surrounding provide exact match
|
23
|
+
Regexp.new("^\\s*#{Regexp.escape(filter[k][1..-2])}\\s*$", Regexp::IGNORECASE)
|
24
|
+
elsif first == '/' && last == '/'
|
25
|
+
# Forward slashes surrounding provide regex match
|
26
|
+
Regexp.new(filter[k][1..-2], Regexp::IGNORECASE)
|
27
|
+
else
|
28
|
+
# Neither surrouding provides substring match
|
29
|
+
Regexp.new(Regexp.escape(filter[k]), Regexp::IGNORECASE)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
filter
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.filter_by_level?(level, filter)
|
38
|
+
case filter[:level]
|
39
|
+
when :info then false
|
40
|
+
when :warn then !['warn', 'error'].include?(level.to_s)
|
41
|
+
when :error then 'error' != level.to_s
|
42
|
+
else false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.filter_by_generated?(generated, filter)
|
47
|
+
filter[:generated] && generated < filter[:generated]
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.filter_by_source?(source, filter)
|
51
|
+
filter[:source] && source !~ filter[:source]
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.filter_by_message?(message, filter)
|
55
|
+
filter[:message] && message !~ filter[:message]
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.filter_by_rec_count?(rec_count, filter)
|
59
|
+
filter[:rec_count] > 0 && rec_count >= filter[:rec_count]
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,280 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'metadata/util/win32/peheader'
|
3
|
+
require 'metadata/util/win32/versioninfo'
|
4
|
+
require 'util/miq-xml'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'util/miq-encode'
|
7
|
+
|
8
|
+
class MD5deep
|
9
|
+
attr_reader :fullDirCount, :fullFileCount
|
10
|
+
attr_accessor :versioninfo, :imports
|
11
|
+
|
12
|
+
def initialize(fs = nil, options = {})
|
13
|
+
@fullFileCount = 0
|
14
|
+
@fullDirCount = 0
|
15
|
+
# Create XML document
|
16
|
+
@xml = XmlHash.createDoc(:filesystem)
|
17
|
+
@fs = fs.kind_of?(MiqFS) ? fs : nil
|
18
|
+
|
19
|
+
# Read optional parameters if they exist in the options hash
|
20
|
+
@opts = {'versioninfo' => true, 'imports' => true, 'contents' => false,
|
21
|
+
'exclude' => ["pagefile.sys", "hiberfil.sys", ".", ".."],
|
22
|
+
'digest' => ["md5"], "winVerList" => %w(.exe .dll .ocx .scr)
|
23
|
+
}.merge(options)
|
24
|
+
# Make sure md5 is part of our digest array
|
25
|
+
@opts['digest'].push("md5") unless @opts['digest'].include?("md5")
|
26
|
+
# Convert hash to an OpenStruct for cleaner referencing
|
27
|
+
@opts = OpenStruct.new(@opts)
|
28
|
+
|
29
|
+
# Conditionally load digest libraries as needed.
|
30
|
+
@opts.digest.each do |h|
|
31
|
+
begin
|
32
|
+
require 'digest/' + h.downcase
|
33
|
+
rescue LoadError
|
34
|
+
# This load error is not a concern since the standard digests are already included
|
35
|
+
# in ruby by default, and the non-standard ones will be loaded by their name above.
|
36
|
+
# $log.debug "Unable to load module for [#{h}]"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def scan(path, rootID = "/")
|
42
|
+
path = File.expand_path(path)
|
43
|
+
rootID = rootID[2..-1] if rootID.length > 2 && rootID[1..1] == ":"
|
44
|
+
xmlNode = @xml.root.add_element("dir", "name" => rootID)
|
45
|
+
read_fs(path, xmlNode)
|
46
|
+
@xml
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.scan_glob(fs, filename, options = {})
|
50
|
+
md5 = MD5deep.new(fs, options)
|
51
|
+
md5.scan_glob(filename)
|
52
|
+
end
|
53
|
+
|
54
|
+
def scan_glob(filename)
|
55
|
+
filename.tr!("\\", "/")
|
56
|
+
startDir = File.dirname(filename)
|
57
|
+
globPattern = File.basename(filename)
|
58
|
+
@xml.root.add_attribute("base_path", startDir)
|
59
|
+
@fs.chdir(startDir)
|
60
|
+
|
61
|
+
# First check if we are passed a fully qualifed file name
|
62
|
+
if @fs.fileExists?(filename)
|
63
|
+
processFile(startDir, globPattern, @xml.root)
|
64
|
+
else
|
65
|
+
# If the file is not found then process the data as a glob pattern.
|
66
|
+
@fs.dirGlob(globPattern) do |f|
|
67
|
+
# $log.info "Glob file found: [#{f}]"
|
68
|
+
# Passing "startDir" as the first parameter is a work-around for issues
|
69
|
+
# when scanning Win VMs from Linux where the path returned from dirGlob
|
70
|
+
# do not include the drive letter.
|
71
|
+
# Below is the original line
|
72
|
+
# processFile(File.dirname(f), File.basename(f), @xml.root)
|
73
|
+
processFile(startDir, File.basename(f), @xml.root)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
@xml
|
77
|
+
end
|
78
|
+
|
79
|
+
def read_fs(path, xmlNode)
|
80
|
+
if @fs
|
81
|
+
@fs.dirForeach(path) { |x| processFile(path, x, xmlNode) }
|
82
|
+
@fs.dirForeach(path) { |x| processDir(path, x, xmlNode) }
|
83
|
+
else
|
84
|
+
Dir.foreach(path) { |x| processFile(path, x, xmlNode) }
|
85
|
+
Dir.foreach(path) { |x| processDir(path, x, xmlNode) }
|
86
|
+
end
|
87
|
+
|
88
|
+
# Add up all the sums for all sub-elements
|
89
|
+
xmlNode.add_attributes(calculate_sums(xmlNode))
|
90
|
+
end
|
91
|
+
|
92
|
+
def processDir(path, x, xmlNode)
|
93
|
+
if x != "." && x != ".."
|
94
|
+
currFile = File.join(path, x)
|
95
|
+
|
96
|
+
begin
|
97
|
+
if File.directory?(currFile)
|
98
|
+
@fullDirCount += 1
|
99
|
+
# $log.debug "DIR : #{currFile}"
|
100
|
+
xmlSubNode = xmlNode.add_element("dir", "name" => x, "fqname" => currFile)
|
101
|
+
xmlSubNode.add_attributes({"atime" => File.atime(currFile).getutc.iso8601, "ctime" => File.ctime(currFile).getutc.iso8601, "mtime" => File.mtime(currFile).getutc.iso8601})
|
102
|
+
read_fs(currFile, xmlSubNode)
|
103
|
+
end
|
104
|
+
rescue Errno::EACCES, RuntimeError
|
105
|
+
end
|
106
|
+
else
|
107
|
+
@fullDirCount += 1
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def processFile(path, x, xmlNode)
|
112
|
+
if (@opts.exclude.include?(x) == false) && x[0..0] != "$"
|
113
|
+
currFile = File.join(path, x)
|
114
|
+
|
115
|
+
begin
|
116
|
+
# unless File.directory?(currFile) then
|
117
|
+
unless isDir?(currFile)
|
118
|
+
# File we have an exclusion list and the current file is in it, skip to the next file
|
119
|
+
@fullFileCount += 1
|
120
|
+
fh = fileOpen(currFile)
|
121
|
+
|
122
|
+
xmlFileNode = xmlNode.add_element("file", "name" => x, "fqname" => currFile)
|
123
|
+
statHash = {}
|
124
|
+
statHash.merge!(getFileStats(fh))
|
125
|
+
statHash.merge!(calculate_digest(fh))
|
126
|
+
xmlFileNode.add_attributes(statHash)
|
127
|
+
|
128
|
+
ext = File.extname(currFile).downcase
|
129
|
+
if @opts.winVerList.include?(ext)
|
130
|
+
if @opts.versioninfo || @opts.imports
|
131
|
+
peHdr = PEheader.new(fh) rescue nil
|
132
|
+
unless peHdr.nil?
|
133
|
+
xmlFileNode.add_element("versioninfo", peHdr.versioninfo) if @opts.versioninfo && !peHdr.versioninfo.blank?
|
134
|
+
xmlFileNode.add_element("libraries", "imports" => peHdr.getImportList) if @opts.imports && !peHdr.imports.blank?
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
getFileContents(fh, xmlFileNode) if @opts.contents == true
|
140
|
+
fh.close
|
141
|
+
end
|
142
|
+
rescue Errno::EACCES, RuntimeError, SystemCallError
|
143
|
+
fh.close if fh.kind_of?(File) && !fh.closed?
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def isDir?(currFile)
|
149
|
+
if @fs
|
150
|
+
@fs.fileDirectory?(currFile)
|
151
|
+
else
|
152
|
+
File.directory?(currFile)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def fileOpen(currFile)
|
157
|
+
if @fs
|
158
|
+
fh = @fs.fileOpen(currFile)
|
159
|
+
else
|
160
|
+
fh = File.open(currFile)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def getFileStats(fh)
|
165
|
+
# If we are processing a member of the File class, use the File::Stat object to get data
|
166
|
+
fh = fh.stat if fh.class == File
|
167
|
+
{"size" => fh.size, "atime" => fh.atime.getutc.iso8601, "ctime" => fh.ctime.getutc.iso8601, "mtime" => fh.mtime.getutc.iso8601}
|
168
|
+
end
|
169
|
+
|
170
|
+
def calculate_sums(xmlNode)
|
171
|
+
rollup = create_digest_hash
|
172
|
+
# Add size to the hash as a Fixnum
|
173
|
+
rollup['size'] = 0
|
174
|
+
|
175
|
+
xmlNode.each_element do |e|
|
176
|
+
rollup.each_pair do |k, _v|
|
177
|
+
if k == "size"
|
178
|
+
rollup[k] += e.attributes[k].to_i if e.attributes[k]
|
179
|
+
else
|
180
|
+
rollup[k] << e.attributes[k] if e.attributes[k]
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
rollup.each { |k, v| rollup[k] = v.to_s unless k == 'size' }
|
186
|
+
rollup
|
187
|
+
end
|
188
|
+
|
189
|
+
def calculate_digest(fileName)
|
190
|
+
unless @opts.digest.empty?
|
191
|
+
# if fileName.class.to_s != "MiqFile"
|
192
|
+
# raise "File [#{fileName}] is not in a readable state." unless File.readable?(fileName)
|
193
|
+
# end
|
194
|
+
|
195
|
+
# Create hash for requested digests
|
196
|
+
digest = create_digest_hash
|
197
|
+
|
198
|
+
fileName.seek(0, IO::SEEK_SET)
|
199
|
+
# Loop over each digest and add the file contents
|
200
|
+
while buf = fileName.read(10240000)
|
201
|
+
digest.each_pair { |_k, v| v << buf }
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
digest.each_pair { |k, v| digest[k] = v.to_s }
|
206
|
+
digest
|
207
|
+
end
|
208
|
+
|
209
|
+
def create_digest_hash
|
210
|
+
dHash = {}
|
211
|
+
@opts.digest.each do |h|
|
212
|
+
begin
|
213
|
+
dHash[h.downcase] = Digest.const_get(h.upcase).new
|
214
|
+
rescue NameError
|
215
|
+
# If we are unable to load a digest, skip it.
|
216
|
+
end
|
217
|
+
end
|
218
|
+
dHash
|
219
|
+
end
|
220
|
+
|
221
|
+
def getFileContents(fh, xml_node)
|
222
|
+
fh.seek(0, IO::SEEK_SET)
|
223
|
+
buf = fh.read(1024000) || "" # read will return nil when at EOF.
|
224
|
+
xml_node.add_element("contents", "compressed" => "true", "encoded" => "true").text = (MIQEncode.encode(buf))
|
225
|
+
end
|
226
|
+
|
227
|
+
def to_xml
|
228
|
+
@xml
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# Only run if we are calling this script directly
|
233
|
+
if __FILE__ == $0
|
234
|
+
# if 1
|
235
|
+
require 'MiqVm/MiqVm'
|
236
|
+
require 'util/miq-logger'
|
237
|
+
|
238
|
+
$log = MIQLogger.get_log(nil, __FILE__)
|
239
|
+
$log.level = Log4r::INFO
|
240
|
+
|
241
|
+
startTime = Time.now
|
242
|
+
|
243
|
+
# Mount VM Image to a real drive letter
|
244
|
+
# mountNative, startPath = false, "M:/WINDOWS/system32/mui"
|
245
|
+
vmHDImage = "D:\\Virtual Machines\\VC20\\Windows Server 2003 Standard Edition.vmx"
|
246
|
+
|
247
|
+
begin
|
248
|
+
@vm = MiqVm.new(vmHDImage, nil)
|
249
|
+
|
250
|
+
@systemFs = @vm.rootTrees[0]
|
251
|
+
if @systemFs
|
252
|
+
# Note: SHA22 is not valid. It is here for testing of bad parms
|
253
|
+
# md5 = MD5deep.new(@systemFs, {"digest"=>%w(SHA1)}) #, %w(MD5 RMD160 SHA1 SHA256 SHA384 SHA512 SHA22))
|
254
|
+
md5 = MD5deep.new(@systemFs) # , %w(MD5 RMD160 SHA1 SHA256 SHA384 SHA512 SHA22))
|
255
|
+
# xml = md5.scan("C:/Program Files/VMware/VMware VirtualCenter 2.0")
|
256
|
+
xml = md5.scan_glob("c:/windows/system32/*.sc?")
|
257
|
+
# xml = md5.scan_glob("C:/Program Files/vmware/VMware VirtualCenter 2.0/vmprep.exe")
|
258
|
+
|
259
|
+
$log.info "writing XML..."
|
260
|
+
xml.write(STDOUT, 0)
|
261
|
+
puts ""
|
262
|
+
File.open("d:/temp/md5out.xml", "w") { |f| xml.write(f, 0); f.close }
|
263
|
+
stopTime = Time.now
|
264
|
+
end
|
265
|
+
|
266
|
+
$log.info startTime
|
267
|
+
$log.info stopTime
|
268
|
+
$log.info "Run time : #{(stopTime - startTime).to_i}"
|
269
|
+
$log.info "File count: #{md5.fullFileCount}"
|
270
|
+
$log.info "Dir count: #{md5.fullDirCount}"
|
271
|
+
rescue NameError => err
|
272
|
+
unless err.to_s.include?("MiqVm")
|
273
|
+
$log.warn err
|
274
|
+
$log.fatal err.backtrace.join("\n")
|
275
|
+
end
|
276
|
+
rescue => err
|
277
|
+
$log.fatal err
|
278
|
+
$log.fatal err.backtrace.join("\n")
|
279
|
+
end
|
280
|
+
end
|