Example #1
0
    def initialize(self):

        self.systemLoggingDB = SystemLoggingDB()

        self.notification = NotificationClient()

        userList = self.am_getOption("Reviewer", [])

        self.log.debug("Users to be notified:", ', '.join(userList))

        mailList = []
        for user in userList:
            mail = getUserOption(user, 'Email', '')
            if not mail:
                self.log.warn("Could not get user's mail", user)
            else:
                mailList.append(mail)

        if not mailList:
            mailList = Operations().getValue('EMail/Logging', [])

        if not len(mailList):
            errString = "There are no valid users in the mailing list"
            varString = "[" + ','.join(userList) + "]"
            self.log.warn(errString, varString)

        self.log.info("List of mails to be notified", ','.join(mailList))

        self._mailAddress = mailList
        self._subject = 'New error messages were entered in the SystemLoggingDB'
        return S_OK()
Example #2
0
class SystemLoggingDBCleaner(AgentModule):
    def initialize(self):

        self.SystemLoggingDB = SystemLoggingDB()

        self.period = int(self.am_getOption("RemoveDate", '30')) * day

        return S_OK()

    def execute(self):
        """ The main agent execution method
    """
        limitDate = toString(dateTime() - self.period)
        limitDate = limitDate[:limitDate.find('.')]

        commonString = 'FROM MessageRepository WHERE messageTime <'
        cmd = "SELECT count(*) %s '%s'" % (commonString, limitDate)
        result = self.SystemLoggingDB._query(cmd)
        if not result['OK']:
            return result
        recordsToErase = result['Value'][0][0]

        if recordsToErase == 0:
            self.log.info('No records to erase')
            return S_OK('No records to erase')
        else:
            cmd = "DELETE LOW_PRIORITY %s '%s'" % (commonString, limitDate)
            result = self.SystemLoggingDB._update(cmd)
            if not result['OK']:
                self.log.error('Could not erase the requested records',
                               'those older than %s' % limitDate)
                return result
            else:
                self.log.info('%s records have been erased' % recordsToErase)
                return result
Example #3
0
  def initialize(self):
 
    self.SystemLoggingDB = SystemLoggingDB()

    self.notification=NotificationClient()
        
    userString = self.am_getOption( "Reviewer", 'mseco' )
    
    self.log.debug( "Users to be notified", ": " + userString )
   
    userList = List.fromChar( userString, ",")
    
    mailList = []
    for user in userList:
      retval = gConfig.getOption( "/Registry/Users/" + user + "/Email" )
      if not retval['OK']:
        self.log.warn( "Could not get user's mail", retval['Message'] )
      else:
        mailList.append( retval['Value'] )
        
    if not mailList:
      mailList = gConfig.getValue( '/Operations/EMail/Logging', [] )

    if not len(mailList):
      errString = "There are no valid users in the list"
      varString = "[" + ','.join( userList ) + "]"
      self.log.error( errString, varString )
      return S_ERROR( errString + varString )
    
    self.log.info( "List of mails to be notified", ','.join( mailList ) )
   
    self._mailAddress = mailList
    self._subject = 'New error messages were entered in the SystemLoggingDB'
    return S_OK()
Example #4
0
    def initialize(self):

        self.SystemLoggingDB = SystemLoggingDB()

        self.period = int(self.am_getOption("RemoveDate", '30')) * day

        return S_OK()
Example #5
0
  def test_addAndRemove(self):
    """ Some test cases
    """

    systemName = 'TestSystem'
    subSystemName = 'TestSubSystem'
    level = 10
    time = toString()
    msgTest = 'Hello'
    variableText = time
    frameInfo = ""
    message = tupleToMessage((systemName, level, time, msgTest, variableText, frameInfo, subSystemName))
    site = 'somewehere'
    longSite = 'somewehere1234567890123456789012345678901234567890123456789012345678901234567890'
    nodeFQDN = '127.0.0.1'
    userDN = 'Yo'
    userGroup = 'Us'
    remoteAddress = 'elsewhere'

    records = 10

    db = SystemLoggingDB()
    res = db._connect()
    self.assertTrue(res['OK'])

    gLogger.info('\n Inserting some records\n')
    for k in xrange(records):
      result = db.insertMessage(message, site, nodeFQDN, userDN, userGroup, remoteAddress)
      self.assertTrue(result['OK'])
      self.assertEqual(result['lastRowId'], k + 1)
      self.assertEqual(result['Value'], 1)

    result = db._queryDB(showFieldList=['SiteName'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], site)

    result = db._queryDB(showFieldList=['SystemName'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], systemName)

    result = db._queryDB(showFieldList=['SubSystemName'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], subSystemName)

    result = db._queryDB(showFieldList=['OwnerGroup'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], userGroup)

    result = db._queryDB(showFieldList=['FixedTextString'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], msgTest)

    result = db._queryDB(showFieldList=['VariableText', 'SiteName'], count=True, groupColumn='VariableText')
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][1], site)
    self.assertEqual(result['Value'][0][2], records)

    result = db.insertMessage(message, longSite, nodeFQDN, userDN, userGroup, remoteAddress)
    self.assertFalse(result['OK'])
Example #6
0
def initializeSystemLoggingHandler(serviceInfo):
    """ Check that we can connect to the DB and that the tables are properly created or updated
  """
    global gLogDB
    gLogDB = SystemLoggingDB()
    res = gLogDB._connect()
    if not res['OK']:
        return res

    return S_OK()
def initializeSystemLoggingHandler( serviceInfo ):
  """ Check that we can connect to the DB and that the tables are properly created or updated
  """
  global gLogDB
  gLogDB = SystemLoggingDB()
  res = gLogDB._connect()
  if not res['OK']:
    return res

  return S_OK()
Example #8
0
def initializeSystemLoggingHandler( serviceInfo ):
  """ Check that we can connect to the DB and that the tables are properly created or updated
  """
  global gLogDB
  gLogDB = SystemLoggingDB()
  res = gLogDB._connect()
  if not res['OK']:
    return res
  res = gLogDB._checkTable()
  if not res['OK'] and not res['Message'] == 'The requested table already exist':
    return res

  return S_OK()
Example #9
0
def initializeSystemLoggingHandler(serviceInfo):
    """ Check that we can connect to the DB and that the tables are properly created or updated

      :param dict serviceInfo: service information dictionary

      :return: S_OK()/S_ERROR()
  """
    global gLogDB
    gLogDB = SystemLoggingDB()
    res = gLogDB._connect()
    if not res['OK']:
        return res

    return S_OK()
  def initialize(self):
     
    self.SystemLoggingDB = SystemLoggingDB()
 
    self.period = int( self.am_getOption( "RemoveDate", '30' ) ) * day
    
    return S_OK()	
  def initialize( self ):

    self.systemLoggingDB = SystemLoggingDB()

    self.notification = NotificationClient()

    userList = self.am_getOption( "Reviewer", [] )

    self.log.debug( "Users to be notified:", ', '.join( userList ) )

    mailList = []
    for user in userList:
      mail = getUserOption( user, 'Email', '' )
      if not mail:
        self.log.warn( "Could not get user's mail", user )
      else:
        mailList.append( mail )

    if not mailList:
      mailList = Operations().getValue( 'EMail/Logging', [] )

    if not len( mailList ):
      errString = "There are no valid users in the mailing list"
      varString = "[" + ','.join( userList ) + "]"
      self.log.warn( errString, varString )

    self.log.info( "List of mails to be notified", ','.join( mailList ) )

    self._mailAddress = mailList
    self._subject = 'New error messages were entered in the SystemLoggingDB'
    return S_OK()
Example #12
0
  def initialize(self):

    self.systemLoggingDB = SystemLoggingDB()

    self.agentName = self.am_getModuleParam('fullName')

    self.notification = NotificationClient()

    mailList = self.am_getOption("MailList", [])

    userList = self.am_getOption("Reviewer", [])

    self.log.debug("Users to be notified:", ', '.join(userList))

    for user in userList:
      mail = getUserOption(user, 'Email', '')
      if not mail:
        self.log.warn("Could not get user's mail", user)
      else:
        mailList.append(mail)

    if not mailList:
      mailList = Operations().getValue('EMail/Logging', [])

    if not mailList:
      errString = "There are no valid users in the list of email where to send the report"
      errString += "\nPlease specify some in Operations/<default>/EMail/Logging"
      varString = "[" + ','.join(userList) + "]"
      self.log.error(errString, varString)
      return S_ERROR(errString + varString)

    self.log.info("List of mails to be notified", ','.join(mailList))
    self._mailAddress = mailList
    self._threshold = int(self.am_getOption('Threshold', 10))

    self.__days = self.am_getOption('QueryPeriod', 7)
    self._period = int(self.__days) * day
    self._limit = int(self.am_getOption('NumberOfErrors', 10))

    string = "The %i most common errors in the SystemLoggingDB" % self._limit
    self._subject = string + " for the last %s days" % self.__days
    return S_OK()
Example #13
0
    def initialize(self):

        self.SystemLoggingDB = SystemLoggingDB()

        self.agentName = self.am_getModuleParam('fullName')

        self.notification = NotificationClient()

        mailList = self.am_getOption("MailList", [])

        userString = self.am_getOption("Reviewer", 'mseco')
        userList = List.fromChar(userString, ",")
        self.log.debug("Users to be notified", ": " + userString)
        for user in userList:
            retval = gConfig.getOption("/Registry/Users/" + user + "/email")
            if not retval['OK']:
                self.log.warn("Could not get user's mail", retval['Message'])
            else:
                mailList.append(retval['Value'])

        if not mailList:
            mailList = gConfig.getValue('/Operations/EMail/Logging', [])

        if not len(mailList):
            errString = "There are no valid users in the list"
            varString = "[" + ','.join(userList) + "]"
            self.log.error(errString, varString)
            return S_ERROR(errString + varString)

        self.log.info("List of mails to be notified", ','.join(mailList))
        self._mailAddress = mailList
        self._threshold = int(self.am_getOption('Threshold', 10))

        self.__days = self.am_getOption('QueryPeriod', 7)
        self._period = int(self.__days) * day
        self._limit = int(self.am_getOption('NumberOfErrors', 10))

        string = "The %i most common errors in the SystemLoggingDB" % self._limit
        self._subject = string + " for the last %s days" % self.__days
        return S_OK()
class SystemLoggingDBCleaner(AgentModule):


  def initialize(self):
     
    self.SystemLoggingDB = SystemLoggingDB()
 
    self.period = int( self.am_getOption( "RemoveDate", '30' ) ) * day
    
    return S_OK()	

  def execute(self):
    """ The main agent execution method
    """
    limitDate = toString( dateTime() - self.period )
    limitDate = limitDate[:limitDate.find('.')]

    commonString = 'FROM MessageRepository WHERE messageTime <'
    cmd = "SELECT count(*) %s '%s'" % ( commonString, limitDate )
    result = self.SystemLoggingDB._query( cmd )
    if not result['OK']: 
      return result
    recordsToErase=result['Value'][0][0]

    if recordsToErase == 0:
      self.log.info('No records to erase')
      return S_OK('No records to erase')
    else:
      cmd = "DELETE LOW_PRIORITY %s '%s'" % ( commonString, limitDate )
      result =  self.SystemLoggingDB._update( cmd )
      if not result['OK']:
        self.log.error( 'Could not erase the requested records',
                        'those older than %s' % limitDate )
        return result
      else:
        self.log.info('%s records have been erased' % recordsToErase )
        return result
  def initialize(self):

    self.systemLoggingDB = SystemLoggingDB()

    self.agentName = self.am_getModuleParam('fullName')

    self.notification = NotificationClient()

    mailList = self.am_getOption("MailList", [])

    userList = self.am_getOption("Reviewer", [])

    self.log.debug("Users to be notified:", ', '.join(userList))

    for user in userList:
      mail = getUserOption(user, 'Email', '')
      if not mail:
        self.log.warn("Could not get user's mail", user)
      else:
        mailList.append(mail)

    if not mailList:
      mailList = Operations().getValue('EMail/Logging', [])

    if not mailList:
      errString = "There are no valid users in the list of email where to send the report"
      errString += "\nPlease specify some in Operations/<default>/EMail/Logging"
      varString = "[" + ','.join(userList) + "]"
      self.log.error(errString, varString)
      return S_ERROR(errString + varString)

    self.log.info("List of mails to be notified", ','.join(mailList))
    self._mailAddress = mailList
    self._threshold = int(self.am_getOption('Threshold', 10))

    self.__days = self.am_getOption('QueryPeriod', 7)
    self._period = int(self.__days) * day
    self._limit = int(self.am_getOption('NumberOfErrors', 10))

    string = "The %i most common errors in the SystemLoggingDB" % self._limit
    self._subject = string + " for the last %s days" % self.__days
    return S_OK()
    def initialize(self):

        self.systemLoggingDB = SystemLoggingDB()

        self.agentName = self.am_getModuleParam("fullName")

        self.notification = NotificationClient()

        mailList = self.am_getOption("MailList", [])

        userList = self.am_getOption("Reviewer", [])

        self.log.debug("Users to be notified:", ", ".join(userList))

        for user in userList:
            mail = getUserOption(user, "Email", "")
            if not mail:
                self.log.warn("Could not get user's mail", user)
            else:
                mailList.append(mail)

        if not mailList:
            mailList = Operations().getValue("EMail/Logging", [])

        if not len(mailList):
            errString = "There are no valid users in the list"
            varString = "[" + ",".join(userList) + "]"
            self.log.error(errString, varString)
            return S_ERROR(errString + varString)

        self.log.info("List of mails to be notified", ",".join(mailList))
        self._mailAddress = mailList
        self._threshold = int(self.am_getOption("Threshold", 10))

        self.__days = self.am_getOption("QueryPeriod", 7)
        self._period = int(self.__days) * day
        self._limit = int(self.am_getOption("NumberOfErrors", 10))

        string = "The %i most common errors in the SystemLoggingDB" % self._limit
        self._subject = string + " for the last %s days" % self.__days
        return S_OK()
  def initialize( self ):
     
    self.SystemLoggingDB = SystemLoggingDB()
    
    self.agentName = self.am_getModuleParam( 'fullName' )

    self.notification = NotificationClient()

    mailList = self.am_getOption( "MailList", [] )

    userString = self.am_getOption( "Reviewer", 'mseco' )
    userList = List.fromChar( userString, "," )
    self.log.debug( "Users to be notified", ": " + userString )
    for user in userList:
      retval = gConfig.getOption( "/Registry/Users/" + user + "/email" )
      if not retval['OK']:
        self.log.warn( "Could not get user's mail", retval['Message'] )
      else:
        mailList.append( retval['Value'] )
    
    if not mailList:
      mailList = gConfig.getValue( '/Operations/EMail/Logging', [] )

    if not len( mailList ):
      errString = "There are no valid users in the list"
      varString = "[" + ','.join( userList ) + "]"
      self.log.error( errString, varString )
      return S_ERROR( errString + varString )
    
    self.log.info("List of mails to be notified", ','.join(mailList))
    self._mailAddress = mailList
    self._threshold = int( self.am_getOption( 'Threshold', 10 ) )
    
    self.__days = self.am_getOption( 'QueryPeriod',7 )
    self._period=int( self.__days ) * day
    self._limit = int ( self.am_getOption( 'NumberOfErrors', 10 ) )
    
    string = "The %i most common errors in the SystemLoggingDB" %  self._limit
    self._subject = string + " for the last %s days" % self.__days
    return S_OK()
Example #18
0
  def test_addAndRemove(self):
    """ Some test cases
    """

    systemName = 'TestSystem'
    subSystemName = 'TestSubSystem'
    level = 10
    time = toString()
    msgTest = 'Hello'
    variableText = time
    frameInfo = ""
    message = tupleToMessage((systemName, level, time, msgTest, variableText, frameInfo, subSystemName))
    site = 'somewehere'
    longSite = 'somewehere1234567890123456789012345678901234567890123456789012345678901234567890'
    nodeFQDN = '127.0.0.1'
    userDN = 'Yo'
    userGroup = 'Us'
    remoteAddress = 'elsewhere'

    records = 10

    db = SystemLoggingDB()
    res = db._connect()
    self.assertTrue(res['OK'])

    gLogger.info('\n Inserting some records\n')
    for k in xrange(records):
      result = db.insertMessage(message, site, nodeFQDN, userDN, userGroup, remoteAddress)
      self.assertTrue(result['OK'])
      self.assertEqual(result['lastRowId'], k + 1)
      self.assertEqual(result['Value'], 1)

    result = db._queryDB(showFieldList=['SiteName'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], site)

    result = db._queryDB(showFieldList=['SystemName'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], systemName)

    result = db._queryDB(showFieldList=['SubSystemName'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], subSystemName)

    result = db._queryDB(showFieldList=['OwnerGroup'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], userGroup)

    result = db._queryDB(showFieldList=['FixedTextString'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], msgTest)

    result = db._queryDB(showFieldList=['VariableText', 'SiteName'], count=True, groupColumn='VariableText')
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][1], site)
    self.assertEqual(result['Value'][0][2], records)

    result = db.insertMessage(message, longSite, nodeFQDN, userDN, userGroup, remoteAddress)
    self.assertFalse(result['OK'])
class TopErrorMessagesReporter( AgentModule ):

  def initialize( self ):

    self.systemLoggingDB = SystemLoggingDB()

    self.agentName = self.am_getModuleParam( 'fullName' )

    self.notification = NotificationClient()

    mailList = self.am_getOption( "MailList", [] )

    userList = self.am_getOption( "Reviewer", [] )

    self.log.debug( "Users to be notified:", ', '.join( userList ) )

    for user in userList:
      mail = getUserOption( user, 'Email', '' )
      if not mail:
        self.log.warn( "Could not get user's mail", user )
      else:
        mailList.append( mail )

    if not mailList:
      mailList = Operations().getValue( 'EMail/Logging', [] )

    if not len( mailList ):
      errString = "There are no valid users in the list"
      varString = "[" + ','.join( userList ) + "]"
      self.log.error( errString, varString )
      return S_ERROR( errString + varString )

    self.log.info( "List of mails to be notified", ','.join( mailList ) )
    self._mailAddress = mailList
    self._threshold = int( self.am_getOption( 'Threshold', 10 ) )

    self.__days = self.am_getOption( 'QueryPeriod', 7 )
    self._period = int( self.__days ) * day
    self._limit = int ( self.am_getOption( 'NumberOfErrors', 10 ) )

    string = "The %i most common errors in the SystemLoggingDB" % self._limit
    self._subject = string + " for the last %s days" % self.__days
    return S_OK()

  def execute( self ):
    """ The main agent execution method
    """
    limitDate = date() - self._period
    tableList = [ "MessageRepository", "FixedTextMessages", "Systems",
                  "SubSystems" ]
    columnsList = [ "SystemName", "SubSystemName", "count(*) as entries",
                    "FixedTextString" ]
    cmd = "SELECT " + ', '.join( columnsList ) + " FROM " \
          + " NATURAL JOIN ".join( tableList ) \
          + " WHERE MessageTime > '%s'" % limitDate \
          + " GROUP BY FixedTextString HAVING entries > %s" % self._threshold \
          + " ORDER BY entries DESC LIMIT %i;" % self._limit

    result = self.systemLoggingDB._query( cmd )
    if not result['OK']:
      return result

    messageList = result['Value']

    if messageList == 'None' or messageList == ():
      self.log.warn( 'The DB query returned an empty result' )
      return S_OK()

    mailBody = '\n'
    for message in messageList:
      mailBody = mailBody + "Count: " + str( message[2] ) + "\tError: '"\
                 + message[3] + "'\tSystem: '" + message[0]\
                 + "'\tSubsystem: '" + message[1] + "'\n"

    mailBody = mailBody + "\n\n-------------------------------------------------------\n"\
               + "Please do not reply to this mail. It was automatically\n"\
               + "generated by a Dirac Agent.\n"

    result = self.systemLoggingDB._getDataFromAgentTable( self.agentName )
    self.log.debug( result )
    if not result['OK']:
      errorString = "Could not get the date when the last mail was sent"
      self.log.error( errorString )
      return S_ERROR( errorString )
    else:
      if len( result['Value'] ):
        self.log.debug( "date value: %s" % fromString( result['Value'][0][0][1:-1] ) )
        lastMailSentDate = fromString( result['Value'][0][0][1:-1] )
      else:
        lastMailSentDate = limitDate - 1 * day
        result = self.systemLoggingDB._insertDataIntoAgentTable( self.agentName, lastMailSentDate )
        if not result['OK']:
          errorString = "Could not insert data into the DB"
          self.log.error( errorString, result['Message'] )
          return S_ERROR( errorString + ": " + result['Message'] )

    self.log.debug( "limitDate: %s\t" % limitDate \
                   + "lastMailSentDate: %s\n" % lastMailSentDate )
    if lastMailSentDate > limitDate:
      self.log.info( "The previous report was sent less "\
                     + " than %s days ago" % self.__days )
      return S_OK()

    dateSent = toString( date() )
    self.log.info( "The list with the top errors has been sent" )

    result = self.systemLoggingDB._insertDataIntoAgentTable( self.agentName, dateSent )
    if not result['OK']:
      errorString = "Could not insert data into the DB"
      self.log.error( errorString, result['Message'] )
      return S_ERROR( errorString + ": " + result['Message'] )

    result = self.notification.sendMail( self._mailAddress, self._subject,
                                         mailBody )
    if not result[ 'OK' ]:
      self.log.warn( "The notification could not be sent" )
      return S_OK()

    return S_OK( "The list with the top errors has been sent" )
class TopErrorMessagesReporter( AgentModule ):

  def initialize( self ):

    self.systemLoggingDB = SystemLoggingDB()

    self.agentName = self.am_getModuleParam( 'fullName' )

    self.notification = NotificationClient()

    mailList = self.am_getOption( "MailList", [] )

    userList = self.am_getOption( "Reviewer", [] )

    self.log.debug( "Users to be notified:", ', '.join( userList ) )

    for user in userList:
      mail = getUserOption( user, 'Email', '' )
      if not mail:
        self.log.warn( "Could not get user's mail", user )
      else:
        mailList.append( mail )

    if not mailList:
      mailList = Operations().getValue( 'EMail/Logging', [] )

    if not len( mailList ):
      errString = "There are no valid users in the list"
      varString = "[" + ','.join( userList ) + "]"
      self.log.error( errString, varString )
      return S_ERROR( errString + varString )

    self.log.info( "List of mails to be notified", ','.join( mailList ) )
    self._mailAddress = mailList
    self._threshold = int( self.am_getOption( 'Threshold', 10 ) )

    self.__days = self.am_getOption( 'QueryPeriod', 7 )
    self._period = int( self.__days ) * day
    self._limit = int ( self.am_getOption( 'NumberOfErrors', 10 ) )

    string = "The %i most common errors in the SystemLoggingDB" % self._limit
    self._subject = string + " for the last %s days" % self.__days
    return S_OK()

  def execute( self ):
    """ The main agent execution method
    """
    limitDate = date() - self._period
    tableList = [ "MessageRepository", "FixedTextMessages", "Systems",
                  "SubSystems" ]
    columnsList = [ "SystemName", "SubSystemName", "count(*) as entries",
                    "FixedTextString" ]
    cmd = "SELECT " + ', '.join( columnsList ) + " FROM " \
          + " NATURAL JOIN ".join( tableList ) \
          + " WHERE MessageTime > '%s'" % limitDate \
          + " GROUP BY FixedTextString HAVING entries > %s" % self._threshold \
          + " ORDER BY entries DESC LIMIT %i;" % self._limit

    result = self.systemLoggingDB._query( cmd )
    if not result['OK']:
      return result

    messageList = result['Value']

    if messageList == 'None' or messageList == ():
      self.log.warn( 'The DB query returned an empty result' )
      return S_OK()

    mailBody = '\n'
    for message in messageList:
      mailBody = mailBody + "Count: " + str( message[2] ) + "\tError: '"\
                 + message[3] + "'\tSystem: '" + message[0]\
                 + "'\tSubsystem: '" + message[1] + "'\n"

    mailBody = mailBody + "\n\n-------------------------------------------------------\n"\
               + "Please do not reply to this mail. It was automatically\n"\
               + "generated by a Dirac Agent.\n"

    result = self.systemLoggingDB._getDataFromAgentTable( self.agentName )
    self.log.debug( result )
    if not result['OK']:
      errorString = "Could not get the date when the last mail was sent"
      self.log.error( errorString )
      return S_ERROR( errorString )
    else:
      if len( result['Value'] ):
        self.log.debug( "date value: %s" % fromString( result['Value'][0][0][1:-1] ) )
        lastMailSentDate = fromString( result['Value'][0][0][1:-1] )
      else:
        lastMailSentDate = limitDate - 1 * day
        result = self.systemLoggingDB._insertDataIntoAgentTable( self.agentName, lastMailSentDate )
        if not result['OK']:
          errorString = "Could not insert data into the DB"
          self.log.error( errorString, result['Message'] )
          return S_ERROR( errorString + ": " + result['Message'] )

    self.log.debug( "limitDate: %s\t" % limitDate \
                   + "lastMailSentDate: %s\n" % lastMailSentDate )
    if lastMailSentDate > limitDate:
      self.log.info( "The previous report was sent less "\
                     + " than %s days ago" % self.__days )
      return S_OK()

    dateSent = toString( date() )
    self.log.info( "The list with the top errors has been sent" )

    result = self.systemLoggingDB._insertDataIntoAgentTable( self.agentName, dateSent )
    if not result['OK']:
      errorString = "Could not insert data into the DB"
      self.log.error( errorString, result['Message'] )
      return S_ERROR( errorString + ": " + result['Message'] )

    result = self.notification.sendMail( self._mailAddress, self._subject,
                                         mailBody )
    if not result[ 'OK' ]:
      self.log.warn( "The notification could not be sent" )
      return S_OK()

    return S_OK( "The list with the top errors has been sent" )
class ErrorMessageMonitor( AgentModule ):

  def initialize( self ):

    self.systemLoggingDB = SystemLoggingDB()

    self.notification = NotificationClient()

    userList = self.am_getOption( "Reviewer", [] )

    self.log.debug( "Users to be notified:", ', '.join( userList ) )

    mailList = []
    for user in userList:
      mail = getUserOption( user, 'Email', '' )
      if not mail:
        self.log.warn( "Could not get user's mail", user )
      else:
        mailList.append( mail )

    if not mailList:
      mailList = Operations().getValue( 'EMail/Logging', [] )

    if not len( mailList ):
      errString = "There are no valid users in the mailing list"
      varString = "[" + ','.join( userList ) + "]"
      self.log.warn( errString, varString )

    self.log.info( "List of mails to be notified", ','.join( mailList ) )

    self._mailAddress = mailList
    self._subject = 'New error messages were entered in the SystemLoggingDB'
    return S_OK()

  def execute( self ):
    """ The main agent execution method
    """
    condDict = {'ReviewedMessage':0}
    result = self.systemLoggingDB.getCounters( 'FixedTextMessages', ['ReviewedMessage'], condDict )
    if not result['OK']:
      return result

    if not result['Value']:
      self.log.info( 'No messages need review' )
      return S_OK( 'No messages need review' )
    returnFields = [ 'FixedTextID', 'FixedTextString', 'SystemName',
                     'SubSystemName' ]
    result = self.systemLoggingDB._queryDB( showFieldList = returnFields,
                                            groupColumn = 'FixedTextString',
                                            condDict = condDict )
    if not result['OK']:
      self.log.error( 'Failed to obtain the non reviewed Strings',
                     result['Message'] )
      return S_OK()
    messageList = result['Value']

    if messageList == 'None' or not messageList:
      self.log.error( 'The DB query returned an empty result' )
      return S_OK()

    mailBody = 'These new messages have arrived to the Logging Service\n'
    for message in messageList:
      mailBody = mailBody + "String: '" + message[1] + "'\tSystem: '" \
                 + message[2] + "'\tSubsystem: '" + message[3] + "'\n"

    if self._mailAddress:
      result = self.notification.sendMail( self._mailAddress, self._subject, mailBody )
      if not result[ 'OK' ]:
        self.log.warn( "The mail could not be sent" )
        return S_OK()

    messageIDs = [ message[0] for message in messageList ]
    condDict = {'FixedTextID': messageIDs}
    result = self.systemLoggingDB.updateFields( 'FixedTextMessages', ['ReviewedMessage'], [1], condDict = condDict )
    if not result['OK']:
      self.log.error( 'Could not update message Status', result['ERROR'] )
      return S_OK()
    self.log.verbose( 'Updated message Status for:', str( messageList ) )

    self.log.info( "The messages have been sent for review",
                    "There are %s new descriptions" % len( messageList ) )
    return S_OK( "%s Messages have been sent for review" % len( messageList ) )
def initializeSystemLoggingHandler(serviceInfo):

    global LogDB
    LogDB = SystemLoggingDB()
    return S_OK()
Example #23
0
 def setUp(self):
   self.db = SystemLoggingDB()
Example #24
0
class ErrorMessageMonitor(AgentModule):

  def initialize(self):
 
    self.SystemLoggingDB = SystemLoggingDB()

    self.notification=NotificationClient()
        
    userString = self.am_getOption( "Reviewer", 'mseco' )
    
    self.log.debug( "Users to be notified", ": " + userString )
   
    userList = List.fromChar( userString, ",")
    
    mailList = []
    for user in userList:
      retval = gConfig.getOption( "/Registry/Users/" + user + "/Email" )
      if not retval['OK']:
        self.log.warn( "Could not get user's mail", retval['Message'] )
      else:
        mailList.append( retval['Value'] )
        
    if not mailList:
      mailList = gConfig.getValue( '/Operations/EMail/Logging', [] )

    if not len(mailList):
      errString = "There are no valid users in the list"
      varString = "[" + ','.join( userList ) + "]"
      self.log.error( errString, varString )
      return S_ERROR( errString + varString )
    
    self.log.info( "List of mails to be notified", ','.join( mailList ) )
   
    self._mailAddress = mailList
    self._subject = 'New error messages were entered in the SystemLoggingDB'
    return S_OK()

  def execute(self):
    """ The main agent execution method
    """
    cmd = "SELECT count(*) FROM FixedTextMessages WHERE ReviewedMessage=0"
    result = self.SystemLoggingDB._query( cmd )
    if not result['OK']:
      return result
    recordsToReview=result['Value'][0][0]

    if recordsToReview == 0:
      self.log.info('No messages need review')
      return S_OK('No messages need review')
    else:
      conds = { 'ReviewedMessage': '0' }
      returnFields = [ 'FixedTextID','FixedTextString', 'SystemName',
                       'SubSystemName' ]
      result = self.SystemLoggingDB._queryDB( showFieldList = returnFields,
                                              groupColumn = 'FixedTextString', 
                                              condDict = conds )
      if not result['OK']:
        self.log.error('Failed to obtain the non reviewed Strings',
                       result['Message'])
        return S_OK()
      messageList = result['Value']

      if messageList == 'None' or messageList == ():
        self.log.error('The DB query returned an empty result')
        return S_OK()

      mailBody ='These new messages have arrived to the Logging Service\n'
      for message in messageList:
        mailBody = mailBody + "String: '" + message[1] + "'\tSystem: '" \
                   + message[2] + "'\tSubsystem: '" + message[3] + "'\n"

      result = self.notification.sendMail( self._mailAddress, self._subject, mailBody )
      if not result[ 'OK' ]:
        self.log.warn( "The mail could not be sent" )
        return S_OK()

      for message in messageList:
        cmd = "UPDATE LOW_PRIORITY FixedTextMessages SET ReviewedMessage=1"
        cond = " WHERE FixedTextID=%s" % message[0]
        result =  self.SystemLoggingDB._update( cmd + cond )
        self.log.verbose('Message Status updated',
                         '(%d, %s)' % (message[0], message[1]))
        if not result['OK']:
          self.log.error( 'Could not update status of Message', message[1] )
          return S_OK()

      self.log.info( "The messages have been sent for review",
                      "There are %s new descriptions" % recordsToReview )
      return S_OK( "%s Messages have been sent for review" % recordsToReview )
Example #25
0
# FIXME: to bring back to life

"""  This program tests that the Logging DB can be actually queried from DIRAC 
"""
import DIRAC
from DIRAC.FrameworkSystem.DB.SystemLoggingDB import SystemLoggingDB

DBpoint=SystemLoggingDB()

testList = [{'method': DBpoint.getMessagesByFixedText,
             'arguments': ( ( 'error message 1' ), ),
             'outputType': 'Type',
             'output': True},
            {'method': DBpoint.getMessagesByFixedText,
             'arguments': ( ( [ 'error message 1', 'error message 4' ] ), ),
             'outputType': 'Type',
             'output': True},
            {'method': DBpoint.getMessagesByDate,
             'arguments': ( '2007-08-24', '2007-08-26' , ),
             'outputType': 'Type',
             'output': True},
            {'method': DBpoint.getMessagesBySite,
             'arguments': ( ( 'Site1' ), ),
             'outputType': 'Type',
             'output': True},
            {'method': DBpoint.getMessagesBySite,
             'arguments': ( ( [ 'Site1', 'Site2' ] ), ),
             'outputType': 'Type',
             'output': True}, ]

testdict = { 'SystemLoggingDB': testList,}
Example #26
0
class ErrorMessageMonitor(AgentModule):
    def initialize(self):

        self.systemLoggingDB = SystemLoggingDB()

        self.notification = NotificationClient()

        userList = self.am_getOption("Reviewer", [])

        self.log.debug("Users to be notified:", ', '.join(userList))

        mailList = []
        for user in userList:
            mail = getUserOption(user, 'Email', '')
            if not mail:
                self.log.warn("Could not get user's mail", user)
            else:
                mailList.append(mail)

        if not mailList:
            mailList = Operations().getValue('EMail/Logging', [])

        if not len(mailList):
            errString = "There are no valid users in the mailing list"
            varString = "[" + ','.join(userList) + "]"
            self.log.warn(errString, varString)

        self.log.info("List of mails to be notified", ','.join(mailList))

        self._mailAddress = mailList
        self._subject = 'New error messages were entered in the SystemLoggingDB'
        return S_OK()

    def execute(self):
        """ The main agent execution method
    """
        condDict = {'ReviewedMessage': 0}
        result = self.systemLoggingDB.getCounters('FixedTextMessages',
                                                  ['ReviewedMessage'],
                                                  condDict)
        if not result['OK']:
            return result

        if not result['Value']:
            self.log.info('No messages need review')
            return S_OK('No messages need review')
        returnFields = [
            'FixedTextID', 'FixedTextString', 'SystemName', 'SubSystemName'
        ]
        result = self.systemLoggingDB._queryDB(showFieldList=returnFields,
                                               groupColumn='FixedTextString',
                                               condDict=condDict)
        if not result['OK']:
            self.log.error('Failed to obtain the non reviewed Strings',
                           result['Message'])
            return S_OK()
        messageList = result['Value']

        if messageList == 'None' or not messageList:
            self.log.error('The DB query returned an empty result')
            return S_OK()

        mailBody = 'These new messages have arrived to the Logging Service\n'
        for message in messageList:
            mailBody = mailBody + "String: '" + message[1] + "'\tSystem: '" \
                       + message[2] + "'\tSubsystem: '" + message[3] + "'\n"

        if self._mailAddress:
            result = self.notification.sendMail(self._mailAddress,
                                                self._subject, mailBody)
            if not result['OK']:
                self.log.warn("The mail could not be sent")
                return S_OK()

        messageIDs = [message[0] for message in messageList]
        condDict = {'FixedTextID': messageIDs}
        result = self.systemLoggingDB.updateFields('FixedTextMessages',
                                                   ['ReviewedMessage'], [1],
                                                   condDict=condDict)
        if not result['OK']:
            self.log.error('Could not update message Status', result['ERROR'])
            return S_OK()
        self.log.verbose('Updated message Status for:', str(messageList))

        self.log.info("The messages have been sent for review",
                      "There are %s new descriptions" % len(messageList))
        return S_OK("%s Messages have been sent for review" % len(messageList))