예제 #1
0
def AlarmPolTypeActions(granularity, name, siteType, serviceType, resourceType, res, nc, setup, rsDB):
  # raise alarms, right now makes a simple notification

  if res['Action']:

    notif = "%s %s is perceived as" %(granularity, name)
    notif = notif + " %s. Reason: %s." %(res['Status'], res['Reason'])

    NOTIF_D = getUsersToNotify(granularity,
                                      setup, siteType,
                                      serviceType,
                                      resourceType)

    for notification in NOTIF_D:
      for user in notification['Users']:
        if 'Web' in notification['Notifications']:
          nc.addNotificationForUser(user, notif)
        if 'Mail' in notification['Notifications']:
          mailMessage = "Granularity = %s \n" % granularity
          mailMessage = mailMessage + "Name = %s\n" % name
          mailMessage = mailMessage + "New perceived status = %s\n" % res['Status']
          mailMessage = mailMessage + "Reason for status change = %s\n" % res['Reason']

          was = rsDB.getMonitoredsHistory(granularity,
                                          ['Status', 'Reason', 'DateEffective'],
                                          name, False, 'DESC', 1)[0]

          mailMessage = mailMessage + "Was in status \"%s\", " % (was[0])
          mailMessage = mailMessage + "with reason \"%s\", since %s\n" % (was[1], was[2])

          mailMessage = mailMessage + "Setup = %s\n" % setup

          nc.sendMail(getMailForUser(user)['Value'][0],
                      '%s: %s' % (name, res['Status']), mailMessage)
예제 #2
0
파일: PEP.py 프로젝트: vfalbor/DIRAC
  def _AlarmPolTypeActions(self, res, nc, setup, rsDB):
        # raise alarms, right now makes a simple notification

    if res['Action']:

      notif = "%s %s is perceived as" %(self.__granularity, self.__name)
      notif = notif + " %s. Reason: %s." %(res['Status'], res['Reason'])

      NOTIF_D = self.__getUsersToNotify(self.__granularity,
                                        setup, self.__siteType,
                                        self.__serviceType,
                                        self.__resourceType)

      for notification in NOTIF_D:
        for user in notification['Users']:
          if 'Web' in notification['Notifications']:
            nc.addNotificationForUser(user, notif)
          if 'Mail' in notification['Notifications']:
            mailMessage = "Granularity = %s \n" %self.__granularity
            mailMessage = mailMessage + "Name = %s\n" %self.__name
            mailMessage = mailMessage + "New perceived status = %s\n" %res['Status']
            mailMessage = mailMessage + "Reason for status change = %s\n" %res['Reason']

            was = rsDB.getMonitoredsHistory(self.__granularity,
                                            ['Status', 'Reason', 'DateEffective'],
                                            self.__name, False, 'DESC', 1)[0]

            mailMessage = mailMessage + "Was in status \"%s\", " %(was[0])
            mailMessage = mailMessage + "with reason \"%s\", since %s\n" %(was[1], was[2])

            mailMessage = mailMessage + "Setup = %s\n" %setup

            nc.sendMail(getMailForUser(user)['Value'][0],
                        '%s: %s' %(self.__name, res['Status']), mailMessage)
예제 #3
0
파일: TokenAgent.py 프로젝트: vfalbor/DIRAC
    def execute(self):
        """ 
    The main TokenAgent execution method.
    Checks for tokens owned by users that are expiring, and notifies those users.
    Calls rsDB.setToken() to set 'RS_SVC' as owner for those tokens that expired.
    """

        try:

            #reAssign the token to RS_SVC
            for g in ('Site', 'StorageElement'):
                tokensExpired = self.rsDB.getTokens(g, None,
                                                    datetime.datetime.utcnow())
                for token in tokensExpired:
                    self.rsDB.setToken(
                        g, token[0], 'RS_SVC',
                        datetime.datetime(9999, 12, 31, 23, 59, 59))

            #notify token owners
            in2Hours = datetime.datetime.utcnow() + datetime.timedelta(hours=2)
            for g in ('Site', 'StorageElement'):
                tokensExpiring = self.rsDB.getTokens(g, None, in2Hours)
                for token in tokensExpiring:
                    name = token[0]
                    user = token[1]
                    if user == 'RS_SVC':
                        continue
                    expiration = token[2]

                    mailMessage = "The token for %s %s " % (g, name)
                    mailMessage = mailMessage + "will expire on %s\n\n" % expiration
                    mailMessage = mailMessage + "You can renew it with command 'dirac-rss-renew-token'.\n"
                    mailMessage = mailMessage + "If you don't take any action, RSS will take control of the resource."

                    self.nc.sendMail(
                        getMailForUser(user)['Value'][0],
                        'Token for %s is expiring' % name, mailMessage)

            return S_OK()

        except Exception:
            errorStr = "TokenAgent execution"
            gLogger.exception(errorStr)
            return S_ERROR(errorStr)
예제 #4
0
  def execute(self):
    """ 
    The main TokenAgent execution method.
    Checks for tokens owned by users that are expiring, and notifies those users.
    Calls rsDB.setToken() to set 'RS_SVC' as owner for those tokens that expired.
    """
    
    try:
      
      #reAssign the token to RS_SVC
      for g in ('Site', 'StorageElement'):
        tokensExpired = self.rsDB.getTokens(g, None, datetime.datetime.utcnow())
        for token in tokensExpired:
          self.rsDB.setToken(g, token[0], 'RS_SVC', datetime.datetime(9999, 12, 31, 23, 59, 59))

      #notify token owners
      in2Hours = datetime.datetime.utcnow() + datetime.timedelta(hours = 2)
      for g in ('Site', 'StorageElement'):
        tokensExpiring = self.rsDB.getTokens(g, None, in2Hours)
        for token in tokensExpiring:
          name = token[0]
          user = token[1]
          if user == 'RS_SVC':
            continue
          expiration = token[2]
          
          mailMessage = "The token for %s %s " %(g, name)
          mailMessage = mailMessage + "will expire on %s\n\n" %expiration
          mailMessage = mailMessage + "You can renew it with command 'dirac-rss-renew-token'.\n"
          mailMessage = mailMessage + "If you don't take any action, RSS will take control of the resource."
          
          self.nc.sendMail(getMailForUser(user)['Value'][0], 
                           'Token for %s is expiring' %name, mailMessage)


      return S_OK()
    
    except Exception:
      errorStr = "TokenAgent execution"
      gLogger.exception(errorStr)
      return S_ERROR(errorStr)
예제 #5
0
from DIRAC.Core.Security.Misc                         import getProxyInfo
from DIRAC                                            import gConfig, gLogger
from DIRAC.Core.DISET.RPCClient import RPCClient
from DIRAC.ResourceStatusSystem.Utilities.CS import getMailForUser

nc = NotificationClient()

s = RPCClient( "ResourceStatus/ResourceStatus" )

res = getProxyInfo()
if not res['OK']:
  gLogger.error( "Failed to get proxy information", res['Message'] )
  DIRAC.exit( 2 )
userName = res['Value']['username']
group = res['Value']['group']
if group not in ( 'diracAdmin', 'lhcb_prod' ):
  gLogger.error( "You must be lhcb_prod or diracAdmin to execute this script" )
  gLogger.info( "Please issue 'lhcb-proxy-init -g lhcb_prod' or 'lhcb-proxy-init -g diracAdmin'" )
  DIRAC.exit( 2 )

for arg in args:
  g = s.whatIs( arg )
  res = s.extendToken( g, arg, hours )
  if not res['OK']:
    gLogger.error( "Problem with extending: %s" % res['Message'] )
    DIRAC.exit( 2 )
  mailMessage = "The token for %s %s has been successfully renewed for others %i hours" % ( g, arg, hours )
  nc.sendMail( getMailForUser( userName )['Value'][0], 'Token for %s renewed' % arg, mailMessage )

DIRAC.exit( 0 )
from DIRAC.Core.Security.Misc                         import getProxyInfo
from DIRAC                                            import gConfig, gLogger
from DIRAC.Core.DISET.RPCClient import RPCClient
from DIRAC.ResourceStatusSystem.Utilities.CS import getMailForUser

nc = NotificationClient()

s = RPCClient( "ResourceStatus/ResourceStatus" )

res = getProxyInfo()
if not res['OK']:
  gLogger.error( "Failed to get proxy information", res['Message'] )
  DIRAC.exit( 2 )
userName = res['Value']['username']
group = res['Value']['group']
if group not in ( 'diracAdmin', 'lhcb_prod' ):
  gLogger.error( "You must be lhcb_prod or diracAdmin to execute this script" )
  gLogger.info( "Please issue 'lhcb-proxy-init -g lhcb_prod' or 'lhcb-proxy-init -g diracAdmin'" )
  DIRAC.exit( 2 )

for arg in args:
  g = s.whatIs( arg )
  res = s.reAssignToken( g, arg, userName )
  if not res['OK']:
    gLogger.error( "Problem with re-assigning token for %s: " % res['Message'] )
    DIRAC.exit( 2 )
  mailMessage = "The token for %s %s has been successfully re-assigned." % ( g, arg )
  nc.sendMail( getMailForUser( userName )['Value'][0], 'Token for %s reassigned' % arg, mailMessage )

DIRAC.exit( 0 )
예제 #7
0
from DIRAC.Core.Security.Misc import getProxyInfo
from DIRAC import gConfig, gLogger
from DIRAC.Core.DISET.RPCClient import RPCClient
from DIRAC.ResourceStatusSystem.Utilities.CS import getMailForUser

nc = NotificationClient()

s = RPCClient("ResourceStatus/ResourceStatus")

res = getProxyInfo()
if not res["OK"]:
    gLogger.error("Failed to get proxy information", res["Message"])
    DIRAC.exit(2)
userName = res["Value"]["username"]
group = res["Value"]["group"]
if group not in ("diracAdmin", "lhcb_prod"):
    gLogger.error("You must be lhcb_prod or diracAdmin to execute this script")
    gLogger.info("Please issue 'lhcb-proxy-init -g lhcb_prod' or 'lhcb-proxy-init -g diracAdmin'")
    DIRAC.exit(2)

for arg in args:
    g = s.whatIs(arg)
    res = s.extendToken(g, arg, hours)
    if not res["OK"]:
        gLogger.error("Problem with extending: %s" % res["Message"])
        DIRAC.exit(2)
    mailMessage = "The token for %s %s has been successfully renewed for others %i hours" % (g, arg, hours)
    nc.sendMail(getMailForUser(userName)["Value"][0], "Token for %s renewed" % arg, mailMessage)

DIRAC.exit(0)
예제 #8
0
    def execute(self):
        """ 
    The main TokenAgent execution method.
    Checks for tokens owned by users that are expiring, and notifies those users.
    Calls rsDB.setToken() to set 'RS_SVC' as owner for those tokens that expired.
    """

        adminMail = ''

        try:

            #reAssign the token to RS_SVC
            for g in self.ELEMENTS:
                tokensExpired = self.rsDB.getTokens(g, None,
                                                    datetime.datetime.utcnow())

                if tokensExpired:
                    adminMail += '\nLIST OF EXPIRED TOKENS\n'

                for token in tokensExpired:

                    name = token[0]
                    user = token[1]

                    self.rsDB.setToken(
                        g, name, 'RS_SVC',
                        datetime.datetime(9999, 12, 31, 23, 59, 59))
                    adminMail += ' %s %s\n' % (user.ljust(20), name)

            #notify token owners
            inNHours = datetime.datetime.utcnow() + datetime.timedelta(
                hours=self.notifyHours)
            for g in self.ELEMENTS:

                tokensExpiring = self.rsDB.getTokens(g, None, inNHours)

                if tokensExpiring:
                    adminMail += '\nLIST OF EXPIRING TOKENS\n'

                for token in tokensExpiring:

                    name = token[0]
                    user = token[1]

                    adminMail += '\n %s %s\n' % (user.ljust(20), name)

                    if user == 'RS_SVC':
                        continue

                    pdp = PDP(self.VOExt, granularity=g, name=name)

                    decision = pdp.takeDecision()
                    pcresult = decision['PolicyCombinedResult']
                    spresult = decision['SinglePolicyResults']

                    expiration = token[2]

                    mailMessage = "The token for %s %s " % (g, name)
                    mailMessage = mailMessage + "will expire on %s\n\n" % expiration
                    mailMessage = mailMessage + "You can renew it with command 'dirac-rss-renew-token'.\n"
                    mailMessage = mailMessage + "If you don't take any action, RSS will take control of the resource.\n\n"

                    policyMessage = ''

                    if pcresult:

                        policyMessage += "  Policies applied will set status to %s.\n" % pcresult[
                            'Status']

                        for spr in spresult:
                            policyMessage += "    %s Status->%s\n" % (
                                spr['PolicyName'].ljust(25), spr['Status'])

                    mailMessage += policyMessage
                    adminMail += policyMessage

                    self.nc.sendMail(
                        getMailForUser(user)['Value'][0],
                        'Token for %s is expiring' % name, mailMessage)

            if adminMail != '':
                self.nc.sendMail(
                    getMailForUser('ubeda')['Value'][0], "Token's summary",
                    adminMail)

            return S_OK()

        except Exception:
            errorStr = "TokenAgent execution"
            gLogger.exception(errorStr)
            return S_ERROR(errorStr)


#############################################################################
예제 #9
0
s = RPCClient("ResourceStatus/ResourceStatus")

res = getProxyInfo()
if not res['OK']:
    gLogger.error("Failed to get proxy information", res['Message'])
    DIRAC.exit(2)
userName = res['Value']['username']
group = res['Value']['group']
if group not in ('diracAdmin', 'lhcb_prod'):
    gLogger.error("You must be lhcb_prod or diracAdmin to execute this script")
    gLogger.info(
        "Please issue 'lhcb-proxy-init -g lhcb_prod' or 'lhcb-proxy-init -g diracAdmin'"
    )
    DIRAC.exit(2)

for arg in args:
    g = s.whatIs(arg)
    res = s.reAssignToken(g, arg, userName)
    if not res['OK']:
        gLogger.error("Problem with re-assigning token for %s: " %
                      res['Message'])
        DIRAC.exit(2)
    mailMessage = "The token for %s %s has been successfully re-assigned." % (
        g, arg)
    nc.sendMail(
        getMailForUser(userName)['Value'][0], 'Token for %s reassigned' % arg,
        mailMessage)

DIRAC.exit(0)