| 1 | #!/usr/bin/perl -w
|
|---|
| 2 | #
|
|---|
| 3 | # Subroutines brought by the MondoRescue project to do HW/FW/SW inventory
|
|---|
| 4 | #
|
|---|
| 5 | # $Id$
|
|---|
| 6 | #
|
|---|
| 7 | # Copyright B. Cornec 2008
|
|---|
| 8 | # Provided under the GPL v2
|
|---|
| 9 |
|
|---|
| 10 | package MondoRescue::Inventory;
|
|---|
| 11 |
|
|---|
| 12 | use strict 'vars';
|
|---|
| 13 | use Data::Dumper;
|
|---|
| 14 | use English;
|
|---|
| 15 | use File::Basename;
|
|---|
| 16 | use File::Copy;
|
|---|
| 17 | use POSIX qw(strftime);
|
|---|
| 18 | use lib qw (lib);
|
|---|
| 19 | use ProjectBuilder::Base;
|
|---|
| 20 | use ProjectBuilder::Conf;
|
|---|
| 21 | use ProjectBuilder::Distribution;
|
|---|
| 22 | use MondoRescue::LVM;
|
|---|
| 23 |
|
|---|
| 24 | # Inherit from the "Exporter" module which handles exporting functions.
|
|---|
| 25 |
|
|---|
| 26 | use Exporter;
|
|---|
| 27 |
|
|---|
| 28 | # Export, by default, all the functions into the namespace of
|
|---|
| 29 | # any code which uses this module.
|
|---|
| 30 |
|
|---|
| 31 | our @ISA = qw(Exporter);
|
|---|
| 32 | our @EXPORT = qw(mr_inv_os $mr_os);
|
|---|
| 33 |
|
|---|
| 34 | # Globals
|
|---|
| 35 | our %mr_hw;
|
|---|
| 36 | our $mr_hw = \%mr_hw;
|
|---|
| 37 | our %mr_os;
|
|---|
| 38 | our $mr_os = \%mr_hw;
|
|---|
| 39 |
|
|---|
| 40 | =pod
|
|---|
| 41 |
|
|---|
| 42 | =head1 NAME
|
|---|
| 43 |
|
|---|
| 44 | MondoRescue::Inventory, part of the mondorescue.org
|
|---|
| 45 |
|
|---|
| 46 | =head1 DESCRIPTION
|
|---|
| 47 |
|
|---|
| 48 | This modules provides inventory functions for the Mondorescue project in order to report
|
|---|
| 49 | the precise context of the system to be archived (Hardware, Firmware and Software as much as possible)
|
|---|
| 50 | This module aims to be OS independent
|
|---|
| 51 |
|
|---|
| 52 | =head1 USAGE
|
|---|
| 53 |
|
|---|
| 54 | =over 4
|
|---|
| 55 |
|
|---|
| 56 | =item B<mr_inv_hw>
|
|---|
| 57 |
|
|---|
| 58 | This function reports Hardware inventory of the system to archive
|
|---|
| 59 |
|
|---|
| 60 | =cut
|
|---|
| 61 |
|
|---|
| 62 | sub mr_inv_hw {
|
|---|
| 63 |
|
|---|
| 64 | # Keyboard
|
|---|
| 65 | # Raid SW - DM
|
|---|
| 66 | # Partitions
|
|---|
| 67 | # FS/swaps
|
|---|
| 68 | # LVM / ...
|
|---|
| 69 | # PCI / USB / lssd / ...
|
|---|
| 70 | # messages/dmesg
|
|---|
| 71 | # Kernel / Initrd
|
|---|
| 72 | # Kernel Modules
|
|---|
| 73 | # cmdline
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | sub mr_inv_os {
|
|---|
| 77 |
|
|---|
| 78 | ($mr_os->{'name'}, $mr_os->{'version'}, $mr_os->{'family'}, $mr_os->{'type'}, $mr_os->{'os'}, $mr_os->{'suffix'}, $mr_os->{'update'}, $mr_os->{'arch'}) = pb_distro_init();
|
|---|
| 79 |
|
|---|
| 80 | # Get some conf file content when they exist; Depends on genre or more precise tuple
|
|---|
| 81 | for my $p ("mr_proc_cmdline","mr_etc_fstab","mr_etc_raidtab","mr_proc_swaps","mr_proc_partitions","mr_proc_filesystems","mr_proc_modules","mr_proc_xen","mr_proc_cpuinfo","mr_proc_devices","mr_proc_meminfo","mr_proc_misc","mr_proc_mounts","mr_proc_version") {
|
|---|
| 82 | my $key = $p;
|
|---|
| 83 | $key =~ s/mr_//;
|
|---|
| 84 | my ($pp) = pb_conf_get_if($p);
|
|---|
| 85 | if (defined $pp) {
|
|---|
| 86 | my $file = pb_distro_get_param($mr_os->{'name'},$mr_os->{'version'},$mr_os->{'arch'},$pp,$mr_os->{'family'},$mr_os->{'type'},$mr_os->{'os'});
|
|---|
| 87 | if (-r $file) {
|
|---|
| 88 | pb_log(2,"DEBUG: File found: $file\n");
|
|---|
| 89 | $mr_os->{'files'}->{$key} = pb_get_content($file);
|
|---|
| 90 | } else {
|
|---|
| 91 | pb_log(1,"WARNING: $file not found\n");
|
|---|
| 92 | }
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | # Get some commands result content when they exist; Depends on genre or more precise tuple
|
|---|
| 97 | for my $p ("mr_cmd_mount","mr_cmd_df","mr_cmd_dmidecode","mr_cmd_lshw") {
|
|---|
| 98 | my $key = $p;
|
|---|
| 99 | $key =~ s/mr_cmd_//;
|
|---|
| 100 | my ($pp) = pb_conf_get_if($p);
|
|---|
| 101 | my ($po) = pb_conf_get_if("mr_opt_".$key);
|
|---|
| 102 | if (defined $pp) {
|
|---|
| 103 | my $cmd = pb_distro_get_param($mr_os->{'name'},$mr_os->{'version'},$mr_os->{'arch'},$pp,$mr_os->{'family'},$mr_os->{'type'},$mr_os->{'os'});
|
|---|
| 104 | my $opt = "";
|
|---|
| 105 | $opt = pb_distro_get_param($mr_os->{'name'},$mr_os->{'version'},$mr_os->{'arch'},$po,$mr_os->{'family'},$mr_os->{'type'},$mr_os->{'os'}) if (defined ($po));
|
|---|
| 106 | if (-x $cmd) {
|
|---|
| 107 | pb_log(2,"DEBUG: Cmd found: $cmd $opt\n");
|
|---|
| 108 | $mr_os->{'cmd'}->{$key} = `$cmd $opt`;
|
|---|
| 109 | } else {
|
|---|
| 110 | pb_log(1,"WARNING: $cmd not found\n");
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 | }
|
|---|
| 114 | #
|
|---|
| 115 | # LVM setup
|
|---|
| 116 | #
|
|---|
| 117 | ($mr_os->{'lvmver'},$mr_os->{'lvmcmd'}) = mr_lvm_check();
|
|---|
| 118 |
|
|---|
| 119 | # Summary of conf printed.
|
|---|
| 120 | pb_log(1,"OS Inventory: ".Dumper($mr_os)."\n");
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | =item B<mr_inv_fw>
|
|---|
| 124 |
|
|---|
| 125 | This function reports Firmware inventory of the system to archive
|
|---|
| 126 |
|
|---|
| 127 | =cut
|
|---|
| 128 |
|
|---|
| 129 | sub mr_inv_fw {
|
|---|
| 130 |
|
|---|
| 131 | # Linked to bkphw
|
|---|
| 132 | # On Proliant use hpacucli, conrep, hponcfg
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | =item B<mr_inv_sw>
|
|---|
| 136 |
|
|---|
| 137 | This function reports Software inventory of the system to archive
|
|---|
| 138 |
|
|---|
| 139 | =cut
|
|---|
| 140 |
|
|---|
| 141 | sub mr_inv_sw {
|
|---|
| 142 |
|
|---|
| 143 | # Commands presence - use FindBin
|
|---|
| 144 | # deplist
|
|---|
| 145 | # mountlist
|
|---|
| 146 | }
|
|---|