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
  • Thanks George. That was what I was looking for. Now i need to make it dynamic. I want to put the code into the run condition of alarm to set rule variables dynamically. Here is the code I am working with:

    def display_name= 'C-Tier2-DatabaseInstance' <<----NEED TO MAKE DYNAMIC
    def portfolio = display_name.split("-")[0];
    def tier = display_name.split("-")[1];
    def instance = display_name.split("-")[2];

    def DBGroup = portfolio
    switch (DBGroup) {
    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"
    }

    def Priority = tier
    switch (Priority) {
    case "Tier1": Priority = 1
    break
    case "Tier2": Priority = 2
    break
    default: Priority = 3
    }

    def urgency = Priority
    switch (urgency) {
    case 1: urgency = "High"
    break
    case 2: urgency = "Medium"
    break
    default: urgency = "Low"
    }



    I need the condition to read the display name and then do the work. Is there a way to add topology objects to the rule condition so that this condition will be evaluated for every instance in our environment? I am trying to put together a generic piece of code that we can use for all of the customized rules that we copy from existing rules. The data that we are extrapolating will be used to populate a template within our incident ticketing system
Reply
  • Thanks George. That was what I was looking for. Now i need to make it dynamic. I want to put the code into the run condition of alarm to set rule variables dynamically. Here is the code I am working with:

    def display_name= 'C-Tier2-DatabaseInstance' <<----NEED TO MAKE DYNAMIC
    def portfolio = display_name.split("-")[0];
    def tier = display_name.split("-")[1];
    def instance = display_name.split("-")[2];

    def DBGroup = portfolio
    switch (DBGroup) {
    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"
    }

    def Priority = tier
    switch (Priority) {
    case "Tier1": Priority = 1
    break
    case "Tier2": Priority = 2
    break
    default: Priority = 3
    }

    def urgency = Priority
    switch (urgency) {
    case 1: urgency = "High"
    break
    case 2: urgency = "Medium"
    break
    default: urgency = "Low"
    }



    I need the condition to read the display name and then do the work. Is there a way to add topology objects to the rule condition so that this condition will be evaluated for every instance in our environment? I am trying to put together a generic piece of code that we can use for all of the customized rules that we copy from existing rules. The data that we are extrapolating will be used to populate a template within our incident ticketing system
Children
No Data