Insight + Groovy Script => Found and assign automatically the Servers? Almost the solution :-)

Julian from AF June 24, 2020

Hello,

i already contacted Insight support about my demand, they said i need to do it by Groovy Script : 

I have an object type called "Servers". All server are automatically added using the discovery. An specific Attribute for each object called FQDN, it's simply the full name of the servers. Exemple : AFDAOS.fr***.int. 

To monitore our server, we using Centreon (based on nagios), when we have a critical alert, an email is sent to mailbox Jira who create the issue. The subject of the mail is our summary. Exemple : ** PROBLEM alert - AFDAOS.f***.int/AX TEST Service is CRITICAL **.

The result expected : Assign automatically the good server depending of the summary. In this case, the system need to found the part "AFDAOS.fr***.int" inside the summary and automatically assign it to this object inside a specific custom field insight. We already try (we Mindville support ) to do it using IQL but it's not working with the LIKE command.

I never use Groovy script and i don"t have any idea how to start to do it. It doesn't seem too complicated but i need help to start.
2020-06-24 12_40_37-Insight - AF Jira.png2020-06-24 12_41_34-[IT-6741] __ PROBLEM alert - AFDAOS.francois.int_AX TEST Service is CRITICAL __ .png
Thank you !

1 answer

0 votes
Julian from AF June 29, 2020

Hello... I'm learned Groovy (as much as i can) and i'm almost the result i want ! 

Here my code :

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.riadalabs.jira.plugins.insight.services.model.CommentBean;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectAttributeBean
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean

 

Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);

Class iqlFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade");
def iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(iqlFacadeClass);

def objects = iqlFacade.findObjectsByIQLAndSchema(10,"objectTypeId = 2443");
//def test = "AF-172738"
//def ObjectInsightBean = objectFacade.loadObjectBean(test)
//log.warn("ObjectInsightBean " + ObjectInsightBean)
def n = 0
(objects).each {
CurrentObject = objects[n]
def FQDNValue = objectFacade.loadObjectAttributeBean(CurrentObject.getId(),47464).getObjectAttributeValueBeans()[0]; //Load Attribute Value
log.warn("Server " + objects[n])
//log.warn("FQDNValue " + FQDNValue)
//FQDNValueSTR = FQDNValue.ToString()
log.warn("FQDNValue " + FQDNValue)
result = (issue.getSummary().contains(FQDNValue))

log.warn("result " + result)
n ++

The output is : 

2020-06-29 16:45:28,650 [http-nio-8080-exec-17] | Server AFAW16-FS01 (AF-173140)
2020-06-29 16:45:28,650 [http-nio-8080-exec-17] | FQDNValue [2629351(AFAW16-FS01.francois.int)]

I have the following error :

GroovyInsightException: No signature of method: java.lang.String.contains() is applicable for argument types: (com.riadalabs.jira.plugins.insight.services.model.ObjectAttributeValueBean) values: [[2629351(AFAW16-FS01.francois.int)]] Possible solutions: contains(java.lang.CharSequence), contains(java.lang.CharSequence), toString(), toString(), toString(), notify()'

 

The problem is i want use the contain in (issue.getSummary().contains(FQDNValue)), FQDNValue have the good value but seems not be string value. It's [2629351(AFAW16-FS01.xxxx.int) (what's the 2629351 value?? I just want compare the AFAW16-FS01.xxxx.int . 

Have i to import a specific plugin, use another syntax? I tried FQDNValueSTR = FQDNValue.ToString() but it's not working....

Thank you !!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events