Skip to content

Commit

Permalink
Collect Batteries information
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonéri Le Bouder committed May 30, 2010
1 parent 9a48c86 commit 048c1f9
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Revision history for FusionInventory::Agent
ProLiant servers) (Amir PAKDEL)
* HP-UX: HP Management Processor (MP) (Management Interface of HP
Integrity servers) (Amir PAKDEL)
* Collect Batteries information


2.0.6
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package FusionInventory::Agent::Task::Inventory::OS::Generic::Dmidecode::Battery;
use strict;

sub parseDate {
my $string = shift;


if ($string =~ /(\d{1,2})([\/-])(\d{1,2})([\/-])(\d{2})/) {
my $d = $1;
my $m = $3;
my $y = ($5>90?"19":"20").$5;

return "$1/$3/$y";
} elsif ($string =~ /(\d{4})([\/-])(\d{1,2})([\/-])(\d{1,2})/) {
my $y = ($5>90?"19":"20").$1;
my $d = $3;
my $m = $5;

return "$d/$m/$y";
}


}

sub doInventory {
my $params = shift;
my $inventory = $params->{inventory};

my $capacity;
my $voltage;
my $name;
my $serial;
my $date;
my $manufacturer;

# get the BIOS values
my $type;
for(`dmidecode`){
if (/dmi type (\d+),/i) {

if ($type == 22) {
$inventory->addBattery({
CAPACITY => $capacity,
DATE => $date,
NAME => $name,
SERIAL => $serial,
MANUFACTURER => $manufacturer,
VOLTAGE => $voltage
});
$capacity = $date = $name = undef;
$serial = $manufacturer = $voltage = undef;
}
$type = $1;
}


if ($type == 22) {

if(/Name:\s*(.+?)(\s*)$/i) {
$name = $1;
} elsif(/Capacity:\s*(\d+)\s*mWh/i) {
$capacity = $1;
} elsif(/Manufacturer:\s*(.+?)(\s*)$/i) {
$manufacturer = $1;
} elsif(/Serial\s*Number:\s*(.+?)(\s*)$/i) {
$serial = $1
} elsif(/Manufacture\s*date:\s*(\S*)$/i) {
$date = parseDate($1);
} elsif(/Voltage:\s*(\d+)\s*mV/i) {
$voltage = $1;
}
}

}
}
1;
61 changes: 61 additions & 0 deletions lib/FusionInventory/Agent/XML/Query/Inventory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ sub new {
$self->{h}{CONTENT}{ENVS} = [];
$self->{h}{CONTENT}{UPDATES} = [];
$self->{h}{CONTENT}{USBDEVICES} = [];
$self->{h}{CONTENT}{BATTERIES} = [];
$self->{h}{CONTENT}{VERSIONCLIENT} = ['FusionInventory-Agent_v'.$config->{VERSION}];

# Is the XML centent initialised?
Expand Down Expand Up @@ -939,6 +940,36 @@ sub addUSBDevice {
};
}

=item addBattery()
Battery
=cut
sub addBattery {
my ($self, $args) = @_;

my $capacity = $args->{ CAPACITY};
my $date = $args->{ DATE};
my $name = $args->{ NAME};
my $serial = $args->{ SERIAL};
my $manufacturer = $args->{ MANUFACTURER};
my $voltage = $args->{ VOLTAGE};

push @{$self->{h}{CONTENT}{BATTERIES}},
{

CAPACITY => [$capacity?$capacity:''],
DATE => [$date?$date:''],
NAME => [$name?$name:''],
SERIAL => [$serial?$serial:''],
MANUFACTURER => [$manufacturer?$manufacturer:''],
VOLTAGE => [$voltage?$voltage:'']


};
}



=item addRegistry()
Expand Down Expand Up @@ -1852,3 +1883,33 @@ Whether or not it is a HP iLO, Sun SC, HP MP or other kink of Remote Management
Interface speed in MB/s
=back
=head2 BATTERIES
=over 4
=item CAPACITY
Battery capacity in mWh
=item DATE
Manufacture date in the DD/MM/YYYY format
=item NAME
Name of the device
=item SERIAL
Serial number
=item MANUFACTURER
Battery manufacturer
=item VOLTAGE
Voltage in mV
=back

0 comments on commit 048c1f9

Please sign in to comment.