def addOptions(parser):
    """
        @summary : This method is used to add all available options to the option parser.
        
    """

    parser.add_option("-c", "--combine", action="store_true", dest = "combine", default=False, \
                      help=_("Combine data from all specified machines.") )

    parser.add_option("-d", "--date", action="store", type="string", dest="date", default=StatsDateLib.getIsoFromEpoch( time.time() ),\
                       help=_("Decide current time. Usefull for testing.") )

    parser.add_option("-i", "--individual", action="store_true", dest = "individual", default=False, \
                      help=_("Create individual graphics for all specified machines.") )

    parser.add_option( "-l", "--logins", action="store", type="string", dest="logins", default="pds",\
                        help = _("Logins to be used to connect to machines.") )

    parser.add_option( "-m", "--machines", action="store", type="string", dest="machines", default=LOCAL_MACHINE,\
                        help = _("Machines for wich you want to collect data.") )

    parser.add_option("-o", "--outputLanguage", action="store", type="string", dest="outputLanguage",\
                       default=LanguageTools.getMainApplicationLanguage(), help = _("Language in which the graphics are outputted.") )

    parser.add_option("-s", "--span", action="store",type ="int", dest = "timespan", default=24, \
                      help=_("timespan( in hours) of the graphic."))
def addOptions( parser ):
    """
        @summary : This method is used to add all available options to the option parser.
        
    """
    
    parser.add_option("-c", "--combine", action="store_true", dest = "combine", default=False, \
                      help=_("Combine data from all specified machines.") )
    
    parser.add_option("-d", "--date", action="store", type="string", dest="date", default=StatsDateLib.getIsoFromEpoch( time.time() ),\
                       help=_("Decide current time. Usefull for testing.") ) 
    
    parser.add_option("-i", "--individual", action="store_true", dest = "individual", default=False, \
                      help=_("Create individual graphics for all specified machines.") )                    
    
    parser.add_option( "-l", "--logins", action="store", type="string", dest="logins", default="pds",\
                        help = _("Logins to be used to connect to machines.") ) 
    
    parser.add_option( "-m", "--machines", action="store", type="string", dest="machines", default=LOCAL_MACHINE,\
                        help = _("Machines for wich you want to collect data.") ) 
    
    parser.add_option("-o", "--outputLanguage", action="store", type="string", dest="outputLanguage",\
                       default=LanguageTools.getMainApplicationLanguage(), help = _("Language in which the graphics are outputted.") ) 
    
    parser.add_option("-s", "--span", action="store",type ="int", dest = "timespan", default=24, \
                      help=_("timespan( in hours) of the graphic."))    
Пример #3
0
    def prepareQuery(self):
        """
            @summary : Buildup the query  to be executed.
        
            @SIDE_EFFECT :  modifies self.query value.
            
        """
        
        global _ 
        
        if self.queryParameters.combine == 'true':
            totals = True
            mergerType = "regular"
        else:
            totals = False      
            mergerType = ""
            
            
        fixedCurrent  = False
        fixedPrevious = False
        
        if _("current")  in str(self.queryParameters.fixedSpan).lower() :
            fixedCurrent = True 
        elif _("previous") in str(self.queryParameters.fixedSpan).lower():
            fixedPrevious = True      
        else:
            fixedCurrent  = False
            fixedPrevious = False 
       

            
        hour      = self.queryParameters.endTime.split(" ")[1]
        splitDate = self.queryParameters.endTime.split(" ")[0].split( '-' )
        
        date =  splitDate[2] + '-' + splitDate[1]  + '-' + splitDate[0]  + " " + hour 
        if self.queryParameters.span == "": 
            timespan = 0 
        else:
            timespan = int(self.queryParameters.span )    
            
        StatsDateLib.setLanguage( self.querierLanguage )
        startTime, endTime = StatsDateLib.getStartEndInIsoFormat(date, timespan, self.queryParameters.specificSpan, fixedCurrent, fixedPrevious )
        
        timespan = int( StatsDateLib.getSecondsSinceEpoch( endTime ) - StatsDateLib.getSecondsSinceEpoch( startTime ) ) / 3600   
        
        combinedMachineName = ""
        for machine in self.queryParameters.machines:
            combinedMachineName = combinedMachineName + machine

        machines = [ combinedMachineName ]
       
        
        self.graphicProducer = RRDGraphicProducer( self.queryParameters.fileTypes[0], self.queryParameters.statsTypes ,\
                                                   totals,  self.queryParameters.specificSpan,\
                                                   self.queryParameters.sourLients, timespan,\
                                                   startTime, endTime, machines, False,
                                                   mergerType, True, self.querierLanguage, self.querierLanguage )
  
        StatsDateLib.setLanguage( LanguageTools.getMainApplicationLanguage() )
Пример #4
0
    def __init__(self, languages=None):
        """
        
            @param languages: list of languages 
                              for which to generate
                              the doc web pages.
        """

        global _

        self.mainLanguage = LanguageTools.getMainApplicationLanguage()
        self.languages = languages or LanguageTools.getSupportedLanguages()
Пример #5
0
 def __init__( self, languages = None ):
     """
     
         @param languages: list of languages 
                           for which to generate
                           the doc web pages.
     """
     
     global _ 
     
     self.mainLanguage = LanguageTools.getMainApplicationLanguage()
     self.languages = languages or LanguageTools.getSupportedLanguages()
Пример #6
0
def buildCsvFileName(infos):
    """ 
    
        @summary: Builds and returns the file name to use for the csv file.
        
        @param infos: _CvsInfos instance containing the required 
                      information to build up the file name.
        
        @return: Return the built up file name.              
                      
    """

    global _

    StatsDateLib.setLanguage(infos.outputLanguage)
    paths = StatsPaths()
    paths.setPaths(infos.outputLanguage)

    machinesStr = str(infos.machinesForLabels).replace('[', '').replace(
        ']', '').replace(',', '').replace("'",
                                          "").replace('"',
                                                      '').replace(' ', '')

    currentYear, currentMonth, currentDay = StatsDateLib.getYearMonthDayInStrfTime(
        StatsDateLib.getSecondsSinceEpoch(infos.start))
    currentWeek = time.strftime(
        "%W", time.gmtime(StatsDateLib.getSecondsSinceEpoch(infos.start)))

    fileName = paths.STATSCSVFILES

    if infos.span == "daily":
        fileName = fileName + "/" + _(
            "daily/") + infos.fileType + "/%s/%s/%s/%s.csv" % (
                machinesStr, currentYear, currentMonth, currentDay)

    elif infos.span == "weekly":
        fileName = fileName + "/" + _(
            "weekly/") + infos.fileType + "/%s/%s/%s.csv" % (
                machinesStr, currentYear, currentWeek)

    elif infos.span == "monthly":
        fileName = fileName + "/" + _(
            "monthly/") + infos.fileType + "/%s/%s/%s.csv" % (
                machinesStr, currentYear, currentMonth)

    elif infos.span == "yearly":
        fileName = fileName + "/" + _(
            "yearly/") + infos.fileType + "/%s/%s.csv" % (machinesStr,
                                                          currentYear)

    StatsDateLib.setLanguage(LanguageTools.getMainApplicationLanguage())

    return fileName
Пример #7
0
def buildCsvFileName( infos ):
    """ 
    
        @summary: Builds and returns the file name to use for the csv file.
        
        @param infos: _CvsInfos instance containing the required 
                      information to build up the file name.
        
        @return: Return the built up file name.              
                      
    """
    
    global _ 
    
    StatsDateLib.setLanguage(infos.outputLanguage)
    paths = StatsPaths()
    paths.setPaths( infos.outputLanguage )
    
    machinesStr = str(infos.machinesForLabels).replace('[','').replace( ']','' ).replace(',', '').replace("'","").replace( '"','').replace( ' ','' )
    
    currentYear, currentMonth, currentDay = StatsDateLib.getYearMonthDayInStrfTime( StatsDateLib.getSecondsSinceEpoch (infos.start) )     
    currentWeek = time.strftime( "%W", time.gmtime( StatsDateLib.getSecondsSinceEpoch (infos.start) ) )
    
    
    fileName = paths.STATSCSVFILES
   
    if infos.span == "daily":
        fileName = fileName + "/" + _("daily/") + infos.fileType + "/%s/%s/%s/%s.csv" %( machinesStr, currentYear, currentMonth, currentDay )   
    
    elif infos.span == "weekly":
        fileName = fileName + "/" +  _("weekly/") + infos.fileType  + "/%s/%s/%s.csv" %( machinesStr, currentYear, currentWeek ) 
    
    elif infos.span == "monthly":
        fileName = fileName + "/" + _("monthly/") + infos.fileType + "/%s/%s/%s.csv" %( machinesStr, currentYear, currentMonth )
    
    elif infos.span == "yearly":
        fileName = fileName + "/" + _("yearly/") + infos.fileType  + "/%s/%s.csv" %( machinesStr, currentYear )
        
    
    StatsDateLib.setLanguage( LanguageTools.getMainApplicationLanguage() )    
        
    return fileName 
Пример #8
0
def getImagesLangFromForm():
    """
        @summary : Parses form with whom this program was called.
        
        @return: Returns the images and language found within the form.
        
    """
    
    lang = LanguageTools.getMainApplicationLanguage()
    
    images = []
    
    newForm = {}
    
    form = cgi.FieldStorage()

    for key in form.keys():
        value = form.getvalue(key, "")

        if isinstance(value, list):
            newvalue = ",".join(value)
                   
        else:
            newvalue = value
        
        newForm[key.replace("?","")]= newvalue    

    try:
        images = newForm["images"]  
        images = images.split(';')

    except:
        pass
    
    try:
        lang = newForm["lang"]
    except:
        pass  
        
    return images, lang 
Пример #9
0
def addOptions( parser ):
    """
        @summary : This method is used to add all available options to the option parser.
        
    """      
    
    parser.add_option("-c", "--clients", action="store", type="string", dest="clients", default="",
                        help=_("Clients' names") )
    
    parser.add_option( "--copy", action="store_true", dest = "copy", default=False, help=_("Create a copy file for the generated image.") )
   
    parser.add_option( "--combineClients", action="store_true", dest = "combineClients", default=False, \
                       help=_("Combine the data of all client into a single graphics for each graphic type.") )
    
    parser.add_option("-d", "--date", action="store", type="string", dest="currentTime", \
                      default=StatsDateLib.getIsoFromEpoch( time.time() ), help=_("Decide current time. Usefull for testing.") )
    
    parser.add_option("-f", "--fileType", action="store", type="string", dest="fileType", default='tx',\
                       help=_("Type of log files wanted.") )                     
    
    parser.add_option( "-g", "--groupName", action="store", type="string", dest="groupName", default="",
                        help=_("Specify a name for the combined graphics of numerous client/sources. Note : requires the --combinedClients options to work." ) )       
    
    parser.add_option( "-m", "--machines", action="store", type="string", dest="machines", default=LOCAL_MACHINE,\
                        help = _("Machines for wich you want to collect data.") ) 
    
    parser.add_option("-n", "--collectUpToNow", action="store_true", dest = "collectUpToNow", default=False, \
                      help=_("Collect data up to current second.") )
    
    parser.add_option("-o", "--outputLanguage", action="store", type="string", dest="outputLanguage",\
                       default=LanguageTools.getMainApplicationLanguage(), help = _("Language in which the graphics are outputted.") ) 
    
    parser.add_option("-p", "--products", action="store", type = "string", dest = "productTypes", default=_("All"), \
                      help=_("Specific product types to look for in the data collected.") )
    
    parser.add_option("-s", "--span", action="store",type ="int", dest = "timespan", default=12, help=_("timespan( in hours) of the graphic.") )
       
    parser.add_option("-t", "--types", type="string", dest="types", default=_("All"),help=_("Types of data to look for.") )   
Пример #10
0
def main():
    """
        Generates the web page based on the received 
        machines and file type parameters.
        
    """

    error = ""
    form = getForm()
    # print form

    try:
        wordType = form["wordType"]
        if wordType != "products" and wordType != "groupName":
            error = "Error. Word type needs to be either products or groupName."

    except:
        wordType = ""

    try:
        language = form["lang"]
        if language not in LanguageTools.getSupportedLanguages():
            raise
    except:
        language = LanguageTools.getMainApplicationLanguage()

    try:
        word = form["word"]
        word = word.replace(" ", "")
    except:
        error = "Error. Word needs to be specified."
        word = ""

    if word != "":
        updateWordsFromDB(wordType, word, language)

    returnReply(error)
Пример #11
0
def main():
    """
        Generates the web page based on the received 
        machines and file type parameters.
        
    """

    error = ''
    form = getForm()
    #print form

    try:
        wordType = form['wordType']
        if wordType != 'products' and wordType != 'groupName':
            error = "Error. Word type needs to be either products or groupName."

    except:
        wordType = ""

    try:
        language = form['lang']
        if language not in LanguageTools.getSupportedLanguages():
            raise
    except:
        language = LanguageTools.getMainApplicationLanguage()

    try:
        word = form['word']
        word = word.replace(' ', '')
    except:
        error = "Error. Word needs to be specified."
        word = ""

    if word != "":
        updateWordsFromDB(wordType, word, language)

    returnReply(error)
Пример #12
0
    def __init__( self, timespan,  stats = None, clientNames = None, groupName = "", type='lines',           \
                  interval=1, imageName="gnuplotOutput", title = "Stats", currentTime = "",now = False,      \
                  statsTypes = None, productTypes = None, logger = None, logging = True, fileType = "tx", \
                  machines = "", entryType = "minute", maxLatency = 15, workingLanguage = None, outputLanguage = None ):
        """
        
            @summary : GnuPlotter constructor. 
            
        """                                                                    
        
        #TODO Verify if all theses fileds are really necessary.    
        machines = "%s" %machines
        machines = machines.replace( "[","").replace( "]","" ).replace( "'", "" )
        
        self.now         = now                     # False means we round to the top of the hour, True we don't
        self.stats       = stats or []             # ClientStatsPickler instance.
        self.clientNames = clientNames or []       # Clients for wich we are producing the graphics. 
        self.groupName   = groupName               # Group name used when combining data of numerous client/sources.
        self.timespan    = timespan                # Helpfull to build titles 
        self.currentTime = currentTime             # Time of call
        self.type        = 'impulses'              # Must be in: ['linespoint', 'lines', 'boxes', 'impulses'].
        self.fileType    = fileType                # Type of file for wich the data was collected
        self.imageName   = imageName               # Name of the image file.
        self.nbFiles     = []                      # Number of files found in the data collected per server.
        self.nbErrors    = []                      # Number of errors found per server
        self.graph       = Gnuplot.Gnuplot()       # The gnuplot graphic object itself. 
        self.timeOfMax   = [[]]                    # Time where the maximum value occured.  
        self.machines    = machines                # List of machine where we collected info.
        self.entryType   = entryType               # Entry type :  minute, hour, week, month
        self.clientName  = ""                      # Name of the client we are dealing with 
        self.maxLatency  = maxLatency              # Maximum latency 
        self.maximums    = [[]]                    # List of all maximum values 1 for each graphic.
        self.minimums    = [[]]                    # Minimum value of all pairs.
        self.means       = [[]]                    # Mean of all the pairs.
        self.maxFileNames= [[]]                    # Name of file where value is the highest .
        self.filesWhereMaxOccured = [[]]           # List of files for wich said maximums occured.  
        self.statsTypes  = statsTypes or []        # List of data types to plot per client.
        self.totalNumberOfBytes    = []            # Total of bytes for each client 
        self.nbFilesOverMaxLatency = []            # Numbers of files for wich the latency was too long.
        self.ratioOverLatency      = []            # % of files for wich the latency was too long. 
        self.const = len( self.stats ) -1          # Usefull constant
        self.productTypes = productTypes           # Type of product for wich the graph is being generated.  
        self.initialiseArrays()
        self.loggerName       = 'gnuPlotter'
        self.logger           = logger
        self.logging          = logging
        self.workingLanguage  = workingLanguage   # Language with whom we are currently working, in which the string parameters were specified.
        self.outputLanguage  = outputLanguage    # Language in which the graphics will be produced.
        
        if self.logging == True:
            if self.logger == None: # Enable logging
                self.logger = Logger( StatsPaths.STATSLOGGING +  'stats_' + self.loggerName + '.log',\
                                      'INFO', 'TX' + self.loggerName, bytes = True  ) 
                self.logger = self.logger.getLogger()
        
        if self.workingLanguage == None:
            self.workingLanguage = LanguageTools.getMainApplicationLanguage()
        
        if self.outputLanguage == None:    
            self.outputLanguage = LanguageTools.getMainApplicationLanguage()
            
        if self.workingLanguage not in LanguageTools.getSupportedLanguages():
            if self.logging == True:
                _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.workingLanguage )
                self.logger.error( _("Error. %s is not a supported working language.") %( self.workingLanguage )  )
                sys.exit()
                
        if self.outputLanguage not in LanguageTools.getSupportedLanguages():
            if self.logging == True:
                _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.workingLanguage )
                self.logger.error( _("Error. %s is not a supported output language.") %( self.outputLanguage )  )        
                sys.exit()
                
        
        _ = self.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, self.workingLanguage)
        
        self.productTypes = productTypes or [ _( "All" ) ]
        
        _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.outputLanguage )        
        
        
        
        if self.fileType == 'tx':
            self.sourlient = _("Client")
        else:
            self.sourlient = _("Source")

        self.xtics       = self.getXTics( )        # Seperators on the x axis.
Пример #13
0
 def buildRRDFileName( dataType = 'errors', clients = None , machines = None,\
                       groupName = "", fileType = "", usage = "regular"  ):
     """
         @summary : Returns the name of the round robin database bases on the parameters.
     
         @param dataType: byteocunt, errors, filecount, filesOverMaxLatency and latency.
         
         @param clients: list of clients/sources names. If only one is wanted, include it in a list.
         
         @param machines: list of machines associated with client/sources names. If only one is wanted, include it in a list.
         
         @param fileType : Useless for regular and group databases. Obligatory for totalForMachine databases. 
         
         @param groupName: optional. Use only if the list of client/sources has a KNOWN group name.
         
         @param usage: regular, group or totalForMachine.
     
         @return: Returns the name of the round robin database bases on the parameters.
     
     """
     
     _ = LanguageTools.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, LanguageTools.getMainApplicationLanguage() )
     
     clients  = clients or ['client1','client1']
     machines = machines or ['machine1','machine2']
     
     fileName = ""
     
     combinedMachineName = ""   
     for machine in machines:
         combinedMachineName = combinedMachineName + machine
       
     combinedClientsName = ""  
     for client in clients:
         combinedClientsName = combinedClientsName + client
            
     if len(clients) ==1:       
         if usage == "regular":
             fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" %( dataType, combinedClientsName, combinedMachineName )  
         
         elif usage == "group":
         
             fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" %( dataType, groupName, combinedMachineName )
              
         elif usage == "totalForMachine":
              fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" %( dataType, fileType, combinedMachineName )            
     
     else:
         
         if usage == "regular":
             fileName = STATSPATHS.STATSCURRENTDB + _("%s/combined/%s_%s") %( dataType, combinedClientsName, combinedMachineName )  
         
         elif usage == "group":
         
             #fileName = STATSPATHS.STATSCURRENTDB + _("%s/combined/%s_%s") %( dataType, groupName, combinedMachineName )    
             try:
                 existingFiles=  os.listdir(STATSPATHS.STATSCURRENTDB + "%s/combined/"%( dataType) )
             
                 for file in existingFiles:
                     if fnmatch.fnmatch(file, groupName + "*"):
                         fileName = file
                         break
             except:
                 pass
             
             if fileName == "":#no preexisitng file exist for this group
                 fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" %( dataType, groupName, combinedMachineName )    
             else:#else
                 fileName =  STATSPATHS.STATSCURRENTDB + "%s/combined/"%(dataType) + fileName       
              
              
         elif usage == "totalForMachine":
              fileName = STATSPATHS.STATSCURRENTDB + _("%s/combined/%s_%s") %( dataType, fileType, combinedMachineName )   
     
     #print "before ", fileName 
     #fileName = fileName.replace("année","year").replace("nbreDeBytes","bytecount").replace("nbreDeFichiers","filecount").replace("erreurs","errors").replace("latence","latency").replace("fichiersAvecLatenceInnacceptable","filesOverMaxLatency").replace("heures","hours").replace("mois","month").replace("jour","day").replace("","")    
     #print "after ", fileName
     
     return  fileName 
Пример #14
0
def getGraphicProducerFromParserOptions( parser ):
    """
        
        This method parses the argv received when the program was called
        It takes the params wich have been passed by the user and sets them 
        in the corresponding fields of the infos variable.   
    
        If errors are encountered in parameters used, it will immediatly terminate 
        the application. 
    
    """ 
    
    graphicType = _("other")
    mergerType = ""
    
    ( options, args )= parser.parse_args()        
    timespan         = options.timespan
    machines         = options.machines.replace( ' ','').split(',')
    clientNames      = options.clients.replace( ' ','' ).split(',')
    types            = options.types.replace( ' ', '').split(',')
    date             = options.date.replace('"','').replace("'",'')
    fileType         = options.fileType.replace("'",'')
    havingRun        = options.havingRun
    individual       = options.individual
    totals           = options.totals
    daily            = options.daily
    weekly           = options.weekly
    monthly          = options.monthly
    yearly           = options.yearly    
    fixedCurrent     = options.fixedCurrent
    fixedPrevious    = options.fixedPrevious
    copy             = options.copy
    turnOffLogging   = options.turnOffLogging
    outputLanguage   = options.outputLanguage
    
    
    if outputLanguage == "":
        outputLanguage = LanguageTools.getMainApplicationLanguage()
    else :
        if outputLanguage not in LanguageTools.getSupportedLanguages():
            print _("Error. The specified language is not currently supported by this application.")
            print _("Please specify one of the following languages %s or use the default value()" %( str( LanguageTools.getSupportedLanguages() ).replace("[","").replace("]",""), LanguageTools.getMainApplicationLanguage()  ) )
            print _("Program terminated.")
            sys.exit()
            
    counter = 0  
    specialParameters = [daily, monthly, weekly, yearly]
    for specialParameter in specialParameters:
        if specialParameter:
            counter = counter + 1 
            
    if counter > 1 :
        print _("Error. Only one of the daily, weekly and yearly options can be use at a time ")
        print _("Use -h for help.")
        print _("Program terminated.")
        sys.exit()
    
    elif counter == 1 and timespan != None :
        print _("Error. When using the daily, the weekly or the yearly options timespan cannot be specified. " )
        print _("Use -h for help.")
        print _("Program terminated.")
        sys.exit()
        
    elif counter == 0:    
        if fixedPrevious or fixedCurrent:
            print _("Error. When using one of the fixed options, please use either the -d -m -w or -y options. " )
            print _("Use -h for help.")
            print _("Program terminated.")
            sys.exit()
        
        if copy :
            if daily or not( weekly or monthly or yearly ):
                print _("Error. Copying can only be used with the -m -w or -y options. ") 
                print _("Use -h for help.")
                print _("Program terminated.")
            
                
    if counter == 0 and timespan == None :
        timespan = 12
        
    if fixedPrevious and fixedCurrent:
        print _("Error. Please use only one of the fixed options,either fixedPrevious or fixedCurrent. ") 
        print _("Use -h for help.")
        print _("Program terminated.")
        sys.exit()  
    
    if individual and totals:
        print _("Error. Please use only one of the group options,either individual or totals. ")
        print _("Use -h for help.")
        print _("Program terminated.")
        sys.exit()  
    
    try: # Makes sure date is of valid format. 
         # Makes sure only one space is kept between date and hour.
        t =  time.strptime( date, '%Y-%m-%d %H:%M:%S' )
        split = date.split()
        date = "%s %s" %( split[0], split[1] )

    except:    
        print _("Error. The date format must be YYYY-MM-DD HH:MM:SS")
        print _("Use -h for help.")
        print _("Program terminated.")
        sys.exit()         
        
    
    #Set graphic type based on parameters. Only one tpye is allowed at once based on previous validation.
    if daily :
        graphicType = _("daily")
        if fixedPrevious == False and fixedCurrent == False :
            timespan = 24
    elif weekly:
        graphicType = _("weekly")
        if fixedPrevious == False and fixedCurrent == False :
            timespan = 24 * 7
    elif monthly:
        graphicType = _("monthly")
        if fixedPrevious == False and fixedCurrent == False :
            timespan = 24 * 30
    elif yearly:
        graphicType = _("yearly")      
        if fixedPrevious == False and fixedCurrent == False :
            timespan = 24 * 365
    
    
    start, end = StatsDateLib.getStartEndInIsoFormat(date, timespan, graphicType, fixedCurrent, fixedPrevious )
    
    
    timespan = int( StatsDateLib.getSecondsSinceEpoch( end ) - StatsDateLib.getSecondsSinceEpoch( start ) ) / 3600    
                     
            
    #print "timespan %s" %timespan                           
    try:    
        if int( timespan ) < 1 :
            raise 
                
    except:
        
        print _("Error. The timespan value needs to be an integer one above 0.") 
        print _("Use -h for help.")
        print _("Program terminated.")
        sys.exit()        
         
    if fileType != "tx" and fileType != "rx":        
        print _("Error. File type must be either tx or rx.")
        print  "Specified file type was : ", fileType
        print _("Multiple types are not accepted.") 
        print _("Use -h for additional help.")
        print _("Program terminated.")
        sys.exit()            
        
                
    if havingRun == True and clientNames[0] != _("ALL"):
        print _("Error. Cannot use the havingRun option while specifying client/source names.")
        print _("To use havingRun, do not use -c|--client option.")
        print _("Use -h for additional help.")
        print _("Program terminated.")
        sys.exit()
    
    if clientNames[0] == _("ALL"):
        # Get all of the client/sources that have run between graph's start and end. 
        if totals == True or havingRun == True :          
            #print start, end, machines       
            rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNamesHavingRunDuringPeriod( start, end, machines,None, havingrunOnAllMachines = True )
            mergerType = _("totalForMachine")
        else:#Build graphs only for currently runningclient/sources.      
            rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, machines[0] )
            mergerType = _("group")
                     
        if fileType == _("tx"):    
            clientNames = txNames  
            #print clientNames
        else:
            clientNames = rxNames    
            
    else:
        if totals == True :  
            mergerType = _("regular")
    #--------------------------------------------------------------------- try :
            
    if fileType == _("tx"):       
    
        validTypes = [ _("latency"), _("bytecount"), _("errors"), _("filesOverMaxLatency"), _("filecount") ]
        
        if types[0] == _("All") :
            types = validTypes
        else :
            for t in types :
                if t not in validTypes:
                    raise Exception("%s is not a valid type" %t)
                    
    else:      
        
        validTypes = [ _("bytecount"), _("errors"), _("filecount") ]
        
        if types[0] == _("All"):
            types = validTypes
        
        else :
            for t in types :
                if t not in validTypes:
                        raise Exception("")

    #------------------------------------------------------------------- except:
        #----------------------------------------------------------- print types
        # print _("Error. With %s fileType, possible data types values are : %s.") %( fileType, validTypes )
        #---- print _("For multiple types use this syntax : -t 'type1','type2'")
        #-------------------------------- print _("Use -h for additional help.")
        #---------------------------------------- print _("Program terminated.")
        #------------------------------------------------------------ sys.exit()
  
            
    if individual != True :        
        combinedMachineName = ""
        for machine in machines:
            combinedMachineName = combinedMachineName + machine
                    
        machines = [ combinedMachineName ]              
         
                
    if len(clientNames) <1:
        print _("Error. No client/sources were found that matched the specified parameters") %( fileType, validTypes )
        print _("Verify parameters used, especially the machines parameter.")
        print _("Use -h for additional help.")
        print _("Program terminated.")
        sys.exit()


    if len(clientNames) <1:
        print _("Error. No client/sources were found that matched the specified parameters")
        print _("Verify parameters used, especially the machines parameter.")
        print _("Use -h for additional help.")
        print _("Program terminated.")
        sys.exit()  
    
    elif len(clientNames) == 1 and totals == True:   
        print _("Error. Cannot use totals option with only one client/source name.")
        print _("Either remove --total option or use more than one client/source..")
        print _("Use -h for additional help.")
        print _("Program terminated.")
        sys.exit()          
    
    end = StatsDateLib.getIsoWithRoundedHours( end )
    
    graphicsProducer = RRDGraphicProducer( startTime = start, endTime = end, graphicType = graphicType, clientNames = clientNames, types = types, timespan = timespan, machines = machines, fileType = fileType,\
                                           totals = totals, copy = copy, mergerType = mergerType,turnOffLogging = turnOffLogging, inputLanguage = LanguageTools.getMainApplicationLanguage() ,  outputLanguage = outputLanguage )   
            
    return graphicsProducer                       
Пример #15
0
"""
sys.path.insert(1, os.path.dirname( os.path.abspath(__file__) ) + '/../../')

from pxStats.lib.StatsDateLib import StatsDateLib
from pxStats.lib.RrdUtilities import RrdUtilities
from pxStats.lib.GeneralStatsLibraryMethods import GeneralStatsLibraryMethods
from pxStats.lib.StatsPaths import StatsPaths  
from pxStats.lib.LanguageTools import LanguageTools
from pxStats.lib.RRDGraphicProducer import RRDGraphicProducer


"""
    - Small function that adds pxLib to sys path.
"""
STATSPATHS = StatsPaths( )
STATSPATHS.setPaths( LanguageTools.getMainApplicationLanguage() )
sys.path.append( STATSPATHS.PXLIB )

#  These Imports require pxlib 
from   PXManager import *
from   Logger import *

LOCAL_MACHINE = os.uname()[1]
CURRENT_MODULE_ABS_PATH =  os.path.abspath(__file__).replace( ".pyc", ".py" )     
    
       
     
def getGraphicProducerFromParserOptions( parser ):
    """
        
        This method parses the argv received when the program was called
Пример #16
0
 def printWebPage( self ):
     """ 
         @summary : prints out the entire bottom web page
         
         @precondition: Requires _ translator to have been set prior to calling this function.
     
     """
     
     global _ 
     
     paths = StatsPaths()
     paths.setPaths( LanguageTools.getMainApplicationLanguage() )
     fileName =  paths.STATSWEBPAGES + "bottom.html"
     
     fileHandle = open( fileName, "w" )
     
     fileHandle.write("""
     <html>
          <head>
          
     """)   
     
     self.__printJavaScript(fileHandle)
     
     fileHandle.write("""
         </head>
     """)
     
     
     
     fileHandle.write("""  
          <body bgcolor="#FFD684">
               <div style="position:absolute;top:20%%;vertical-align: middle;text-align:center;left:15%%;bottom:0%%;">
                  <img name="logo" id="logo" src="images/mainLogo_%s.gif" ></img>
  
               </div>
     """ %self.mainLanguage)
     
         
     fileHandle.write( """
              <div name="linksSection" id="linksSection" style="position:absolute;top:67%;vertical-align: middle;text-align:center;left:45%;bottom:0%;">
                   
     """)
     
     for i in range( len( self.otherLanguages ) ):
             _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.otherLanguages[i] )
             
             try:
                 fileHandle.write("""<a href="top_%s.html" target="top" onclick="JavaScript:%sVersionWasClicked()">"""%( self.otherLanguages[i],self.otherLanguages[i]) + _("English version.")+ """</a>""")
             except:
                 print _( "Error.Unsupported language detected." )
                 print _( "Make sure %s is a supported language") %( self.otherLanguages[i] )
                 print _( "Program terminated")
                 sys.exit()
                 
             if i !=  len(self.otherLanguages)-1 :
                 fileHandle.write( "<br>" )
     
     fileHandle.write( """         
              </div>
      
          </body>
     </html>
         
         """)
     
     fileHandle.close()    
Пример #17
0
def updateRoundRobinDatabases(  client, machines, fileType, endTime, logger = None ):
    """
        @summary : This method updates every database linked to a certain client.
        
        @note : Database types are linked to the filetype associated with the client.
        
    """
            
    combinedMachineName = ""
    combinedMachineName = combinedMachineName.join( [machine for machine in machines ] )
    
    tempRRDFileName = RrdUtilities.buildRRDFileName( dataType = _("errors"), clients = [client], machines = machines, fileType = fileType)
    startTime   = RrdUtilities.getDatabaseTimeOfUpdate(  tempRRDFileName, fileType ) 
    
    if  startTime == 0 :
        startTime = StatsDateLib.getSecondsSinceEpoch( StatsDateLib.getIsoTodaysMidnight( endTime ) )
        
    
    endTime     = StatsDateLib.getSecondsSinceEpoch( endTime )           
        
    timeSeperators = getTimeSeperatorsBasedOnAvailableMemory(StatsDateLib.getIsoFromEpoch( startTime ), StatsDateLib.getIsoFromEpoch( endTime ), [client], fileType, machines ) 
    
    
    for i in xrange( len(timeSeperators) -1 ) :
        
        dataPairs   = getPairs( [client], machines, fileType, timeSeperators[i], timeSeperators[i+1] , groupName = "", logger = logger )

        for dataType in dataPairs:
            
            translatedDataType = LanguageTools.translateTerm(dataType, 'en', LanguageTools.getMainApplicationLanguage(), CURRENT_MODULE_ABS_PATH)
            
            rrdFileName = RrdUtilities.buildRRDFileName( dataType = translatedDataType, clients = [client], machines = machines, fileType = fileType )

            if not os.path.isfile( rrdFileName ):
                 createRoundRobinDatabase(  databaseName = rrdFileName , startTime= startTime, dataType = dataType )


            if endTime > startTime :
                j = 0 
                while dataPairs[ dataType ][j][0] < startTime:
                    j = j +1
                    
                for k in range ( j, len( dataPairs[ dataType ] )  ):
                    try:
                        rrdtool.update( rrdFileName, '%s:%s' %( int( dataPairs[ dataType ][k][0] ),  dataPairs[ dataType ][k][1] ) )
                    except:
                        if logger != None:
                            try:
                                logger.warning( "Could not update %s. Last update was more recent than %s " %( rrdFileName,int( dataPairs[ dataType ][k][0] ) ) )
                            except:
                                pass    
                        pass
                    
                    
                if logger != None :
                    try:        
                        logger.info( _( "Updated  %s db for %s in db named : %s" ) %( dataType, client, rrdFileName ) )
                    except:
                        pass        
            else:
                if logger != None :
                     try:
                         logger.warning( _( "This database was not updated since it's last update was more recent than specified date : %s" ) %rrdFileName )
                     except:
                         pass    
                
            RrdUtilities.setDatabaseTimeOfUpdate(  rrdFileName, fileType, endTime )  
Пример #18
0
def updateGroupedRoundRobinDatabases( infos, logger = None ):    
    """
        @summary : This method is to be used to update the database 
                   used to stored the merged data of a group.
         
    """
    
    endTime     = StatsDateLib.getSecondsSinceEpoch( infos.endTime )     
    
    tempRRDFileName = RrdUtilities.buildRRDFileName( _("errors"), clients = infos.group, machines = infos.machines, fileType = infos.fileTypes[0]  )  
    startTime       = RrdUtilities.getDatabaseTimeOfUpdate(  tempRRDFileName, infos.fileTypes[0] )
    
   
    if startTime == 0 :        
        startTime = StatsDateLib.getSecondsSinceEpoch( StatsDateLib.getIsoTodaysMidnight( infos.endTime ) )
        
        
    timeSeperators = getTimeSeperatorsBasedOnAvailableMemory( StatsDateLib.getIsoFromEpoch( startTime ), StatsDateLib.getIsoFromEpoch( endTime ), infos.clients, infos.fileTypes[0], infos.machines )
    
    
    #print timeSeperators
    
    for i in xrange(0, len( timeSeperators ),2 ):#timeseperators should always be coming in pairs
        
        startTime = StatsDateLib.getSecondsSinceEpoch( timeSeperators[i] )
        dataPairs = getPairs( infos.clients, infos.machines, infos.fileTypes[0], timeSeperators[i], timeSeperators[i+1], infos.group, logger )
    
        for dataType in dataPairs:
            
            translatedDataType = LanguageTools.translateTerm(dataType, 'en', LanguageTools.getMainApplicationLanguage(), CURRENT_MODULE_ABS_PATH)
            rrdFileName = RrdUtilities.buildRRDFileName( dataType = translatedDataType, clients = infos.group, groupName = infos.group, machines =  infos.machines,fileType = infos.fileTypes[0], usage = "group" )
            
            if not os.path.isfile( rrdFileName ):
                createRoundRobinDatabase( rrdFileName,  startTime, dataType )
            
            if endTime >  startTime  :
                j = 0 
                while dataPairs[ dataType ][j][0] < startTime and j < len( dataPairs[ dataType ] ):
                    #print "going over : %s startime was :%s" %(dataPairs[ dataType ][j][0], startTime)
                    j = j +1
                    
                for k in range ( j, len( dataPairs[ dataType ] )  ):
                    #print "updating %s at %s" %(rrdFileName, int( dataPairs[ dataType ][k][0] ))
                    try:
                        rrdtool.update( rrdFileName, '%s:%s' %( int( dataPairs[ dataType ][k][0] ),  dataPairs[ dataType ][k][1] ) )
                    except:
                        if logger != None:
                            try:
                                logger.warning( "Could not update %s. Last update was more recent than %s " %( rrdFileName,int( dataPairs[ dataType ][k][0] ) ) )
                            except:
                                pass    
                        pass    
            
            else:
                #print "endTime %s was not bigger than start time %s" %( endTime, startTime ) 
                if logger != None :
                    try:
                        logger.warning( _( "This database was not updated since it's last update was more recent than specified date : %s" ) %rrdFileName )
                    except:
                        pass
                        
    RrdUtilities.setDatabaseTimeOfUpdate( tempRRDFileName, infos.fileTypes[0], endTime )         
Пример #19
0
    def prepareQuery(self):
        """
            @summary : Buildup the query  to be executed.
        
            @SIDE_EFFECT :  modifies self.query value.
            
        """

        global _

        if self.queryParameters.combine == 'true':
            totals = True
            mergerType = "regular"
        else:
            totals = False
            mergerType = ""

        fixedCurrent = False
        fixedPrevious = False

        if _("current") in str(self.queryParameters.fixedSpan).lower():
            fixedCurrent = True
        elif _("previous") in str(self.queryParameters.fixedSpan).lower():
            fixedPrevious = True
        else:
            fixedCurrent = False
            fixedPrevious = False

        hour = self.queryParameters.endTime.split(" ")[1]
        splitDate = self.queryParameters.endTime.split(" ")[0].split('-')

        date = splitDate[2] + '-' + splitDate[1] + '-' + splitDate[
            0] + " " + hour
        if self.queryParameters.span == "":
            timespan = 0
        else:
            timespan = int(self.queryParameters.span)

        StatsDateLib.setLanguage(self.querierLanguage)
        startTime, endTime = StatsDateLib.getStartEndInIsoFormat(
            date, timespan, self.queryParameters.specificSpan, fixedCurrent,
            fixedPrevious)

        timespan = int(
            StatsDateLib.getSecondsSinceEpoch(endTime) -
            StatsDateLib.getSecondsSinceEpoch(startTime)) / 3600

        combinedMachineName = ""
        for machine in self.queryParameters.machines:
            combinedMachineName = combinedMachineName + machine

        machines = [combinedMachineName]


        self.graphicProducer = RRDGraphicProducer( self.queryParameters.fileTypes[0], self.queryParameters.statsTypes ,\
                                                   totals,  self.queryParameters.specificSpan,\
                                                   self.queryParameters.sourLients, timespan,\
                                                   startTime, endTime, machines, False,
                                                   mergerType, True, self.querierLanguage, self.querierLanguage )

        StatsDateLib.setLanguage(LanguageTools.getMainApplicationLanguage())
Пример #20
0
def createSymbolicLinks(path, currentlyUsedLanguages):
    """
        @summary : create symbolic links from web-interface to general 
                   pxStats package.
                   
                   This will prevent us from having to sync both
                   sides all the time. i.e updating pxStats
                   ( via svn update for example) will update both 
                   the web interface and the source files at the 
                   same time.
        
        
        @param path   : Paths in which we are installing
                        the web interface.
        
        @param currentlyUsedLanguages: Languages currently set to be 
                                       displayed in the web interface
        
        @precondition : copyFiles method MUST have been called
                        prior to calling this method.
         
    """

    statsPaths = StatsPaths()

    #Links to files in the main application language.
    statsPaths.setPaths(LanguageTools.getMainApplicationLanguage())

    #index.html
    commands.getstatusoutput("ln -s %s/index.html %s/index.html" %
                             (statsPaths.STATSWEBPAGES, path))
    #print "ln -s %s/index.html %s/index.html" %( statsPaths.STATSWEBPAGES, path )

    # .../path/bottom.html  Only on, multilingual fomr of this file exists.
    commands.getstatusoutput("ln -s %s/bottom.html %s/bottom.html" %
                             (statsPaths.STATSWEBPAGES, path))
    #print "ln -s %s/bottom.html %s/bottom.html" %(statsPaths.STATSWEBPAGES , path )

    # .../path/bottom.html  Only on, multilingual fomr of this file exists.
    commands.getstatusoutput(
        "ln -s %s/top_%s.html %s/top.html" %
        (statsPaths.STATSWEBPAGES, LanguageTools.getMainApplicationLanguage(),
         path))
    #print "ln -s %s/bottom.html %s/bottom.html" %(statsPaths.STATSWEBPAGES , path )

    # .../path/pxStats
    commands.getstatusoutput("ln -s %s %s/pxStats" %
                             (statsPaths.STATSROOT, path))
    #print  "ln -s %s %s/pxStats" %( statsPaths.STATSROOT, path  )

    #.../path/images
    commands.getstatusoutput("ln -s %s/images %s/images" %
                             (statsPaths.STATSWEBPAGES, path))
    #print "ln -s %s/images %s/images" %( statsPaths.STATSWEBPAGES, path )

    #.../path/scripts/cgi-bin
    commands.getstatusoutput("ln -s  %s %s/scripts/cgi-bin " %
                             (statsPaths.STATSWEBPAGESGENERATORS, path))
    #print "ln -s  %s %s/scripts/cgi-bin "%(  statsPaths.STATSWEBPAGESGENERATORS, path )

    for language in currentlyUsedLanguages:

        statsPaths.setPaths(language)

        # .../path/html_lang
        commands.getstatusoutput("ln -s %s/html %s/html_%s" %
                                 (statsPaths.STATSWEBPAGES, path, language))
        #print "ln -s %s/html %s/html_%s" %( statsPaths.STATSWEBPAGES, path, language )

        # .../path/archives_lang
        commands.getstatusoutput(
            "ln -s %s %s/archives_%s" %
            (statsPaths.STATSGRAPHSARCHIVES[:-1], path, language))
        #print "ln -s %s %s/archives_%s" %( statsPaths.STATSGRAPHSARCHIVES[:-1], path, language  )

        # .../paths/html_lang/archives
        commands.getstatusoutput(
            "ln -s %s %s/html_%s/archives" %
            (statsPaths.STATSGRAPHSARCHIVES[:-1], path, language))
        #print "ln -s %s %s/html_%s/archives" %( statsPaths.STATSGRAPHSARCHIVES[:-1], path, language  )

        #.../paths/html_lang/csvFiles
        commands.getstatusoutput(
            "ln -s %s %s/html_%s/%s" %
            (statsPaths.STATSCSVFILES[:-1], path, language,
             os.path.basename(statsPaths.STATSCSVFILES)))

        # .../path/top_lang.html
        commands.getstatusoutput(
            "ln -s %s/top_%s.html %s/top_%s.html" %
            (statsPaths.STATSWEBPAGES, language, path, language))
        #print "ln -s %s/top_%s.html %s/top_%s.html" %( statsPaths.STATSWEBPAGES, language, path, language )

        #.../path/scripts/js_lang
        commands.getstatusoutput("ln -s %s/js  %s/scripts/js_%s " %
                                 (statsPaths.STATSWEBPAGES, path, language))
        #print "ln -s %s/js  %s/scripts/js_%s " %( statsPaths.STATSWEBPAGES, path, language )

        commands.getstatusoutput(
            "ln -s %s/html/howTo_%s.html %s/html_%s/docPages/links/howTo_%s.html"
            % (statsPaths.STATSDOC, language, path, language, language))

        commands.getstatusoutput(
            "ln -s %s/html/installation_%s.html %s/html_%s/docPages/links/installation_%s.html"
            % (statsPaths.STATSDOC, language, path, language, language))

        commands.getstatusoutput(
            "ln -s %s/html/monitoringDoc_%s.html %s/html_%s/docPages/links/monitoringDoc_%s.html"
            % (statsPaths.STATSDOC, language, path, language, language))

        commands.getstatusoutput(
            "ln -s %s/html/translationDoc_%s.html %s/html_%s/docPages/links/translationDoc_%s.html"
            % (statsPaths.STATSDOC, language, path, language, language))

        commands.getstatusoutput(
            "ln -s %s/html/developersDoc_%s.html %s/html_%s/docPages/links/developersDoc_%s.html"
            % (statsPaths.STATSDOC, language, path, language, language))

        commands.getstatusoutput(
            "ln -s %s/html/installation_%s.html %s/html_%s/docPages/links/installation_%s.html"
            % (statsPaths.STATSDOC, language, path, language, language))

        commands.getstatusoutput(
            "ln -s %s/html/rrdToolDoc_%s.html %s/html_%s/docPages/links/rrdToolDoc_%s.html"
            % (statsPaths.STATSDOC, language, path, language, language))

        commands.getstatusoutput(
            "ln -s %s/html/troubleshooting_%s.html %s/html_%s/docPages/links/troubleshooting_%s.html"
            % (statsPaths.STATSDOC, language, path, language, language))

        commands.getstatusoutput(
            "ln -s %s/html/images %s/html_%s/docPages/links/images" %
            (statsPaths.STATSDOC, path, language))
Пример #21
0
def updateGroupedRoundRobinDatabases(infos, logger=None):
    """
        @summary : This method is to be used to update the database 
                   used to stored the merged data of a group.
         
    """

    endTime = StatsDateLib.getSecondsSinceEpoch(infos.endTime)

    tempRRDFileName = RrdUtilities.buildRRDFileName(
        _("errors"),
        clients=infos.group,
        machines=infos.machines,
        fileType=infos.fileTypes[0])
    startTime = RrdUtilities.getDatabaseTimeOfUpdate(tempRRDFileName,
                                                     infos.fileTypes[0])

    if startTime == 0:
        startTime = StatsDateLib.getSecondsSinceEpoch(
            StatsDateLib.getIsoTodaysMidnight(infos.endTime))

    timeSeperators = getTimeSeperatorsBasedOnAvailableMemory(
        StatsDateLib.getIsoFromEpoch(startTime),
        StatsDateLib.getIsoFromEpoch(endTime), infos.clients,
        infos.fileTypes[0], infos.machines)

    #print timeSeperators

    for i in xrange(0, len(timeSeperators),
                    2):  #timeseperators should always be coming in pairs

        startTime = StatsDateLib.getSecondsSinceEpoch(timeSeperators[i])
        dataPairs = getPairs(infos.clients, infos.machines, infos.fileTypes[0],
                             timeSeperators[i], timeSeperators[i + 1],
                             infos.group, logger)

        for dataType in dataPairs:

            translatedDataType = LanguageTools.translateTerm(
                dataType, 'en', LanguageTools.getMainApplicationLanguage(),
                CURRENT_MODULE_ABS_PATH)
            rrdFileName = RrdUtilities.buildRRDFileName(
                dataType=translatedDataType,
                clients=infos.group,
                groupName=infos.group,
                machines=infos.machines,
                fileType=infos.fileTypes[0],
                usage="group")

            if not os.path.isfile(rrdFileName):
                createRoundRobinDatabase(rrdFileName, startTime, dataType)

            if endTime > startTime:
                j = 0
                while dataPairs[dataType][j][0] < startTime and j < len(
                        dataPairs[dataType]):
                    #print "going over : %s startime was :%s" %(dataPairs[ dataType ][j][0], startTime)
                    j = j + 1

                for k in range(j, len(dataPairs[dataType])):
                    #print "updating %s at %s" %(rrdFileName, int( dataPairs[ dataType ][k][0] ))
                    try:
                        rrdtool.update(
                            rrdFileName,
                            '%s:%s' % (int(dataPairs[dataType][k][0]),
                                       dataPairs[dataType][k][1]))
                    except:
                        if logger != None:
                            try:
                                logger.warning(
                                    "Could not update %s. Last update was more recent than %s "
                                    % (rrdFileName,
                                       int(dataPairs[dataType][k][0])))
                            except:
                                pass
                        pass

            else:
                #print "endTime %s was not bigger than start time %s" %( endTime, startTime )
                if logger != None:
                    try:
                        logger.warning(
                            _("This database was not updated since it's last update was more recent than specified date : %s"
                              ) % rrdFileName)
                    except:
                        pass

    RrdUtilities.setDatabaseTimeOfUpdate(tempRRDFileName, infos.fileTypes[0],
                                         endTime)
Пример #22
0
    def buildRRDFileName( dataType = 'errors', clients = None , machines = None,\
                          groupName = "", fileType = "", usage = "regular"  ):
        """
            @summary : Returns the name of the round robin database bases on the parameters.
        
            @param dataType: byteocunt, errors, filecount, filesOverMaxLatency and latency.
            
            @param clients: list of clients/sources names. If only one is wanted, include it in a list.
            
            @param machines: list of machines associated with client/sources names. If only one is wanted, include it in a list.
            
            @param fileType : Useless for regular and group databases. Obligatory for totalForMachine databases. 
            
            @param groupName: optional. Use only if the list of client/sources has a KNOWN group name.
            
            @param usage: regular, group or totalForMachine.
        
            @return: Returns the name of the round robin database bases on the parameters.
        
        """

        _ = LanguageTools.getTranslatorForModule(
            CURRENT_MODULE_ABS_PATH,
            LanguageTools.getMainApplicationLanguage())

        clients = clients or ['client1', 'client1']
        machines = machines or ['machine1', 'machine2']

        fileName = ""

        combinedMachineName = ""
        for machine in machines:
            combinedMachineName = combinedMachineName + machine

        combinedClientsName = ""
        for client in clients:
            combinedClientsName = combinedClientsName + client

        if len(clients) == 1:
            if usage == "regular":
                fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" % (
                    dataType, combinedClientsName, combinedMachineName)

            elif usage == "group":

                fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" % (
                    dataType, groupName, combinedMachineName)

            elif usage == "totalForMachine":
                fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" % (
                    dataType, fileType, combinedMachineName)

        else:

            if usage == "regular":
                fileName = STATSPATHS.STATSCURRENTDB + _(
                    "%s/combined/%s_%s") % (dataType, combinedClientsName,
                                            combinedMachineName)

            elif usage == "group":

                #fileName = STATSPATHS.STATSCURRENTDB + _("%s/combined/%s_%s") %( dataType, groupName, combinedMachineName )
                try:
                    existingFiles = os.listdir(STATSPATHS.STATSCURRENTDB +
                                               "%s/combined/" % (dataType))

                    for file in existingFiles:
                        if fnmatch.fnmatch(file, groupName + "*"):
                            fileName = file
                            break
                except:
                    pass

                if fileName == "":  #no preexisitng file exist for this group
                    fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" % (
                        dataType, groupName, combinedMachineName)
                else:  #else
                    fileName = STATSPATHS.STATSCURRENTDB + "%s/combined/" % (
                        dataType) + fileName

            elif usage == "totalForMachine":
                fileName = STATSPATHS.STATSCURRENTDB + _(
                    "%s/combined/%s_%s") % (dataType, fileType,
                                            combinedMachineName)

        #print "before ", fileName
        #fileName = fileName.replace("année","year").replace("nbreDeBytes","bytecount").replace("nbreDeFichiers","filecount").replace("erreurs","errors").replace("latence","latency").replace("fichiersAvecLatenceInnacceptable","filesOverMaxLatency").replace("heures","hours").replace("mois","month").replace("jour","day").replace("","")
        #print "after ", fileName

        return fileName
Пример #23
0
def addOptions(parser):
    """
        @summary : This method is used to add all available options to the option parser.
        
    """

    parser.add_option("-c",
                      "--clients",
                      action="store",
                      type="string",
                      dest="clients",
                      default="",
                      help=_("Clients' names"))

    parser.add_option("--copy",
                      action="store_true",
                      dest="copy",
                      default=False,
                      help=_("Create a copy file for the generated image."))

    parser.add_option( "--combineClients", action="store_true", dest = "combineClients", default=False, \
                       help=_("Combine the data of all client into a single graphics for each graphic type.") )

    parser.add_option("-d", "--date", action="store", type="string", dest="currentTime", \
                      default=StatsDateLib.getIsoFromEpoch( time.time() ), help=_("Decide current time. Usefull for testing.") )

    parser.add_option("-f", "--fileType", action="store", type="string", dest="fileType", default='tx',\
                       help=_("Type of log files wanted.") )

    parser.add_option(
        "-g",
        "--groupName",
        action="store",
        type="string",
        dest="groupName",
        default="",
        help=
        _("Specify a name for the combined graphics of numerous client/sources. Note : requires the --combinedClients options to work."
          ))

    parser.add_option( "-m", "--machines", action="store", type="string", dest="machines", default=LOCAL_MACHINE,\
                        help = _("Machines for wich you want to collect data.") )

    parser.add_option("-n", "--collectUpToNow", action="store_true", dest = "collectUpToNow", default=False, \
                      help=_("Collect data up to current second.") )

    parser.add_option("-o", "--outputLanguage", action="store", type="string", dest="outputLanguage",\
                       default=LanguageTools.getMainApplicationLanguage(), help = _("Language in which the graphics are outputted.") )

    parser.add_option("-p", "--products", action="store", type = "string", dest = "productTypes", default=_("All"), \
                      help=_("Specific product types to look for in the data collected.") )

    parser.add_option("-s",
                      "--span",
                      action="store",
                      type="int",
                      dest="timespan",
                      default=12,
                      help=_("timespan( in hours) of the graphic."))

    parser.add_option("-t",
                      "--types",
                      type="string",
                      dest="types",
                      default=_("All"),
                      help=_("Types of data to look for."))
Пример #24
0
def createSymbolicLinks( path, currentlyUsedLanguages ):
    """
        @summary : create symbolic links from web-interface to general 
                   pxStats package.
                   
                   This will prevent us from having to sync both
                   sides all the time. i.e updating pxStats
                   ( via svn update for example) will update both 
                   the web interface and the source files at the 
                   same time.
        
        
        @param path   : Paths in which we are installing
                        the web interface.
        
        @param currentlyUsedLanguages: Languages currently set to be 
                                       displayed in the web interface
        
        @precondition : copyFiles method MUST have been called
                        prior to calling this method.
         
    """
    
    statsPaths = StatsPaths()
    
    #Links to files in the main application language.
    statsPaths.setPaths( LanguageTools.getMainApplicationLanguage() )
    
    #index.html   
    commands.getstatusoutput( "ln -s %s/index.html %s/index.html" %( statsPaths.STATSWEBPAGES, path ) )
    #print "ln -s %s/index.html %s/index.html" %( statsPaths.STATSWEBPAGES, path ) 
    
    # .../path/bottom.html  Only on, multilingual fomr of this file exists.
    commands.getstatusoutput( "ln -s %s/bottom.html %s/bottom.html" %(statsPaths.STATSWEBPAGES , path )  )
    #print "ln -s %s/bottom.html %s/bottom.html" %(statsPaths.STATSWEBPAGES , path )
    
    # .../path/bottom.html  Only on, multilingual fomr of this file exists.
    commands.getstatusoutput( "ln -s %s/top_%s.html %s/top.html" %(statsPaths.STATSWEBPAGES , LanguageTools.getMainApplicationLanguage(),  path )  )
    #print "ln -s %s/bottom.html %s/bottom.html" %(statsPaths.STATSWEBPAGES , path )
    
    # .../path/pxStats
    commands.getstatusoutput( "ln -s %s %s/pxStats" %( statsPaths.STATSROOT, path  ) )
    #print  "ln -s %s %s/pxStats" %( statsPaths.STATSROOT, path  )
    
    #.../path/images   
    commands.getstatusoutput( "ln -s %s/images %s/images" %( statsPaths.STATSWEBPAGES, path ) )
    #print "ln -s %s/images %s/images" %( statsPaths.STATSWEBPAGES, path )
    
    #.../path/scripts/cgi-bin
    commands.getstatusoutput( "ln -s  %s %s/scripts/cgi-bin "%(  statsPaths.STATSWEBPAGESGENERATORS, path ) )
    #print "ln -s  %s %s/scripts/cgi-bin "%(  statsPaths.STATSWEBPAGESGENERATORS, path )
    
    
    
    
    for language in currentlyUsedLanguages:
        
        statsPaths.setPaths( language )
                
        # .../path/html_lang
        commands.getstatusoutput( "ln -s %s/html %s/html_%s" %( statsPaths.STATSWEBPAGES, path, language ) )
        #print "ln -s %s/html %s/html_%s" %( statsPaths.STATSWEBPAGES, path, language ) 
        
        # .../path/archives_lang 
        commands.getstatusoutput( "ln -s %s %s/archives_%s" %( statsPaths.STATSGRAPHSARCHIVES[:-1], path, language  ) )
        #print "ln -s %s %s/archives_%s" %( statsPaths.STATSGRAPHSARCHIVES[:-1], path, language  )
        
        # .../paths/html_lang/archives
        commands.getstatusoutput( "ln -s %s %s/html_%s/archives" %( statsPaths.STATSGRAPHSARCHIVES[:-1], path, language  ) )
        #print "ln -s %s %s/html_%s/archives" %( statsPaths.STATSGRAPHSARCHIVES[:-1], path, language  )
        
        #.../paths/html_lang/csvFiles
        commands.getstatusoutput( "ln -s %s %s/html_%s/%s" %( statsPaths.STATSCSVFILES[:-1], path, language, os.path.basename( statsPaths.STATSCSVFILES )  ) )
        
        # .../path/top_lang.html
        commands.getstatusoutput( "ln -s %s/top_%s.html %s/top_%s.html" %( statsPaths.STATSWEBPAGES, language, path, language )  ) 
        #print "ln -s %s/top_%s.html %s/top_%s.html" %( statsPaths.STATSWEBPAGES, language, path, language )
    
        #.../path/scripts/js_lang
        commands.getstatusoutput( "ln -s %s/js  %s/scripts/js_%s " %( statsPaths.STATSWEBPAGES, path, language ) )   
        #print "ln -s %s/js  %s/scripts/js_%s " %( statsPaths.STATSWEBPAGES, path, language )

        commands.getstatusoutput( "ln -s %s/html/howTo_%s.html %s/html_%s/docPages/links/howTo_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
        
        commands.getstatusoutput( "ln -s %s/html/installation_%s.html %s/html_%s/docPages/links/installation_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
        
        commands.getstatusoutput( "ln -s %s/html/monitoringDoc_%s.html %s/html_%s/docPages/links/monitoringDoc_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
        
        commands.getstatusoutput( "ln -s %s/html/translationDoc_%s.html %s/html_%s/docPages/links/translationDoc_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
        
        commands.getstatusoutput( "ln -s %s/html/developersDoc_%s.html %s/html_%s/docPages/links/developersDoc_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
        
        commands.getstatusoutput( "ln -s %s/html/installation_%s.html %s/html_%s/docPages/links/installation_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
        
        commands.getstatusoutput( "ln -s %s/html/rrdToolDoc_%s.html %s/html_%s/docPages/links/rrdToolDoc_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
        
        commands.getstatusoutput( "ln -s %s/html/troubleshooting_%s.html %s/html_%s/docPages/links/troubleshooting_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )        
        
        commands.getstatusoutput( "ln -s %s/html/images %s/html_%s/docPages/links/images" %(statsPaths.STATSDOC,path,language )   )     
Пример #25
0
#
##############################################################################################
"""

import commands, os, sys

sys.path.append(1, os.path.dirname(os.path.abspath(__file__)) + "/../../../")

from optparse import OptionParser
from pxStats.lib.StatsPaths import StatsPaths
from pxStats.lib.LanguageTools import LanguageTools
"""
    Small function that adds pxlib to the environment path.  
"""
STATSPATHS = StatsPaths()
STATSPATHS.setPaths(LanguageTools.getMainApplicationLanguage())
sys.path.append(STATSPATHS.PXLIB)
"""
    Imports
    Logger requires pxlib 
"""
from Logger import *

LOCAL_MACHINE = os.uname()[1]
CURRENT_MODULE_ABS_PATH = os.path.abspath(__file__).replace(".pyc", ".py")


def getOptionsFromParser(parser):
    """
        
        This method parses the argv received when the program was called
Пример #26
0
def updateRoundRobinDatabases(client,
                              machines,
                              fileType,
                              endTime,
                              logger=None):
    """
        @summary : This method updates every database linked to a certain client.
        
        @note : Database types are linked to the filetype associated with the client.
        
    """

    combinedMachineName = ""
    combinedMachineName = combinedMachineName.join(
        [machine for machine in machines])

    tempRRDFileName = RrdUtilities.buildRRDFileName(dataType=_("errors"),
                                                    clients=[client],
                                                    machines=machines,
                                                    fileType=fileType)
    startTime = RrdUtilities.getDatabaseTimeOfUpdate(tempRRDFileName, fileType)

    if startTime == 0:
        startTime = StatsDateLib.getSecondsSinceEpoch(
            StatsDateLib.getIsoTodaysMidnight(endTime))

    endTime = StatsDateLib.getSecondsSinceEpoch(endTime)

    timeSeperators = getTimeSeperatorsBasedOnAvailableMemory(
        StatsDateLib.getIsoFromEpoch(startTime),
        StatsDateLib.getIsoFromEpoch(endTime), [client], fileType, machines)

    for i in xrange(len(timeSeperators) - 1):

        dataPairs = getPairs([client],
                             machines,
                             fileType,
                             timeSeperators[i],
                             timeSeperators[i + 1],
                             groupName="",
                             logger=logger)

        for dataType in dataPairs:

            translatedDataType = LanguageTools.translateTerm(
                dataType, 'en', LanguageTools.getMainApplicationLanguage(),
                CURRENT_MODULE_ABS_PATH)

            rrdFileName = RrdUtilities.buildRRDFileName(
                dataType=translatedDataType,
                clients=[client],
                machines=machines,
                fileType=fileType)

            if not os.path.isfile(rrdFileName):
                createRoundRobinDatabase(databaseName=rrdFileName,
                                         startTime=startTime,
                                         dataType=dataType)

            if endTime > startTime:
                j = 0
                while dataPairs[dataType][j][0] < startTime:
                    j = j + 1

                for k in range(j, len(dataPairs[dataType])):
                    try:
                        rrdtool.update(
                            rrdFileName,
                            '%s:%s' % (int(dataPairs[dataType][k][0]),
                                       dataPairs[dataType][k][1]))
                    except:
                        if logger != None:
                            try:
                                logger.warning(
                                    "Could not update %s. Last update was more recent than %s "
                                    % (rrdFileName,
                                       int(dataPairs[dataType][k][0])))
                            except:
                                pass
                        pass

                if logger != None:
                    try:
                        logger.info(
                            _("Updated  %s db for %s in db named : %s") %
                            (dataType, client, rrdFileName))
                    except:
                        pass
            else:
                if logger != None:
                    try:
                        logger.warning(
                            _("This database was not updated since it's last update was more recent than specified date : %s"
                              ) % rrdFileName)
                    except:
                        pass

            RrdUtilities.setDatabaseTimeOfUpdate(rrdFileName, fileType,
                                                 endTime)