[3219] | 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-2014
|
---|
| 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 uname);
|
---|
| 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->{'pbos'} = pb_distro_init();
|
---|
| 79 |
|
---|
| 80 | pb_log(2,"OS Inventory: pbos ".Dumper($mr_os)."\n");
|
---|
| 81 |
|
---|
| 82 | # Get some running kernel info
|
---|
| 83 | ($mr_os->{'uname'}->{'sysname'}, $mr_os->{'uname'}->{'nodename'}, $mr_os->{'uname'}->{'release'}, $mr_os->{'uname'}->{'version'}, $mr_os->{'uname'}->{'machine'}) = uname();
|
---|
| 84 |
|
---|
| 85 | pb_log(2,"OS Inventory: uname ".Dumper($mr_os)."\n");
|
---|
| 86 |
|
---|
| 87 | # Get some conf file content when they exist; Depends on genre or more precise tuple
|
---|
| 88 | 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") {
|
---|
| 89 | my $key = $p;
|
---|
| 90 | $key =~ s/mr_//;
|
---|
| 91 | my ($pp) = pb_conf_get_if($p);
|
---|
| 92 | if (defined $pp) {
|
---|
| 93 | my $file = pb_distro_get_param($mr_os->{'pbos'},$pp);
|
---|
| 94 | if (-r $file) {
|
---|
| 95 | pb_log(2,"DEBUG: File found: $file\n");
|
---|
| 96 | $mr_os->{'files'}->{$key} = pb_get_content($file);
|
---|
| 97 | } else {
|
---|
| 98 | pb_log(1,"WARNING: $file not found\n");
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | pb_log(2,"OS Inventory: files ".Dumper($mr_os)."\n");
|
---|
| 104 |
|
---|
| 105 | return;
|
---|
| 106 | # Get some commands result content when they exist; Depends on genre or more precise tuple
|
---|
| 107 | for my $p ("mr_cmd_mount","mr_cmd_df","mr_cmd_dmidecode","mr_cmd_lshw") {
|
---|
| 108 | my $key = $p;
|
---|
| 109 | $key =~ s/mr_cmd_//;
|
---|
| 110 | my ($pp) = pb_conf_get_if($p);
|
---|
| 111 | my ($po) = pb_conf_get_if("mr_opt_".$key);
|
---|
| 112 | if (defined $pp) {
|
---|
| 113 | my $cmd = pb_distro_get_param($mr_os->{'pbos'},$pp);
|
---|
| 114 | my $opt = "";
|
---|
| 115 | $opt = pb_distro_get_param($mr_os->{'pbos'},$po) if (defined ($po));
|
---|
| 116 | if (-x $cmd) {
|
---|
| 117 | pb_log(2,"DEBUG: Cmd found: $cmd $opt\n");
|
---|
| 118 | $mr_os->{'cmd'}->{$key} = `$cmd $opt`;
|
---|
| 119 | } else {
|
---|
| 120 | pb_log(1,"WARNING: $cmd not found\n");
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | pb_log(2,"OS Inventory: cmds ".Dumper($mr_os)."\n");
|
---|
| 126 | #
|
---|
| 127 | # LVM setup
|
---|
| 128 | #
|
---|
| 129 | ($mr_os->{'lvmver'},$mr_os->{'lvmcmd'}) = mr_lvm_check();
|
---|
| 130 |
|
---|
| 131 | # Summary of conf printed.
|
---|
| 132 | pb_log(1,"OS Inventory: ".Dumper($mr_os)."\n");
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | =item B<mr_inv_fw>
|
---|
| 136 |
|
---|
| 137 | This function reports Firmware inventory of the system to archive
|
---|
| 138 |
|
---|
| 139 | =cut
|
---|
| 140 |
|
---|
| 141 | sub mr_inv_fw {
|
---|
| 142 |
|
---|
| 143 | # Linked to bkphw
|
---|
| 144 | # On Proliant use hpacucli, conrep, hponcfg
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | =item B<mr_inv_sw>
|
---|
| 148 |
|
---|
| 149 | This function reports Software inventory of the system to archive
|
---|
| 150 |
|
---|
| 151 | =cut
|
---|
| 152 |
|
---|
| 153 | sub mr_inv_sw {
|
---|
| 154 |
|
---|
| 155 | # Commands presence - use FindBin
|
---|
| 156 | # deplist
|
---|
| 157 | # mountlist
|
---|
| 158 | }
|
---|