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
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
'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' record['Component']['Module'] = service record['Component']['Type'] = 'external' record['Host']['HostName'] = host record['Host']['CPU'] = cpu record['Installation']['Instance'] = service record['Installation']['InstallationTime'] = datetime.utcnow() records.append(record) # Add the installations to the database for record in records: result = monitoringClient.addInstallation(record['Installation'], record['Component'], record['Host'], True) if not result['OK']: gLogger.error(result['Message'])