示例#1
0
 def __init__(self, appName, log):      
     
     if appName is None : self.appName = self.__class__.__name__.lower()
     else               : self.appName = appName
     
     if log is not None : 
         self.log = log          # Overwrite the default. 
         self.stdAlone = False
            
     else               : 
         self.log      = log4py.Logger().get_instance() 
         self.logFile  = getLogHandler(appName,self.log)
         self.stdAlone = True                     # Standalone invocations (notify)
         
     self.cwd    = None
     self.rpwd   = None        # Remote Working dir
     self.lpwd   = None        # Local Working  dir
     
     self.dirDetLst  = []      # Detailed File list
     self.dirLst     = []      # place holder for dir list (filename only)
     self.dirPathLst = []      # place holder for dir list
     self.txFiles    = []      # transfer files. List of SUCC transfered files. 
     
     self.cmdStep    = {}      # Empty for base class
     self.infaEnvVar = {}      # Empty for base class  
示例#2
0
def main(argv):
    
    if len(argv) > 1 :
        logFile = getLogHandler(argv[1])
        
    else:
        log.error( "USAGE : <%s> fx [args] Not enough arguments " % argv[0])
        sys.exit(1)
示例#3
0
 def main(self, Argv):
     rc = 1  # Failed
     logFile = getLogHandler(self.appName, self.log)
     self.log.info('logFile= %s' % logFile)
     
     # should NEVER get this programmatic error !!!!
     rc = self.setArgs(Argv)    
     if rc != 0 : return rc
     
     rc = self._getEnvVars()
     if rc != 0 :
         self.log.error("Need to set all env vars:\n %s" % self.infaEnvVar.keys())
         return rc
     
     sys.exit(rc)
示例#4
0
    def main(self, Argv):
        rc = 1  # Failed
        logFile = getLogHandler(self.appName, self.log, True)
        self.log.info('logFile= %s' % logFile)

        # should NEVER get this programmatic error !!!!
        if self.cmdStep is None or len(self.cmdStep) == 0:
            self.log.critical("Program Error:self.cmdStep is ", self.cmdStep)
            return 1

        rc = self.setArgs(Argv)
        if rc != 0: return rc

        rc = self._getEnvVars()
        if rc != 0: return rc

        rc = self._getConfigFile()
        if rc != 0: return rc

        self._setDataDir()

        if self.runSeq is not None and len(self.runSeq) > 0:
            rc = self._execSteps(self.runSeq)
            if rc == 0:
                self.log.info('Completed running execSteps rc = %s' % rc)
            else:
                self.log.error('execSteps rc = %s' % rc)

        if rc != RET_WARN:
            text = 'Please see logFile %s' % logFile
            subj = "SUCCESS running %s on %s " % (
                self.appName,
                self.hostname) if rc == 0 else "ERROR running %s on %s" % (
                    self.appName, self.hostname)
            #r, msg = sm.sendNotif(rc, self.log, subj, text, [logFile, ])
            r = -1
            msg = "Need to enable notification"
            self.log.info('Sending Notification\t%s rc = %s' % (msg, r))

        else:
            self.log.info(
                'Notification Overrided. Not sending message (RET_WARN) rc = %s '
                % rc)

        self.printEnvBean()
        return rc
示例#5
0
def _bkupSAS(argv):
    ln = "backupSAS"              # LogName Hardcoded in case not defined in an ENV VAR or in cmd line. 
    print len(argv)
    if len(argv) > 1 : ln = argv[1]
    logFile = getLogHandler(ln,log)  
    print "LogFile is %s " % logFile

    # invoke SAS script
    log.info('Starting Metadata Backup to %s' % bkpDst)
    rc = _metaBkup()
    if rc != 0 : log.error("%s rc=%s" % (rc,bc.SASBkupCmd))
    else       : 
        log.info("%s rc=%s" % (rc,bc.SASBkupCmd))
        rc = _copyBkup(bc.bkpSASDir,bkpDst)
        log.info('_copyBkup rc = %s' % rc )

    return rc
示例#6
0
def main(Args):

    # Set log
    fn = os.path.splitext(os.path.basename(sys.argv[0]))[0]
    logFile = getLogHandler(fn,log)
    log.info('logFile= %s' % logFile)
    
   # EO Uncomment in UNIX or set en vars in windows.                         
    rc = _getEnvVars()
    if rc != 0 :
        log.error( "Need to set all env vars:\n %s" %  infaEnvVar.keys())
        return (rc)

    rc = parseArg(sys.argv)
    log.info('userOpt = ' , userOpt)
    if rc != 0 : return(rc)
    if os.environ.has_key('CONFIG_FILE') : 
        fn = os.environ['CONFIG_FILE']
    else:
        log.error("need to set env : 'CONFIG_FILE' " )  
        return 1
    
    log.info('Loading config file:%s' % fn)
    rc = fu.loadConfigFile(fn,ib,log)
    if rc != 0 : 
        log.error('Exiting the program')
        return 1
    
    if (config) : show_config(ib)
    #print "MEMBERS ", inspect.getmembers (ib)
    # Execute program    
    if runSeq is not None and len(runSeq) > 0 : 
        rc = execSteps(runSeq)
        if rc == 0 : log.info ('Completed running execSteps')
        else       : log.error('execSteps rc = %s' % rc)

    text = 'Please see logFile %s' % logFile
    subj = "SUCCESS running %s on %s " %(fn,hostname ) if rc == 0 else "ERROR running %s on %s" % (fn,hostname)
    rc,msg=sm.sendNotif(rc,log,subj,text,[logFile,])
    log.info('Sending Notification\t%s rc = %s' % (msg,rc))
    
    sys.exit(rc)
示例#7
0
def main(argv):
    appName = os.path.splitext(os.path.basename(argv[0]))[0]
    if len(argv) != 2:
        log.error("USAGE : <%s> fx [runSeq] Incorrect Number of arguments (%d)" % (argv[0], len(argv)))
        sys.exit(1)

    runSeq = argv[1]
    logFile = getLogHandler(appName, log)
    log.info("logfile = ", logFile)

    rc = _getEnvVars()
    if rc != 0:
        log.error("Need to set all env vars:\n %s" % infaEnvVar.keys())
        sys.exit(rc)

    log.info("Loading Config File %s" % ib.configFile)
    rc = fu.loadConfigFile(ib.configFile, ib, log)
    if rc != 0:
        log.error("Cannot Load %s Exiting the program" % ib.configFile)
        return 1

    # Execute program
    if runSeq is not None and len(runSeq) > 0:
        rc = execSteps(runSeq)
        if rc == 0:
            log.info("Completed running execSteps")
        else:
            log.error("execSteps rc = %s" % rc)

    log.info("Executed cmd = ", argv[1:], " rc = ", rc)
    subj = (
        ("SUCCESS running %s on Server %s Monitoring %s " % (appName, hostname, ib.rhost))
        if rc == 0
        else ("ERROR running %s on Server %s. Monitoring %s " % (appName, hostname, ib.rhost))
    )
    text = "Running %s host=%s. Monitoring %s . Please See logfile %s" % (appName, hostname, ib.rhost, logFile)
    text += gText

    rc1, msg = sm.sendNotif(rc, log, subj, text, [logFile])
    log.info("logFile= %s" % logFile)
    log.info("Sending Notification\t%s rc = %s" % (msg, rc1))
    return rc
示例#8
0
 def main(self, Argv):
     rc = 1  # Failed
     logFile = getLogHandler(self.appName, self.log)
     self.log.info('logFile= %s' % logFile)
     
     # should NEVER get this programmatic error !!!!
     if self.cmdStep is None or len(self.cmdStep) == 0 :
         self.log.error("Program Error:self.cmdStep is ", self.cmdStep)
         return rc
     
     rc = self.setArgs(Argv)
     if rc != 0 : return rc
     
     rc = self._getEnvVars()
     if rc != 0 :
         self.log.error("Need to set all env vars:\n %s" % self.infaEnvVar.keys())
         return rc
     
     rc = self._getConfigFile()
     if rc != 0 :
         self.log.error("Error Loading Config File:\n")
         return rc
     
     self._setDataDir()
        
     if self.runSeq is not None and len(self.runSeq) > 0 : 
         rc = self._execSteps(self.runSeq)
         if rc == 0 : self.log.info ('Completed running execSteps rc = %s' % rc)
         else       : self.log.error('execSteps rc = %s' % rc)
     
     
     if rc != RET_WARN:
         text = 'Please see logFile %s' % logFile
         subj = "SUCCESS running %s on %s " % (self.appName, self.hostname) if rc == 0 else "ERROR running %s on %s" % (self.appName, self.hostname)
         r, msg = sm.sendNotif(rc, self.log, subj, text, [logFile, ])
         self.log.info('Sending Notification\t%s rc = %s' % (msg, r))    
     
     else:
         self.log.info('Notification Overrided. Not sending message (RET_WARN) rc = %s ' % rc)
         
     self.printEnvBean()
     sys.exit(rc)
示例#9
0
def main(argv):

    # Set log
    fn = os.path.splitext(os.path.basename(sys.argv[0]))[0]
    logFile = getLogHandler(fn,log)
    log.info('logFile= %s' % logFile)
    
    rc = _getEnvVars()
    if rc != 0 :
        log.error( "Need to set all env vars:\n %s" %  infaEnvVar.keys())
        sys.exit(rc)
    
    rc = bkupDir()
    log.info('bkupDir rc = %s ' % rc)
    subj = ("SUCCESS running backup on Server %s " % ('host')) if rc == 0 else ("ERROR running backup on Server %s " % ('host'))
    text = "Running backup on host %s. Please See logfile %s" % (hostname,logFile)

    #text += gText

    rc,msg=sm.sendNotif(rc,log,subj,text,[logFile,])
    log.info('logFile= %s' % logFile)
    log.info('Sending Notification\t%s rc = %s' % (msg,rc))
示例#10
0
def main():
    logFile = getLogHandler('Test', logger, True)
    logger.info("Logfile is %s", logFile)
    #rc = parseCDR()
    rc = runC(logger)
    return rc
示例#11
0
def main():
    logFile = getLogHandler('Test', logger, True)
    logger.info("Logfile is %s", logFile)
示例#12
0
import os , sys
import csv
import ConfigParser
import subprocess
from optparse import OptionParser

import proc.process    as proc
import utils.fileutils as fu
import utils.strutils  as su
import common.log4py   as log4py 
from   common.loghdl import getLogHandler

ln   =  'gp2nz_mig' 
log  =  log4py.Logger().get_instance()
logfile = getLogHandler(ln,log)
tblLoadCnt = {'table1':100,
              'table2':200,
              'table3':300,
              'table4':1,
              'table5':5,
              }  # Hold target load counts.

def getOptions(arg):
    usage = 'usage: %prog [options -t=<table name>]'
    parser = OptionParser(usage)
    parser.add_option('-t', '--table', dest='table', type='string', metavar='name',
            help='Table to be extracted')
    parser.add_option('-c', '--config', dest='config', type='string', metavar='name',
            help='Config file name')
    (options, arg) = parser.parse_args(arg)
示例#13
0
import utils.fileutils as fu
import utils.strutils as su

from common.loghdl import getLogHandler

os.environ["LOG_LEVEL"] = "NORMAL"
os.environ["LOG_DIR"] = r"C:/apps/logs"
os.environ["LOGNAME"] = "chk_files"
os.environ["APP_NAME"] = "chk_files"

hostname = socket.gethostname()
appName = os.environ["APP_NAME"]

# Get the Logname
log = log4py.Logger().get_instance()
logFile = getLogHandler("chk_files", log)
infaLogs = "logs"
RET_WARN = 101


class InfaBaseAppBean:
    pass


# cfgFile = r'C:\apps\config\chk_files.cfg'
ib = InfaBaseAppBean

# Use wildcard in filename
def _checkIncWildFiles(fn):

    # Get file