package FusionInventory::Agent::Task::Inventory::OS::Solaris::CPU;

use strict;

sub isInventoryEnabled {
        my $params = shift;
        my $logger = $params->{logger};

        if (!can_run ("kstat")) {
                $logger->debug('kstat not found in $PATH');
                return;
        }

        1;
}

sub doInventory {
        my $params = shift;
        my $inventory = $params->{inventory};

        my %cpus;
        foreach(`kstat -p cpu_info:::brand cpu_info:::clock_MHz`) {
                /^[^:]*:([^:]*):[^:]*:([^\s]*)\s*(.*)$/;
                %cpus->{$1}->{$2} = $3;
        }

		# Because of compatability reasons with the current OCS-Reports-Interface
		# there is no distinction between CORES and SOCKETS. Instead every CORE is
		# counted as a SOCKET with one CORE.
		# Presuming a SOCKET-aware OCS-Reports-Interface, it is possible to detect
		# the SOCKET/CORE relationship by parsing the kstat-variable "chip_id"

        foreach(values %cpus) {
                $inventory->addCPU({
                        NAME => $_->{brand},
                        CORE => 1,
                        SPEED => $_->{clock_MHz}
                });
        }
}
1;