File Coverage

blib/lib/FusionInventory/Agent/Task/Inventory/Generic/Ipmi.pm
Criterion Covered Total %
statement 12 32 37.5
branch 0 20 0.0
condition n/a
subroutine 4 6 66.6
pod 0 2 0.0
total 16 60 26.6


line stmt bran cond sub pod time code
1             #
2             # OcsInventory agent - IPMI lan channel report
3             #
4             # Copyright (c) 2008 Jean Parpaillon
5             #
6             # The Intelligent Platform Management Interface (IPMI) specification
7             # defines a set of common interfaces to a computer system which system
8             # administrators can use to monitor system health and manage the
9             # system. The IPMI consists of a main controller called the Baseboard
10             # Management Controller (BMC) and other satellite controllers.
11             #
12             # The BMC can be fetched through client like OpenIPMI drivers or
13             # through the network. Though, the BMC hold a proper MAC address.
14             #
15             # This module reports the MAC address and, if any, the IP
16             # configuration of the BMC. This is reported as a standard NIC.
17             #
18             package FusionInventory::Agent::Task::Inventory::Generic::Ipmi;
19              
20 1     1   106417440 use strict;
  1         9  
  1         47  
21 1     1   6 use warnings;
  1         2  
  1         65  
22              
23 1     1   373 use FusionInventory::Agent::Tools;
  1         2  
  1         130  
24 1     1   494 use FusionInventory::Agent::Tools::Network;
  1         2  
  1         328  
25              
26             sub isEnabled {
27 0 0   0 0   return unless canRun('ipmitool');
28             }
29              
30             sub doInventory {
31 0     0 0   my (%params) = @_;
32              
33 0           my $inventory = $params{inventory};
34 0           my $logger = $params{logger};
35              
36 0           my $handle = getFileHandle(
37             logger => $logger,
38             command => "ipmitool lan print",
39             );
40              
41 0 0         return unless $handle;
42              
43 0           my $interface = {
44             DESCRIPTION => 'bmc',
45             TYPE => 'ethernet',
46             MANAGEMENT => 1,
47             STATUS => 'Down',
48             };
49              
50 0           while (my $line = <$handle>) {
51 0 0         if ($line =~ /^IP Address\s+:\s+($ip_address_pattern)/) {
52 0 0         $interface->{IPADDRESS} = $1 unless $1 eq '0.0.0.0';
53             }
54 0 0         if ($line =~ /^Default Gateway IP\s+:\s+($ip_address_pattern)/) {
55 0 0         $interface->{IPGATEWAY} = $1 unless $1 eq '0.0.0.0';
56             }
57 0 0         if ($line =~ /^Subnet Mask\s+:\s+($ip_address_pattern)/) {
58 0 0         $interface->{IPMASK} = $1 unless $1 eq '0.0.0.0';
59             }
60 0 0         if ($line =~ /^MAC Address\s+:\s+($mac_address_pattern)/) {
61 0           $interface->{MACADDR} = $1;
62             }
63             }
64 0           close $handle;
65              
66             $interface->{IPSUBNET} = getSubnetAddress(
67             $interface->{IPADDRESS}, $interface->{IPMASK}
68 0           );
69              
70 0 0         $interface->{STATUS} = 'Up' if $interface->{IPADDRESS};
71              
72 0           $inventory->addEntry(
73             section => 'NETWORKS',
74             entry => $interface
75             );
76             }
77              
78             1;