Exemplo n.º 1
0
  def sysinfo( self ):

    DN = getUserDN()
    group = getSelectedGroup()

    #TODO: remove hosts code after v6r7 since it will be built-in
    result = gConfig.getSections( "/Registry/Hosts" )
    if not result[ "Value" ]:
      return { "success" : "false" , "error" : result[ "Message" ] }
    hosts = result[ "Value" ]

    client = SystemAdministratorIntegrator( hosts = hosts , delegatedDN=DN ,
                                          delegatedGroup=group )
    result = client.getHostInfo()
    gLogger.debug( result )
    if not result[ "OK" ]:
      return { "success" : "false" , "error" : result[ "Message" ] }
    result = result[ "Value" ]

    callback = list()
    for i in result:
      if result[ i ][ "OK" ]:
        tmp = result[ i ][ "Value" ]
      else:
        tmp = dict()
      tmp[ "Host" ] = i
      callback.append( tmp )

    total = len( callback )
    if not total > 0:
      return { "success" : "false" , "error" : "No system information found" }
    return { "success" : "true" , "result" : callback , "total" : total }
    def do_showall(self, args):
        """ Show status of all the components in all the hosts
    
        Usage:
          showall [-snmth] [-ASE] [-N name] [-H host] - show status of components
                              
        Options:
            -d extra debug printout
          Sorting options:                      
            -s system
            -n component name
            -m component module
            -t component type
            -h component host  
          Selection options:
            -A select agents
            -S select services
            -E select executors
            -N <component pattern> select component with the name containing the pattern 
            -H <host name> select the given host  
            -T <setup name> select the given setup
    """

        argss = args.split()
        sortOption = ''
        componentType = ''
        componentName = ''
        hostName = ''
        setupName = ''
        debug = False
        while len(argss) > 0:
            option = argss[0]
            del argss[0]
            sortOption = ''
            if option == '-s':
                sortOption = "System"
            elif option == '-n':
                sortOption = "Name"
            elif option == '-m':
                sortOption = "Module"
            elif option == '-t':
                sortOption = "Type"
            elif option == '-h':
                sortOption = "Host"
            elif option == "-A":
                componentType = 'Agents'
            elif option == "-S":
                componentType = 'Services'
            elif option == "-E":
                componentType = 'Executors'
            elif option == "-d":
                debug = True
            elif option == "-N":
                componentName = argss[0]
                del argss[0]
            elif option == "-H":
                hostName = argss[0]
                del argss[0]
            elif option == "-T":
                setupName = argss[0]
                del argss[0]
            else:
                self.__errMsg('Invalid option %s' % option)
                return

        client = SystemAdministratorIntegrator()
        resultAll = client.getOverallStatus()
        resultInfo = client.getInfo()

        if not resultAll['OK']:
            self.__errMsg(resultAll['Message'])
        else:
            fields = [
                "System", 'Name', 'Module', 'Type', 'Setup', 'Host', 'Runit',
                'Uptime'
            ]
            records = []
            for host in resultAll['Value']:
                if hostName and not hostName in host:
                    continue
                result = resultAll['Value'][host]
                if not result['OK']:
                    if debug:
                        self.__errMsg("Host %s: %s" %
                                      (host, result['Message']))
                    continue
                rDict = result['Value']
                for compType in rDict:
                    if componentType and componentType != compType:
                        continue
                    for system in rDict[compType]:
                        components = rDict[compType][system].keys()
                        components.sort()
                        for component in components:
                            if componentName and not componentName in component:
                                continue
                            record = []
                            if rDict[compType][system][component]['Installed']:
                                module = str(rDict[compType][system][component]
                                             ['Module'])
                                record += [
                                    system, component, module,
                                    compType.lower()[:-1]
                                ]
                                if resultInfo['OK'] and host in resultInfo[
                                        'Value'] and resultInfo['Value'][host][
                                            'OK']:
                                    setup = resultInfo['Value'][host]['Value'][
                                        'Setup']
                                else:
                                    setup = 'Unknown'
                                if setupName and not setupName in setup:
                                    continue
                                record += [setup]
                                record += [host]
                                record += [
                                    str(rDict[compType][system][component]
                                        ['RunitStatus'])
                                ]
                                record += [
                                    str(rDict[compType][system][component]
                                        ['Timeup'])
                                ]
                                records.append(record)
            printTable(fields, records, sortOption)
Exemplo n.º 3
0
Script.setUsageMessage('\n'.join([
    __doc__.split('\n')[1], 'Usage:',
    '  %s [option|cfgfile] ... [debug]' % Script.scriptName
]))

Script.parseCommandLine(ignoreErrors=False)
args = Script.getPositionalArgs()

componentType = ''

# Get my setup
mySetup = gConfig.getValue('DIRAC/Setup')

# Retrieve information from all the hosts
client = SystemAdministratorIntegrator(exclude=excludedHosts)
resultAll = client.getOverallStatus()

notificationClient = NotificationClient()
for host in resultAll['Value']:
    if not resultAll['Value'][host]['OK']:
        # If the host cannot be contacted, exclude it and send message
        excludedHosts.append(host)

        result = notificationClient.sendMail(
            Operations().getValue('EMail/Production', []), 'Unreachable host',
            '\ndirac-populate-component-db: Could not fill the database with the components from unreachable host %s\n'
            % host)
        if not result['OK']:
            gLogger.error(
                'Can not send unreachable host notification mail: %s' %
Exemplo n.º 4
0
 def do_showall( self, args ):
   """ Show status of all the components in all the hosts
   
       Usage:
         showall [-snmth] [-ASE] [-N name] [-H host] - show status of components
                             
       Options:
           -d extra debug printout
         Sorting options:                      
           -s system
           -n component name
           -m component module
           -t component type
           -h component host  
         Selection options:
           -A select agents
           -S select services
           -E select executors
           -N <component pattern> select component with the name containing the pattern 
           -H <host name> select the given host  
           -T <setup name> select the given setup
   """
   
   argss = args.split()
   sortOption = ''
   componentType = ''
   componentName = ''
   hostName = ''
   setupName = ''
   debug = False
   while len( argss ) > 0:
     option = argss[0]
     del argss[0]
     sortOption = ''
     if option == '-s':
       sortOption = "System"
     elif option == '-n':
       sortOption = "Name" 
     elif option == '-m':
       sortOption = "Module"
     elif option == '-t':
       sortOption = "Type"
     elif option == '-h':
       sortOption = "Host"
     elif option == "-A":
       componentType = 'Agents'
     elif option == "-S":
       componentType = 'Services'
     elif option == "-E":
       componentType = 'Executors'
     elif option == "-d":
       debug = True  
     elif option == "-N":
       componentName = argss[0]        
       del argss[0]      
     elif option == "-H":
       hostName = argss[0]        
       del argss[0]   
     elif option == "-T":
       setupName = argss[0]        
       del argss[0]     
     else:
       self.__errMsg( 'Invalid option %s' % option )  
       return
   
   client = SystemAdministratorIntegrator()
   resultAll = client.getOverallStatus()
   resultInfo = client.getInfo()
   
   if not resultAll['OK']:
     self.__errMsg( resultAll['Message'] )
   else:
     fields = ["System",'Name','Module','Type','Setup','Host','Runit','Uptime']
     records = []
     for host in resultAll['Value']:
       if hostName and not hostName in host:
         continue
       result = resultAll['Value'][host]
       if not result['OK']:
         if debug:
           self.__errMsg( "Host %s: %s" % (host,result['Message']) )
         continue  
       rDict = result['Value']
       for compType in rDict:
         if componentType and componentType != compType:
           continue
         for system in rDict[compType]:
           components = rDict[compType][system].keys()
           components.sort()
           for component in components:
             if componentName and not componentName in component:
               continue
             record = []
             if rDict[compType][system][component]['Installed']:
               module = str( rDict[compType][system][component]['Module'] )
               record += [ system,component,module,compType.lower()[:-1]]
               if resultInfo['OK'] and host in resultInfo['Value'] and resultInfo['Value'][host]['OK']:
                 setup = resultInfo['Value'][host]['Value']['Setup']
               else:
                 setup = 'Unknown'
               if setupName and not setupName in setup:
                 continue  
               record += [setup]    
               record += [host]  
               record += [str( rDict[compType][system][component]['RunitStatus'] )]
               record += [str( rDict[compType][system][component]['Timeup'] )]
               records.append(record)  
     printTable( fields, records, sortOption )        
Exemplo n.º 5
0
def main():
    global excludedHosts
    Script.registerSwitch(
        "e:", "exclude=",
        "Comma separated list of hosts to be excluded from the scanning process",
        setExcludedHosts)
    Script.parseCommandLine(ignoreErrors=False)

    componentType = ""

    # Get my setup
    mySetup = gConfig.getValue("DIRAC/Setup")

    # Retrieve information from all the hosts
    client = SystemAdministratorIntegrator(exclude=excludedHosts)
    resultAll = client.getOverallStatus()
    if not resultAll["OK"]:
        gLogger.error(resultAll["Message"])
        DIRACexit(-1)

    # Retrieve user installing the component
    result = getProxyInfo()
    if result["OK"]:
        user = result["Value"]["username"]
    else:
        DIRACexit(-1)
    if not user:
        user = "******"

    for host in resultAll["Value"]:
        if not resultAll["Value"][host]["OK"]:
            # If the host cannot be contacted, exclude it and send message
            excludedHosts.append(host)

            result = NotificationClient().sendMail(
                Operations().getValue("EMail/Production", []),
                "Unreachable host",
                "\ndirac-populate-component-db: Could not fill the database with the components from unreachable host %s\n"
                % host,
            )
            if not result["OK"]:
                gLogger.error(
                    "Can not send unreachable host notification mail: %s" %
                    result["Message"])

    resultHosts = client.getHostInfo()
    if not resultHosts["OK"]:
        gLogger.error(resultHosts["Message"])
        DIRACexit(-1)
    resultInfo = client.getInfo()
    if not resultInfo["OK"]:
        gLogger.error(resultInfo["Message"])
        DIRACexit(-1)
    resultMySQL = client.getMySQLStatus()
    if not resultMySQL["OK"]:
        gLogger.error(resultMySQL["Message"])
        DIRACexit(-1)
    resultAllDB = client.getDatabases()
    if not resultAllDB["OK"]:
        gLogger.error(resultAllDB["Message"])
        DIRACexit(-1)
    resultAvailableDB = client.getAvailableDatabases()
    if not resultAvailableDB["OK"]:
        gLogger.error(resultAvailableDB["Message"])
        DIRACexit(-1)

    records = []
    finalSet = list(set(resultAll["Value"]) - set(excludedHosts))
    for host in finalSet:
        hasMySQL = True
        result = resultAll["Value"][host]
        hostResult = resultHosts["Value"][host]
        infoResult = resultInfo["Value"][host]
        mySQLResult = resultMySQL["Value"][host]
        allDBResult = resultAllDB["Value"][host]
        availableDBResult = resultAvailableDB["Value"][host]

        if not result["OK"]:
            gLogger.error("Host %s: %s" % (host, result["Message"]))
            continue
        if not hostResult["OK"]:
            gLogger.error("Host %s: %s" % (host, hostResult["Message"]))
            continue
        if not infoResult["OK"]:
            gLogger.error("Host %s: %s" % (host, infoResult["Message"]))
            continue
        if mySQLResult["OK"]:
            if not allDBResult["OK"]:
                gLogger.error("Host %s: %s" % (host, allDBResult["Message"]))
                continue
            if not availableDBResult["OK"]:
                gLogger.error("Host %s: %s" %
                              (host, availableDBResult["Message"]))
                continue
        else:
            hasMySQL = False

        setup = infoResult["Value"]["Setup"]
        if setup != mySetup:
            continue

        cpu = hostResult["Value"]["CPUModel"].strip()
        rDict = result["Value"]
        # Components other than databases
        for compType in rDict:
            if componentType and componentType != compType:
                continue
            for system in rDict[compType]:
                components = sorted(rDict[compType][system])
                for component in components:
                    record = {"Installation": {}, "Component": {}, "Host": {}}
                    if rDict[compType][system][component][
                            "Installed"] and component != "ComponentMonitoring":
                        runitStatus = str(
                            rDict[compType][system][component]["RunitStatus"])
                        if runitStatus != "Unknown":
                            module = str(
                                rDict[compType][system][component]["Module"])
                            record["Component"]["System"] = system
                            record["Component"]["Module"] = module
                            # Transform 'Services' into 'service', 'Agents' into 'agent' ...
                            record["Component"]["Type"] = compType.lower()[:-1]
                            record["Host"]["HostName"] = host
                            record["Host"]["CPU"] = cpu
                            record["Installation"]["Instance"] = component
                            record["Installation"][
                                "InstallationTime"] = datetime.utcnow()
                            record["Installation"]["InstalledBy"] = user
                            records.append(record)

        # Databases
        csClient = CSAPI()
        cfg = csClient.getCurrentCFG()["Value"]

        if hasMySQL:
            allDB = allDBResult["Value"]
            availableDB = availableDBResult["Value"]

            for db in allDB:
                # Check for DIRAC only databases
                if db in availableDB and db != "InstalledComponentsDB":
                    # Check for 'installed' databases
                    isSection = cfg.isSection(
                        "Systems/" + availableDB[db]["System"] + "/" +
                        cfg.getOption("DIRAC/Setups/" + setup + "/" +
                                      availableDB[db]["System"]) +
                        "/Databases/" + db + "/")
                    if isSection:
                        record = {
                            "Installation": {},
                            "Component": {},
                            "Host": {}
                        }
                        record["Component"]["System"] = availableDB[db][
                            "System"]
                        record["Component"]["Module"] = db
                        record["Component"]["Type"] = "DB"
                        record["Host"]["HostName"] = host
                        record["Host"]["CPU"] = cpu
                        record["Installation"]["Instance"] = db
                        record["Installation"][
                            "InstallationTime"] = datetime.utcnow()
                        record["Installation"]["InstalledBy"] = user
                        records.append(record)

    monitoringClient = ComponentMonitoringClient()

    # Add the installations to the database
    for record in records:
        result = MonitoringUtilities.monitorInstallation(
            record["Component"]["Type"],
            record["Component"]["System"],
            record["Installation"]["Instance"],
            record["Component"]["Module"],
            record["Host"]["CPU"],
            record["Host"]["HostName"],
        )
        if not result["OK"]:
            gLogger.error(result["Message"])

Script.setUsageMessage( '\n'.join( [ __doc__.split( '\n' )[1],
                        'Usage:',
                        '  %s [option|cfgfile] ... [debug]' % Script.scriptName ] ) )

Script.parseCommandLine( ignoreErrors = False )
args = Script.getPositionalArgs()

componentType = ''

# Get my setup
mySetup = gConfig.getValue( 'DIRAC/Setup' )

# Retrieve information from all the hosts
client = SystemAdministratorIntegrator( exclude = excludedHosts )
resultAll = client.getOverallStatus()

# Retrieve user installing the component
result = getProxyInfo()
if result[ 'OK' ]:
  user = result[ 'Value' ][ 'username' ]
else:
  DIRACexit( -1 )
if not user:
  user = '******'

notificationClient = NotificationClient()
for host in resultAll[ 'Value' ]:
  if not resultAll[ 'Value' ][ host ][ 'OK' ]:
    # If the host cannot be contacted, exclude it and send message
Exemplo n.º 7
0
def main():
    global excludedHosts
    Script.registerSwitch(
        "e:", "exclude=",
        "Comma separated list of hosts to be excluded from the scanning process",
        setExcludedHosts)
    Script.parseCommandLine(ignoreErrors=False)

    componentType = ''

    # Get my setup
    mySetup = gConfig.getValue('DIRAC/Setup')

    # Retrieve information from all the hosts
    client = SystemAdministratorIntegrator(exclude=excludedHosts)
    resultAll = client.getOverallStatus()

    # Retrieve user installing the component
    result = getProxyInfo()
    if result['OK']:
        user = result['Value']['username']
    else:
        DIRACexit(-1)
    if not user:
        user = '******'

    notificationClient = NotificationClient()
    for host in resultAll['Value']:
        if not resultAll['Value'][host]['OK']:
            # If the host cannot be contacted, exclude it and send message
            excludedHosts.append(host)

            result = notificationClient.sendMail(
                Operations().getValue('EMail/Production',
                                      []), 'Unreachable host',
                '\ndirac-populate-component-db: Could not fill the database with the components from unreachable host %s\n'
                % host)
            if not result['OK']:
                gLogger.error(
                    'Can not send unreachable host notification mail: %s' %
                    result['Message'])

    if not resultAll['OK']:
        gLogger.error(resultAll['Message'])
        DIRACexit(-1)
    resultHosts = client.getHostInfo()
    if not resultHosts['OK']:
        gLogger.error(resultHosts['Message'])
        DIRACexit(-1)
    resultInfo = client.getInfo()
    if not resultInfo['OK']:
        gLogger.error(resultInfo['Message'])
        DIRACexit(-1)
    resultMySQL = client.getMySQLStatus()
    if not resultMySQL['OK']:
        gLogger.error(resultMySQL['Message'])
        DIRACexit(-1)
    resultAllDB = client.getDatabases()
    if not resultAllDB['OK']:
        gLogger.error(resultAllDB['Message'])
        DIRACexit(-1)
    resultAvailableDB = client.getAvailableDatabases()
    if not resultAvailableDB['OK']:
        gLogger.error(resultAvailableDB['Message'])
        DIRACexit(-1)

    records = []
    finalSet = list(set(resultAll['Value']) - set(excludedHosts))
    for host in finalSet:
        hasMySQL = True
        result = resultAll['Value'][host]
        hostResult = resultHosts['Value'][host]
        infoResult = resultInfo['Value'][host]
        mySQLResult = resultMySQL['Value'][host]
        allDBResult = resultAllDB['Value'][host]
        availableDBResult = resultAvailableDB['Value'][host]

        if not result['OK']:
            gLogger.error('Host %s: %s' % (host, result['Message']))
            continue
        if not hostResult['OK']:
            gLogger.error('Host %s: %s' % (host, hostResult['Message']))
            continue
        if not infoResult['OK']:
            gLogger.error('Host %s: %s' % (host, infoResult['Message']))
            continue
        if mySQLResult['OK']:
            if not allDBResult['OK']:
                gLogger.error('Host %s: %s' % (host, allDBResult['Message']))
                continue
            if not availableDBResult['OK']:
                gLogger.error('Host %s: %s' %
                              (host, availableDBResult['Message']))
                continue
        else:
            hasMySQL = False

        setup = infoResult['Value']['Setup']
        if setup != mySetup:
            continue

        cpu = hostResult['Value']['CPUModel'].strip()
        rDict = result['Value']
        # Components other than databases
        for compType in rDict:
            if componentType and componentType != compType:
                continue
            for system in rDict[compType]:
                components = sorted(rDict[compType][system])
                for component in components:
                    record = {'Installation': {}, 'Component': {}, 'Host': {}}
                    if rDict[compType][system][component]['Installed'] and \
                            component != 'ComponentMonitoring':
                        runitStatus = \
                            str(rDict[compType][system][component]['RunitStatus'])
                        if runitStatus != 'Unknown':
                            module = \
                                str(rDict[compType][system][component]['Module'])
                            record['Component']['System'] = system
                            record['Component']['Module'] = module
                            # Transform 'Services' into 'service', 'Agents' into 'agent' ...
                            record['Component']['Type'] = compType.lower()[:-1]
                            record['Host']['HostName'] = host
                            record['Host']['CPU'] = cpu
                            record['Installation']['Instance'] = component
                            record['Installation'][
                                'InstallationTime'] = datetime.utcnow()
                            record['Installation']['InstalledBy'] = user
                            records.append(record)

        # Databases
        csClient = CSAPI()
        cfg = csClient.getCurrentCFG()['Value']

        if hasMySQL:
            allDB = allDBResult['Value']
            availableDB = availableDBResult['Value']

            for db in allDB:
                # Check for DIRAC only databases
                if db in availableDB and db != 'InstalledComponentsDB':
                    # Check for 'installed' databases
                    isSection = cfg.isSection(
                        'Systems/' + availableDB[db]['System'] + '/' +
                        cfg.getOption('DIRAC/Setups/' + setup + '/' +
                                      availableDB[db]['System']) +
                        '/Databases/' + db + '/')
                    if isSection:
                        record = {
                            'Installation': {},
                            'Component': {},
                            'Host': {}
                        }
                        record['Component']['System'] = availableDB[db][
                            'System']
                        record['Component']['Module'] = db
                        record['Component']['Type'] = 'DB'
                        record['Host']['HostName'] = host
                        record['Host']['CPU'] = cpu
                        record['Installation']['Instance'] = db
                        record['Installation'][
                            'InstallationTime'] = datetime.utcnow()
                        record['Installation']['InstalledBy'] = user
                        records.append(record)

    monitoringClient = ComponentMonitoringClient()

    # Add the installations to the database
    for record in records:
        result = MonitoringUtilities.monitorInstallation(
            record['Component']['Type'], record['Component']['System'],
            record['Installation']['Instance'], record['Component']['Module'],
            record['Host']['CPU'], record['Host']['HostName'])
        if not result['OK']:
            gLogger.error(result['Message'])