Common Functions


Page description

From version 8.2 ADDM has option that all patterns can import functions from other *.tpl modules. Current page contains descriptions of all common functions, which are used by the pattern modules from Common_Functions.tpl file.

dsn_rdbms_servers

This function returns a list of the related RDBMS SIs by the DSN.

Input variables

  • host - Host node, the pattern is running on.
  • dsn_name - Data Source Name, used by the product

Output variables

  • db_srvs - List of the related RDBM servers. Currently Oracle Database Server, Microsoft SQL Server and IBM DB2 Database Server are supported.

Function functionality

The function queries 'HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\<DSN_NAME>\Driver' registry key and parses the output with the regexes:

RDBMS type

Regular Expression

Oracle Database Server

regex '\\SQORA'

Microsoft SQL Server

regex '\\SQLSRV'

IBM DB2 Database Server

regex '\\DB2CLI'

Then the function deploys approaches, specific to the RDBMS type and searches for related SIs.
 The following scenarios are used:

Oracle

If DSN type is 'Oracle Database Server', the function extracts Oracle home from driver key with help of regex:

  • '(?i)^(\w:\\.+)BIN\\SQORA.*\.dll'

Then it reads '<ORACLE_HOME>network\admin\tnsnames.ora' file and extracts DB host and port with respective regexes:

RDBMS attribute

Regular Expression

Oracle host

regex '(?is)\s*%global_name%\s*=\s*\(\s*DESCRIPTION.*?HOST\s*=\s*(\S+)\)'

Oracle port

regex '(?is)\s*%global_name%\s*=\s*\(\s*DESCRIPTION.*?PORT\s*=\s*(\d+\s*)\)'

Global name, used in above regexes is extracted from the following registry key:

  • 'HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\<DSN_NAME>\ServerName'

DB2

In case of IBM DB2 Database Server, the function launches 'db2cmd -c -i -w db2 list system odbc data sources | findstr /C:"<DSN>"' command to extract DB2 Copy name from its output using regex:

  • '(?i)IBM DB2 ODBC DRIVER - (\S+)'

It then looks for the profile file (db2cli.ini) location in registry:

  • 'HKEY_LOCAL_MACHINE\SOFTWARE\IBM\DB2\InstalledCopies\<COPY_NAME>\PROFILES\<PROFILE_NAME>\DB2INSTPROF'

This file contains DB2 instance alias, which is extracted with help of regular expression:

  • '(?i)%dsn_name%\]\r*\n\s*DBALIAS=(\S+)'

If DB2 alias was successfully obtained, the function runs 'db2cmd -c -i -w db2 list database directory' command, to find related Node name by matching the output against regex:

  • '(?i)Database\salias\s*=\s*%db_alias%(?:\r*\n.*?)+Node\sname\s*=\s*(\S+)'

If successful, the last command 'db2cmd -c -i -w db2 list node directory' is launched to extract database host and port with respective regexes:

RDBMS attribute

Regular Expression

DB2 host

regex '(?i)Node\sname\s+=\s+%node_name%(?:\r+\n.+)+?Hostname\s+=\s+(\S+)'

DB2 port

regex '(?i)Node\sname\s+=\s+%node_name%(?:\r+\n.+)+?Service\sname\s+=\s+(\d+)'

MS SQL

In case of MS SQL Server, the function queries the following registry key:

  • 'HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\<DSN_NAME>\ServerName'

Then it extracts related RDBM Server instance details:

RDBMS attribute

Regular Expression

MSSQL host

regex '(\S+)\\'

MSSQL port

regex '\\(\S+)'

If regexes failed to extract the host and instance, the function considers that default MS SQL instance is used and sets key value as DB host. Instance name is set to 'MSSQLSERVER' in this case.

Open Issues

There are no known open issues with this pattern.

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*

BMC Discovery content reference