Foglight

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?

  • Hi,

    You can try something like this :

    hostName = 'C-Tier1-DatabaseInstance'
    hostNameElements = hostName.split('-')

    Then you can find the parts like this :
    print hostNameElements [0]
    print hostNameElements [1]
    print hostNameElements [2]


    Regards
  • 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
  • I have this piece of code that I want to put into the rule condition that will dynamically determine information from the display name:

    def display_name= 'C-Tier2-DatabaseInstance'  <-------------------------  Needs to be 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"

     break

     case "B": emailAddr= "DatabasePortfolioB"

     break

     case "C": emailAddr= "DatabasePortfolioC"

     break

     case "D": emailAddr= "DatabasePortfolioD"

     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"

    }

    Is there a way to add topology objects to the rule condition section to that I can pull the display name in?  Are the global variables?

     

  • Hi,

    Assuming that you are working with Rule :  DBSS - Jobs Failed ...

    This rule uses the following topology type as scope : DBSS_Agent_Job_List

    So scope is of type DBSS_Agent_Job_List

     

     

    You can use the following code to take the host name of the database :

    scope.dbss_host.get("name")

     

     

    In General you can use the script console to write & test your code before applying to any rule :

    In your case :

    Open Script Console :

    Do a query for   !DBSS_Agent_Job_List

    Check your instances on the middle part,

    then select an instance of DBSS_Agent_Job_List and check it's properties on the bottom.

     

     

    Having selected an instance (this is your scope ! )

    You can create a new script  and write your code ...

    Press run and you can test it ...

     

     

    Regards