VMware Cloud Community
johnp_hyperic
Contributor
Contributor

Including group name in alert email template

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
Reply
0 Kudos
3 Replies
jvalkeal_hyperi

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.
Reply
0 Kudos
jvalkeal_hyperi

Ok, it works. Here's modified default template for quick example.
Reply
0 Kudos
johnp_hyperic
Contributor
Contributor

Thats excellent - implemented, tested and running!
Reply
0 Kudos