#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2005,2007 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)52   1.2   src/csm/install/invokeSFPEventSensor.perl, setup, csm_rfish, rfishs001b 1/30/06 22:02:58

use strict;
BEGIN { $::csmpm = $ENV{'CSM_PM'} ? $ENV{'CSM_PM'} : '/opt/csm/pm'; }
use lib $::csmpm;
use File::Path;

use Getopt::Std;
use NodeUtils;
use CSMDefs;
use MessageUtils;

$::MSGCAT     = 'csmInstall.cat';
$::MSGMAPPATH = $ENV{'CSM_MSGMAPS'} ? $ENV{'CSM_MSGMAPS'} : '/opt/csm/msgmaps';
$::MSGSET     = 'csminstall';

sub usage
{
print <<ENDOFUSAGETEXT;
Usage:  invokeSFPEventSensor [-h]
        invokeSFPEventSensor [-v | -V] -f <SFP_data_filename> 
ENDOFUSAGETEXT
exit 1;
}

#variables
my $dataFileName;
my $allData= "LSSVCEVENTS_ALL";
sub getArgs
{
    if (! getopts('hf:vV') ) { &usage; }
    if ($::opt_h) { &usage }

    $::VERBOSE = $::opt_v || $::opt_V ;

    # SFP data file name 
    if ($::opt_f)
    {
        $dataFileName = $::opt_f;
    }
}



sub readSFPData
{

    # open the SFP data file for reading the content into memeory
    unless (open(DATA_FILE, "< $dataFileName"))
    {
        MessageUtils->messageFromCat('csmInstall.cat', $::MSGMAPPATH, 'csminstall',
                                  'E2', 'EMsgCANT_READ_FILE', $dataFileName);
    }

    #common variables that needs to be used
    my $line;
                                             
    while ($line = <DATA_FILE>)
    {
        (grep(/^\s*#/, $line)) && next;    # Skip comment lines
         next if ($line =~ /^\s*$/);        # Next if empty blank line
         chomp $line;
         $allData = $allData . $line ;
     }
     close(DATA_FILE);

}


#main

&getArgs();

&readSFPData();
#print $allData;

#send the SFP data to the sensor 
NodeUtils->runcmd("/usr/bin/refsensor CSMServiceableEventSensor String=\'$allData\'");
exit 0;

