This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to Parse a string in a rule condition

I have the need to take a string that is used as a Display Name for a database instance in Foglight for SQL Server and parse it.  For instance, the Display name might be something like C-Tier1-DatabaseInstance.   I am building a rule where I have the need to split the string in separate variables to build conditional statements.  What is the syntax to do something like this?

Parents
  • Hi,

    Example

    4 Rules Variables :

    1:
    Name : DBSS_HostName (Expression Type)
    Code : return scope.dbss_host.get("name");


    2:
    Name : myEmailAddr (Expression Type)
    Code :
    switch (@DBSS_HostName.split("-")[0]) {
    case "A": emailAddr = "DatabasePortfolioA@exchange.schwab.com"
    break
    case "B": emailAddr= "DatabasePortfolioB@exchange.schwab.com"
    break
    case "C": emailAddr= "DatabasePortfolioC@exchange.schwab.com"
    break
    case "D": emailAddr= "DatabasePortfolioD@exchange.schwab.com"
    break
    default: emailAddr= "SQLOperations@exchange.schwab.com"
    }
    return emailAddr;

    You can use this as the @emailAddr as the email recipient.


    3:Name : myPriority (Expression Type)
    Code :
    switch (@DBSS_HostName.split("-")[1]) {
    case "Tier1": Priority = 1
    break
    case "Tier2": Priority = 2
    break
    default: Priority = 3
    }
    return Priority;


    etc


    Regards
Reply
  • Hi,

    Example

    4 Rules Variables :

    1:
    Name : DBSS_HostName (Expression Type)
    Code : return scope.dbss_host.get("name");


    2:
    Name : myEmailAddr (Expression Type)
    Code :
    switch (@DBSS_HostName.split("-")[0]) {
    case "A": emailAddr = "DatabasePortfolioA@exchange.schwab.com"
    break
    case "B": emailAddr= "DatabasePortfolioB@exchange.schwab.com"
    break
    case "C": emailAddr= "DatabasePortfolioC@exchange.schwab.com"
    break
    case "D": emailAddr= "DatabasePortfolioD@exchange.schwab.com"
    break
    default: emailAddr= "SQLOperations@exchange.schwab.com"
    }
    return emailAddr;

    You can use this as the @emailAddr as the email recipient.


    3:Name : myPriority (Expression Type)
    Code :
    switch (@DBSS_HostName.split("-")[1]) {
    case "Tier1": Priority = 1
    break
    case "Tier2": Priority = 2
    break
    default: Priority = 3
    }
    return Priority;


    etc


    Regards
Children
No Data