<commit_before>require 'boris/profiler'
require 'boris/profilers/unix_core'
require 'boris/helpers/constants'

module Boris; module Profilers
  class Solaris < UNIX
    
    SOLARIS_ZONE_MODEL = 'Oracle Virtual Platform'
    
    def self.matches_target?(connector)
      return true if connector.value_at('uname') =~ /sunos/i
    end

    def get_hardware
      super

      detect_platform if !@platform
      detect_zone if !@zone

      if @zone == :child
        @hardware[:vendor] = VENDOR_ORACLE
        @hardware[:model] = SOLARIS_ZONE_MODEL
      elsif @platform == :sparc
        @hardware[:vendor] = VENDOR_ORACLE

        @hardware[:firmware_version] = @connector.value_at(%q{/usr/platform/`uname -m`/sbin/prtdiag -v | egrep -i "^obp" | awk '{print $2}'})
        model_data = @connector.value_at('/usr/sbin/prtconf -b | grep banner-name')
        @hardware[:model] = model_data.after_colon
      else
        @hardware[:firmware_version] = @connector.value_at('/usr/sbin/smbios -t SMB_TYPE_BIOS | grep -i "version string"').after_colon
        model_data = @connector.values_at("/usr/sbin/smbios -t SMB_TYPE_SYSTEM | egrep -i 'manufacturer|product|serial'")
        @hardware[:vendor] = model_data.grep(/manufacturer/i)[0].after_colon
        @hardware[:model] = model_data.grep(/product/i)[0].after_colon
        @hardware[:serial] = model_data.grep(/serial number/i)[0].after_colon
      end

      memory_data = @connector.value_at("/usr/sbin/prtconf | egrep -i 'memory size' | awk '{print $3}'")
      @hardware[:memory_installed_mb] = memory_data.to_i

      cpu_arch_data = @connector.values_at("isainfo -v | egrep -i applications | awk '{print $1}'")
      @hardware[:cpu_architecture] = cpu_arch_data.include?('64-bit') ? 64 : 32

      cpu_data = @connector.values_at(%q{kstat -m cpu_info | nawk '{if(tolower($1)~/^(chip_id|core_id|clock_mhz|vendor_id|brand)/) {sub($1, $1"|"); print $0}}'})

      @hardware[:cpu_physical_count] = cpu_data.grep(/chip_id/i).uniq.size
      @hardware[:cpu_core_count] = cpu_data.grep(/core_id/i).uniq.size / @hardware[:cpu_physical_count]
      @hardware[:cpu_model] = cpu_data.grep(/brand/i)[0].after_pipe
      @hardware[:cpu_speed_mhz] = cpu_data.grep(/clock_mhz/i)[0].after_pipe.to_i

      @hardware[:cpu_vendor] = if @platform == :sparc
        VENDOR_ORACLE
      else
        cpu_data.grep(/vendor_id/i)[0].after_pipe
      end

      @hardware
    end

    def get_hosted_shares
      super

      share_data = @connector.values_at(%q{nawk '{system("df -k | grep " $2)}' /usr/sbin/shares | nawk '{print $NF "|" $1}'})
      share_data.each do |share|
        h = hosted_share_template
        share = share.split('|')
        h[:name] = share[0]
        h[:path] = share[1]
        @hosted_shares << h
      end

      @hosted_shares
    end

    def get_installed_applications
      super

      application_data = @connector.values_at("pkginfo -il -c application | egrep -i '^$|(name|version|basedir|vendor|instdate):'")
      application_data.join("\n").split("\n\n").each do |application|

        application = application.split("\n")
        h = installed_application_template

        date_installed = application.grep(/instdate:/i)[0].split(/instdate:/i)[1].strip
        h[:date_installed] = DateTime.strptime(date_installed, '%b %d %Y %H:%M')
        h[:name] = application.grep(/name:/i)[0].after_colon
        h[:version] = application.grep(/version:/i)[0].after_colon

        # these sometimes don't show up
        install_location = application.grep(/basedir:/i)[0]
        h[:install_location] = install_location.after_colon if install_location
        vendor = application.grep(/vendor:/i)[0]
        h[:vendor] = vendor.after_colon if vendor

        @installed_applications << h
      end

      @installed_applications
    end

    def get_installed_patches
      super
<commit_msg>fixed bug on parsing applications w/o installdate<commit_after>require 'boris/profiler'
require 'boris/profilers/unix_core'
require 'boris/helpers/constants'

module Boris; module Profilers
  class Solaris < UNIX
    
    SOLARIS_ZONE_MODEL = 'Oracle Virtual Platform'
    
    def self.matches_target?(connector)
      return true if connector.value_at('uname') =~ /sunos/i
    end

    def get_hardware
      super

      detect_platform if !@platform
      detect_zone if !@zone

      if @zone == :child
        @hardware[:vendor] = VENDOR_ORACLE
        @hardware[:model] = SOLARIS_ZONE_MODEL
      elsif @platform == :sparc
        @hardware[:vendor] = VENDOR_ORACLE

        @hardware[:firmware_version] = @connector.value_at(%q{/usr/platform/`uname -m`/sbin/prtdiag -v | egrep -i "^obp" | awk '{print $2}'})
        model_data = @connector.value_at('/usr/sbin/prtconf -b | grep banner-name')
        @hardware[:model] = model_data.after_colon
      else
        @hardware[:firmware_version] = @connector.value_at('/usr/sbin/smbios -t SMB_TYPE_BIOS | grep -i "version string"').after_colon
        model_data = @connector.values_at("/usr/sbin/smbios -t SMB_TYPE_SYSTEM | egrep -i 'manufacturer|product|serial'")
        @hardware[:vendor] = model_data.grep(/manufacturer/i)[0].after_colon
        @hardware[:model] = model_data.grep(/product/i)[0].after_colon
        @hardware[:serial] = model_data.grep(/serial number/i)[0].after_colon
      end

      memory_data = @connector.value_at("/usr/sbin/prtconf | egrep -i 'memory size' | awk '{print $3}'")
      @hardware[:memory_installed_mb] = memory_data.to_i

      cpu_arch_data = @connector.values_at("isainfo -v | egrep -i applications | awk '{print $1}'")
      @hardware[:cpu_architecture] = cpu_arch_data.include?('64-bit') ? 64 : 32

      cpu_data = @connector.values_at(%q{kstat -m cpu_info | nawk '{if(tolower($1)~/^(chip_id|core_id|clock_mhz|vendor_id|brand)/) {sub($1, $1"|"); print $0}}'})

      @hardware[:cpu_physical_count] = cpu_data.grep(/chip_id/i).uniq.size
      @hardware[:cpu_core_count] = cpu_data.grep(/core_id/i).uniq.size / @hardware[:cpu_physical_count]
      @hardware[:cpu_model] = cpu_data.grep(/brand/i)[0].after_pipe
      @hardware[:cpu_speed_mhz] = cpu_data.grep(/clock_mhz/i)[0].after_pipe.to_i

      @hardware[:cpu_vendor] = if @platform == :sparc
        VENDOR_ORACLE
      else
        cpu_data.grep(/vendor_id/i)[0].after_pipe
      end

      @hardware
    end

    def get_hosted_shares
      super

      share_data = @connector.values_at(%q{nawk '{system("df -k | grep " $2)}' /usr/sbin/shares | nawk '{print $NF "|" $1}'})
      share_data.each do |share|
        h = hosted_share_template
        share = share.split('|')
        h[:name] = share[0]
        h[:path] = share[1]
        @hosted_shares << h
      end

      @hosted_shares
    end

    def get_installed_applications
      super

      application_data = @connector.values_at("pkginfo -il -c application | egrep -i '^$|(name|version|basedir|vendor|instdate):'")
      application_data.join("\n").split(/\n\n/).each do |application|
        application = application.split(/\n/)
        h = installed_application_template

        h[:name] = application.grep(/name:/i)[0].after_colon
        h[:version] = application.grep(/version:/i)[0].after_colon

        # these items sometimes don't show up
        date_installed = application.grep(/instdate:/i)[0]
        h[:date_installed] = DateTime.strptime(date_installed.split(/instdate:/i)[1].strip, '%b %d %Y %H:%M') if date_installed
        install_location = application.grep(/basedir:/i)[0]
        h[:install_location] = install_location.after_colon if install_location
        vendor = application.grep(/vendor:/i)[0]
        h[:vendor] = vendor.after_colon if vendor

        @installed_applications << h
      end

      @installed_applications
    end

    def get_installed_patches
      super

{'fraction_non_alphanumeric': 0.1430771204927499, 'fraction_numerical': 0.007442576671371744, 'mean_word_length': 3.1723768736616704, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '347491', 'n_tokens_mistral': 2790, 'n_tokens_neox': 2670, 'n_words': 459}