Get correct service name (MS SQL Server) example

For MS SQL server, some sites use a placeholder name for the SERVICE_NAME. This example shows how to replace the placeholder with the actual service name.

In the Get correct service name policy, the MS SQL server instance uses a placeholder name, MS SQL SERVER for the SERVICE_NAME. The service name and the server hostname are concatenated into SERVER_HOSTNAME, separated by a backslash (\). For example:
SERVICE_NAME SERVER_HOSTNAME
MS SQL SERVER MY_SQL_SERVICE\MY_HOST
This example has one rule and two rule actions.
  • Session level criteria:
    • Server IP address = 20.20.20.20
    • Database type = MS SQL SERVER
  • Rule actions:
    1. TRANSFORM SERVICE NAME

      This rule finds all instances of SERVER HOSTNAME that contain a backslash. The output (for SERVER HOSTNAME) is the data after the backslash.

      • Source = SERVER HOSTNAME
      • Match pattern = (.*)\\(.*)
      • Output format = \2
    2. TRANSFORM SERVER HOSTNAME

      This rule moves the first part of the original SERVER HOSTNAME and moves it to the SERVICE NAME.

      • Source = SERVER HOSTNAME
      • Match pattern = (.*)\\(.*)
      • Output format = \1

The final output is as follows:

SERVICE_NAME SERVER_HOSTNAME
MY_SQL_SERVICE MY_HOST

SR language example

SR_POLICIES
{
        IF (DB_TYPE = 'MS SQL SERVER' SERVER_IP = '20.20.20.20')
        {
                TRANSFORM_SERVICE_NAME SOURCE = SERVER_HOST_NAME MATCH_PATTERN = '(.*)\\(.*)' OUTPUT_FORMAT = '\2' 
                TRANSFORM_SERVER_HOST_NAME MATCH_PATTERN = '(.*)\\(.*)' OUTPUT_FORMAT = '\1'
        }
}