vCenter

 View Only
  • 1.  Including group name in alert email template

    Posted Jan 06, 2009 04:32 AM
    Hi All,

    I'm wondering if there is a method to include the group in which a resource resides in email alerts. I am using Hyperic to monitor a number of customers servers, which each customer having a group in Hyperic. I have a few customers whose servers are called "Server" so it's important I can differentiate between them.

    I know you can alter the templates by editing the text_email and html_email gsp files, but I'm not sure what the property would be for resouce groups.

    JP


  • 2.  RE: Including group name in alert email template

    Posted Jan 06, 2009 10:50 AM
    Here's how to list those through groovy console.

    ----
    import org.hyperic.hq.authz.server.session.ResourceGroupManagerEJBImpl
    import org.hyperic.hq.authz.server.session.ResourceManagerEJBImpl
    import org.hyperic.hq.appdef.shared.AppdefEntityID

    def rgMan = ResourceGroupManagerEJBImpl.one
    def rMan = ResourceManagerEJBImpl.one

    def aid = new AppdefEntityID("3:10247")
    def r = rMan.findResource(aid)

    def collection = rgMan.getGroups(r)

    def gStr = new StringBuffer()
    gStr.append("Groups containing this resource:\n")

    collection.each{
    if(!it.system)
    gStr.append(it.name + "\n")

    }

    gStr

    ----
    In this example aid value can be found from link when browsing resources.

    http://localhost:7080/Resource.do?eid=3:10247

    To use this in text_email.gsp, do something like this:

    1. add import to start of file. (there's already few of those)
    import org.hyperic.hq.authz.server.session.ResourceGroupManagerEJBImpl

    2. gsp template runner already gives resource, so add below between <% %> section:


    def rgMan = ResourceGroupManagerEJBImpl.one

    def collection = rgMan.getGroups(resource)

    def gStr = new StringBuffer()
    gStr.append("Groups containing this resource:\n")

    collection.each{
    if(!it.system)
    gStr.append(it.name + "\n")

    }

    3. finally in text section add new variable to print it to output text

    ${gStr}


    I havent tried this but it should work.


  • 3.  RE: Including group name in alert email template

    Posted Jan 06, 2009 11:41 AM
    Ok, it works. Here's modified default template for quick example.


  • 4.  RE: Including group name in alert email template

    Posted Jan 07, 2009 06:24 AM
    Thats excellent - implemented, tested and running!