def monitorInstallation(componentType,
                        system,
                        component,
                        module=None,
                        cpu=None,
                        hostname=None):
    """
    Register the installation of a component in the ComponentMonitoringDB
    """
    monitoringClient = ComponentMonitoringClient()

    if not module:
        module = component

    # Retrieve user installing the component
    user = None
    result = getProxyInfo()
    if result["OK"]:
        proxyInfo = result["Value"]
        if "username" in proxyInfo:
            user = proxyInfo["username"]
    else:
        return result
    if not user:
        user = "******"

    if not cpu:
        cpu = "Not available"
        for line in open("/proc/cpuinfo"):
            if line.startswith("model name"):
                cpu = line.split(":")[1][0:64]
                cpu = cpu.replace("\n", "").lstrip().rstrip()

    if not hostname:
        hostname = socket.getfqdn()
    instance = component[0:32]

    result = monitoringClient.installationExists(
        {
            "Instance": instance,
            "UnInstallationTime": None
        },
        {
            "Type": componentType,
            "DIRACSystem": system,
            "DIRACModule": module
        },
        {
            "HostName": hostname,
            "CPU": cpu
        },
    )

    if not result["OK"]:
        return result
    if result["Value"]:
        return S_OK("Monitoring of %s is already enabled" % component)

    result = monitoringClient.addInstallation(
        {
            "InstallationTime": datetime.datetime.utcnow(),
            "InstalledBy": user,
            "Instance": instance
        },
        {
            "Type": componentType,
            "DIRACSystem": system,
            "DIRACModule": module
        },
        {
            "HostName": hostname,
            "CPU": cpu
        },
        True,
    )
    return result
Exemple #2
0
def monitorInstallation(componentType,
                        system,
                        component,
                        module=None,
                        cpu=None,
                        hostname=None):
    """
  Register the installation of a component in the ComponentMonitoringDB
  """
    monitoringClient = ComponentMonitoringClient()

    if not module:
        module = component

    # Retrieve user installing the component
    user = None
    result = getProxyInfo()
    if result['OK']:
        proxyInfo = result['Value']
        if 'username' in proxyInfo:
            user = proxyInfo['username']
    else:
        return result
    if not user:
        user = '******'

    if not cpu:
        cpu = 'Not available'
        for line in open('/proc/cpuinfo'):
            if line.startswith('model name'):
                cpu = line.split(':')[1][0:64]
                cpu = cpu.replace('\n', '').lstrip().rstrip()

    if not hostname:
        hostname = socket.getfqdn()
    instance = component[0:32]

    result = monitoringClient.installationExists(
        {
            'Instance': instance,
            'UnInstallationTime': None
        }, {
            'Type': componentType,
            'System': system,
            'Module': module
        }, {
            'HostName': hostname,
            'CPU': cpu
        })

    if not result['OK']:
        return result
    if result['Value']:
        return S_OK('Monitoring of %s is already enabled' % component)

    result = monitoringClient.addInstallation(
        {
            'InstallationTime': datetime.datetime.utcnow(),
            'InstalledBy': user,
            'Instance': instance
        }, {
            'Type': componentType,
            'System': system,
            'Module': module
        }, {
            'HostName': hostname,
            'CPU': cpu
        }, True)
    return result
Exemple #3
0
    # Services
    serviceResult = {}
    for service in services:
        serviceResult[service] = resultService[service]['Value'][host]
        if not serviceResult[service]['OK']:
            gLogger.warn('Host %s: %s' %
                         (host, serviceResult[service]['Message']))
            continue

        # Is the service already in the database?
        result = monitoringClient.installationExists(
            {
                'UnInstallationTime': None,
                'Instance': service
            }, {
                'System': 'External',
                'Module': service,
                'Type': 'external'
            }, {
                'HostName': host,
                'CPU': cpu
            })
        if not result['OK']:
            gLogger.error('Host %s: %s' % (host, result['Message']))
        else:
            if result['Value']:
                gLogger.warn(
                    'Host %s: Installation of %s already exists in database' %
                    (host, service))
            else:
                record = {'Installation': {}, 'Component': {}, 'Host': {}}
                record['Component']['System'] = 'External'