[2467] | 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;
|
---|
[2667] | 21 | use ProjectBuilder::Distribution;
|
---|
| 22 | use MondoRescue::LVM;
|
---|
| 23 | use MondoRescue::Kernel;
|
---|
[2467] | 24 |
|
---|
| 25 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
| 26 |
|
---|
| 27 | use Exporter;
|
---|
| 28 |
|
---|
| 29 | # Export, by default, all the functions into the namespace of
|
---|
| 30 | # any code which uses this module.
|
---|
| 31 |
|
---|
| 32 | our @ISA = qw(Exporter);
|
---|
[2667] | 33 | our @EXPORT = qw(mr_inv_os $mr_os);
|
---|
[2467] | 34 |
|
---|
[2667] | 35 | # Globals
|
---|
| 36 | our %mr_hw;
|
---|
| 37 | our $mr_hw = \%mr_hw;
|
---|
| 38 | our %mr_os;
|
---|
| 39 | our $mr_os = \%mr_hw;
|
---|
| 40 |
|
---|
[2467] | 41 | =pod
|
---|
| 42 |
|
---|
| 43 | =head1 NAME
|
---|
| 44 |
|
---|
| 45 | MondoRescue::Inventory, part of the mondorescue.org
|
---|
| 46 |
|
---|
| 47 | =head1 DESCRIPTION
|
---|
| 48 |
|
---|
| 49 | This modules provides inventory functions for the Mondorescue project in order to report
|
---|
| 50 | the precise context of the system to be archived (Hardware, Firmware and Software as much as possible)
|
---|
| 51 | This module aims to be OS independent
|
---|
| 52 |
|
---|
| 53 | =head1 USAGE
|
---|
| 54 |
|
---|
| 55 | =over 4
|
---|
| 56 |
|
---|
| 57 | =item B<mr_inv_hw>
|
---|
| 58 |
|
---|
| 59 | This function reports Hardware inventory of the system to archive
|
---|
| 60 |
|
---|
| 61 | =cut
|
---|
| 62 |
|
---|
| 63 | sub mr_inv_hw {
|
---|
| 64 |
|
---|
| 65 | # Keyboard
|
---|
| 66 | # Raid SW - DM
|
---|
| 67 | # Partitions
|
---|
| 68 | # FS/swaps
|
---|
| 69 | # LVM / ...
|
---|
[2468] | 70 | # PCI / USB / lssd / ...
|
---|
[2467] | 71 | # messages/dmesg
|
---|
| 72 | # Kernel / Initrd
|
---|
| 73 | # Kernel Modules
|
---|
| 74 | # cmdline
|
---|
[2468] | 75 | }
|
---|
[2467] | 76 |
|
---|
[2667] | 77 | sub mr_inv_os {
|
---|
[2468] | 78 |
|
---|
[2667] | 79 | ($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();
|
---|
[2468] | 80 |
|
---|
[2667] | 81 | # Get some conf file content when they exist; Depends on genre or more precise tuple
|
---|
| 82 | for my $p ("mr_cmdline","mr_fstab","mr_raidtab","mr_swap","mr_partitions","mr_filesystems","mr_modules","mr_xen") {
|
---|
| 83 | my $key = $p;
|
---|
| 84 | $key =~ s/mr_//;
|
---|
| 85 | my ($pp) = pb_conf_get_if($p);
|
---|
| 86 | if (defined $pp) {
|
---|
| 87 | 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'});
|
---|
| 88 | if (-r $file) {
|
---|
| 89 | pb_log(2,"DEBUG: File found: $file\n");
|
---|
| 90 | $mr_os->{'files'}->{$key} = pb_get_content($file);
|
---|
| 91 | } else {
|
---|
| 92 | pb_log(2,"WARNING: $file not found\n");
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
[2467] | 95 | }
|
---|
[2667] | 96 |
|
---|
| 97 | # Get some commands result content when they exist; Depends on genre or more precise tuple
|
---|
| 98 | for my $p ("mr_mount","mr_lsmod","mr_df") {
|
---|
| 99 | my $key = $p;
|
---|
| 100 | $key =~ s/mr_//;
|
---|
| 101 | my ($pp) = pb_conf_get_if($p);
|
---|
| 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 | pb_log(2,"DEBUG: Cmd found: $cmd\n");
|
---|
| 105 | $mr_os->{'cmd'}->{$key} = `$cmd`;
|
---|
| 106 | }
|
---|
[2468] | 107 | }
|
---|
[2667] | 108 | #
|
---|
| 109 | # LVM setup
|
---|
| 110 | #
|
---|
| 111 | ($mr_os->{'lvmver'},$mr_os->{'$lvmcmd'}) = mr_lvm_check();
|
---|
[2467] | 112 |
|
---|
[2667] | 113 | # Summary of conf printed.
|
---|
| 114 | pb_log(1,"OS Inventory: ".Dumper($mr_os)."\n");
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[2467] | 117 | =item B<mr_inv_fw>
|
---|
| 118 |
|
---|
| 119 | This function reports Firmware inventory of the system to archive
|
---|
| 120 |
|
---|
| 121 | =cut
|
---|
| 122 |
|
---|
| 123 | sub mr_inv_fw {
|
---|
| 124 |
|
---|
| 125 | # Linked to bkphw
|
---|
| 126 | # On Proliant use hpacucli, conrep, hponcfg
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | =item B<mr_inv_sw>
|
---|
| 130 |
|
---|
| 131 | This function reports Software inventory of the system to archive
|
---|
| 132 |
|
---|
| 133 | =cut
|
---|
| 134 |
|
---|
| 135 | sub mr_inv_sw {
|
---|
| 136 |
|
---|
| 137 | # Commands presence - use FindBin
|
---|
| 138 | # deplist
|
---|
| 139 | # mountlist
|
---|
| 140 | }
|
---|