HEX
Server: Apache/2.4.6 () PHP/7.4.33
System: Linux chile-dev-app-1 5.4.17-2136.315.5.el7uek.x86_64 #2 SMP Wed Dec 21 19:57:57 PST 2022 x86_64
User: apache (48)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //lib/python2.7/site-packages/sos/plugins/exadata.py
# This file is part of the sos project: https://github.com/sosreport/sos  
#                                                                         
# This copyrighted material is made available to anyone wishing to use,   
# modify, copy, or redistribute it subject to the terms and conditions of 
# version 2 of the GNU General Public License.                            
#                                                                         
# See the LICENSE file in the source distribution for further information.

from sos.plugins import Plugin, RedHatPlugin
import os
import re
import subprocess
                                                                       
class LibExaClient(Plugin, RedHatPlugin):          
	"""
	Exadata Node Data Collection
	"""

	plugin_name = 'exadata'                                
	profiles = ('system', 'exadata')
	short_desc = "Exadata info"
	
	imageInfo = "/usr/local/bin/imageinfo"
 
	image_cmd = [
		'imageinfo',
		'imagehistory'
	]
	
	cell_ip = []
	local_ip =[]
	
	def cellos_logs(self):
		self.add_copy_spec([
			"/var/log/cellos/vm_maker*",
			"/var/log/cellos/*console.log*"
		])
	
	def exa_cmds(self):
		for k in self.image_cmd:
			self.add_cmd_output('%s' % (k), foreground=True)
	
	def exa_conf(self):
		try:
			self.add_copy_spec([
				"/etc/libvirt/exadata.conf",
			])
		except Exception as e:
			print(e)

	def local_ips(self):
		lcl_ip_out = []
		lcl_ip = "rds-info -n | awk '{print $1}'| sort -u | egrep -v 'LocalAddr|RDS|^$|Connections|RemoteAddr'"
		for line2 in subprocess.check_output(lcl_ip, shell=True).splitlines():
			lcl_ip_out.append(line2.decode('utf-8'))
		lcl_ip_out.sort()
		return lcl_ip_out

	def cells_ip(self):
		cellip_list=[]
		cell_file = open('/etc/oracle/cell/network-config/cellip.ora', 'r')
		cell_IP = cell_file.readlines()
		for line in cell_IP:
			cellip_list.extend(line.split('"')[1].rsplit(";"))
		cell_file.close()
		cellip_list.sort()
		return cellip_list

	def rem_ips(self):
		r_ip=[]
		rem_ip = "rds-info -n | awk '{print $2}' | sort -u | egrep -v 'LocalAddr|RDS|^$|Connections:|RemoteAddr'"
		for line2 in subprocess.check_output(rem_ip, shell=True).splitlines():
			r_ip.append(line2.decode('utf-8'))
		r_ip.sort()
		return r_ip
   
	def collect_IP(self):
		rm_ip = []
		lcip_cellip = []     
		imageinfo_out = subprocess.check_output(self.imageInfo, shell=True).decode()
		if imageinfo_out != "":
			for k in imageinfo_out.split('\n'):
				# This is to verify if the node is COMPUTE or STORAGE
                                # Earlier the 'Node type' was shown as COMPUTE in imageinfo
                                # currently as "GUEST"
				if k.startswith("Node type"):
					type1 = list(k.split())
					if type1[-1] == "GUEST":
						# Collect local ip using the first column of rds-info -n output
						lcl_ips = self.local_ips()
						#Collect cell IP from second column of rds-info -n anc compare with cellip.ora file
						cell_ip = self.cells_ip()
						# Remote DB IP is the difference between the below
						rm_ip = self.rem_ips()
						lcip_cellip = lcl_ips + cell_ip
						rmdb_ip = list(set(rm_ip) - set(lcip_cellip))
						rmdb_ip.sort()
						ip_list = "\n----Local-DB_IP-----\n" '%s' "\n" % ('\n'.join(lcl_ips)) + \
						"\n----Remote-DB_IP-----\n" '%s' "\n" % ('\n'.join(rmdb_ip)) + \
						"\n----Cell_IP-----\n" '%s' "\n" % ('\n'.join(cell_ip))
						self.add_string_as_file( '%s' % (ip_list), filename='Exadata_ip_list')
				elif k.startswith("Active node type"):
					type1 = list(k.split())
					if type1[-1] == "STORAGE":
						# Collect local ip using the first column of rds-info -n output
						lcl_ips = self.local_ips()
						rm_ip = self.rem_ips()
						rmdb_ip = list(set(rm_ip) - set(lcl_ips))
						rmdb_ip.sort()
						ip_list = "\n----Local-DB_IP-----\n" '%s' "\n" % ('\n'.join(lcl_ips)) + \
						"\n----Remote_IP-----\n" '%s' "\n" % ('\n'.join(rmdb_ip))
						self.add_string_as_file( '%s' % (ip_list), filename='Exadata_ip_list')
     
	def setup(self):
		exaval = os.path.exists(self.imageInfo)
		if exaval is True:
			self.exa_cmds()
			self.exa_conf()
			self.collect_IP()
			self.cellos_logs()
		else:
			return
# vim: set ts=4 sw=4