#!/usr/local/bin/perl
# 
# $Header: emagent/sysman/admin/scripts/hoststorageUtil.pl /st_emagent_10.2.0.4.3db11.2.0.2/1 2010/04/09 20:51:33 rajverma Exp $
#
# hoststorageUtil.pl
# 
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 
#
#    NAME
#      hoststorageUtil.pl - <one-line expansion of the name>
#
#    DESCRIPTION
#      <short description of component this file declares/defines>
#
#    NOTES
#      <other useful comments, qualifications, etc.>
#
#    MODIFIED   (MM/DD/YY)
#    rajverma    05/22/08 - Script to get the config parameters for hoststorage
#    rajverma    05/22/08 - Creation
# 

use storage::Utilities;

$ENV{PATH} = "/bin:/usr/bin:/usr/sbin:/usr/local/bin:/sbin:$ENV{EMDROOT}/bin";

 my $os_name = `uname -s`;
 chomp($os_name);
#Check if Os is supported or not
 @os_list =  storage::Utilities::getConfig("OS");
 my $hs_support = 0;
      foreach my $opsys (@os_list)
        {
          if (uc($opsys) eq uc($os_name))
            {
                $hs_support = 1 ;
             }
        }

 my $nmhs_perm = 1;
#Throw the error on 3rd day of the week.

# my $week_day = `date +%u` ;
#Default is wednesday ie. 3
#  my @err_day = ("3") ;
#   @err_day =  storage::Utilities::getConfig("Day")
#     if storage::Utilities::getConfig("Day") ;

# Check for the suid bit in the"nmhs" . If not set throw error and exit.
# my $nmhs_err = "error::snmhsutl.c:executable" ;
# my $dev = "/dev/hda";
# my $nmhs_cmd = "nmhs execute_scsi_inquiry ". $dev;
# my $nmhs_out = `$nmhs_cmd`;
# Check for error. If error return with proper message.
# if(($nmhs_out =~ m/^$nmhs_err/) && ($week_day == "@err_day"))
#  {
#        $nmhs_perm = 0;
#  }
# Check which of the entities (Disk, FS, Vol) has crossed the monitoring limit.

 my  @limit_list = storage::Utilities::getConfig("Limit");


   print "em_result=Operating System|$hs_support\n";

   foreach $line(@limit_list)
    {
       $line =~ s/_Limit=/|/;
     print "em_result=$line \n";
    }


# check if the config file is modified or not. 
# check if the default values of collection have changes.
# check if the disks/filesystems/volumes have entries , check count
# to check if file is changed or not. 0 - not changed , 1 - changed.
  my $file_chg = 0 ;
  my @disks = storage::Utilities::getConfig("Disks");
  my @files = storage::Utilities::getConfig("FileSystems");
  my @volumes = storage::Utilities::getConfig("Volumes");

  my @limits  = storage::Utilities::getConfig("Limit");
  my $limit_chg = 0 ; #to check if limit is changed or not.

    foreach $entity (@limits)
    {
       my($name, $value) = split(/=/, $entity) ;
       next unless $value eq "0" ;
	$limit_chg = 1 ;

    }


    #if limit has been changed and disks/fs/vol are entered then config file is changed. 
     if( ($limit_chg == 1) || ($#disks > 0) || ($#files > 0) || ($#volumes > 0) )
        { print "em_result=Config File|1\n";   }
      else
        { print "em_result=Config File|0\n";   }

