DX Unified Infrastructure Management

  • 1.  Replace alarm message via LUA replacing it with only part of initial message

    Posted Oct 19, 2016 04:01 PM

    Hello,

     

    I am receiving an alarm using the email2alarm probe and need to clean up the alarm message before it actually gets processed. I am trying to accomplish this via LUA script and preprocessing rule.

     

    I only want in the portion staring from Details to "windowsize" to be part of the alarm message and drop the rest. Has somebody done something similar and if so can you share the syntax to do this? Thanks!

     

    ==

    message:Hello,

     

    You are assigned 1 triggered incident:

    1) Incident #1
       Opened on: Oct 19 at 9:06 AM CDT
       Description: test01: Percentage CPU GreaterThan 1 undefined
       Details:
           resourceName: test01
           resourceId: /subscriptions/0000000/resourceGroups/US_IT/providers/Microsoft.Compute/virtualMachines/host
           resourceRegion: westus
           condition: {"metricName"=>"Percentage CPU", "metricValue"=>"18.3483333333333", "threshold"=>"1", "windowSize"=>"5", "timeAggregation"=>"Average", "operator"=>"GreaterThan"}
           resourceType: microsoft.compute/virtualmachines
           name: CPU Usage Percent



  • 2.  Re: Replace alarm message via LUA replacing it with only part of initial message

    Broadcom Employee
    Posted Oct 20, 2016 08:37 AM

    so this will require the use of regex.

    some articles on basic regex below:

    in the forum it is hard to tell the original format of the information. I THINK that condition is all on one line.
    condition: {"metricName"=>"Percentage CPU", "metricValue"=>"18.3483333333333", "threshold"=>"1", "windowSize"=>"5", "timeAggregation"=>"Average", "operator"=>"GreaterThan"}
    Did you want the resource and name below that as well?
    I use a tool call regexBuddy to check my syntax and help build poper regex statements
    I would think a regex statement such as
    /windowSize.*/
    would return everything on the same line after windowSize.
    hope this helps


  • 3.  Re: Replace alarm message via LUA replacing it with only part of initial message

    Posted Oct 20, 2016 03:25 PM

    Gene, thanks for the reply. In regexbuddy what language do you select for building UIM based expressions?



  • 4.  Re: Replace alarm message via LUA replacing it with only part of initial message

    Posted Oct 20, 2016 05:51 PM

    Not sure if regex does the tick here. I am trying to create a new alarm message with only the following portion of the message:

     

    Details:
           resourceName: test01
           resourceId: /subscriptions/0000000/resourceGroups/US_IT/providers/Microsoft.Compute/virtualMachines/host
           resourceRegion: westus
           condition: {"metricName"=>"Percentage CPU", "metricValue"=>"18.3483333333333", "threshold"=>"1", "windowSize"=>"5", "timeAggregation"=>"Average", "operator"=>"GreaterThan"}
           resourceType: microsoft.compute/virtualmachines
           name: CPU Usage Percent

     

    This means I guess I need to do some match to tell LUA to only pick the section of the message that starts with details and ends at name.

     

    Thoughts?



  • 5.  Re: Replace alarm message via LUA replacing it with only part of initial message
    Best Answer

    Broadcom Employee
    Posted Oct 26, 2016 10:02 AM

    perl is the language you choose in regex buddy.

     

    I guess you could use string matching as well but i think you are better off with regex as the messages will probably be dynamic in some way.



  • 6.  Re: Replace alarm message via LUA replacing it with only part of initial message

    Posted Oct 26, 2016 10:44 AM

    Thanks Gene for the pointers. Very helpful as usual.

     

    Johannes



  • 7.  Re: Replace alarm message via LUA replacing it with only part of initial message

    Posted Oct 30, 2017 07:57 PM

    Dutchie/Gene, I hope to learn about this. May I ask what is the resolution? I am also trying to do the same. I wanted to replace the “host_name” in below message. Kindly teach me how to do this in LUA scripting that is running in the Pre-Processing Rule. Thanks.

     

    IM_SA_UNIX host_name ECC_Errors There is issue in ECC on this server.



  • 8.  Re: Replace alarm message via LUA replacing it with only part of initial message

    Posted Jul 11, 2018 03:24 PM

    Sharing the solution I got on this.

     

    event.message = string.gsub(event.message,"host_name",event.robot)

    return (event)