Retrieving data from an external API via a Groovy Scripted module
1) Using Expert mode, define a resource as the hostname of the api in question, i.e. api.someapinamehere.com. For the purposes of this example, I'm going to make a call to worldtimeapi.org for data on the timezone America/Chicago to determine if daylight savings time is in effect. 2) Next, choose an available collector and group (optional) and click save. Note: normally you would also add your api user name (if any) and api token as properties, but in this case, it's not necessary. 2) Next, go to Settings -> LogicModules -> DataSources and click Add -> Datasource 3) Follow the steps below to adjust the DataSource: 4) Insert this script in the text box entitled Groovy Script under Collector Attributes import com.santaba.agent.groovyapi.expect.Expect; import com.santaba.agent.groovyapi.snmp.Snmp; import com.santaba.agent.groovyapi.http.*; import com.santaba.agent.groovyapi.jmx.*; import org.xbill.DNS.*; import groovy.json.*; //Defines host as the name of the resource added, in this case worldtimeapi.org def host = hostProps.get("system.hostname"); //Defines the path to endpoint def endpointUrl = "/api/timezone/America/Chicago" //Defines port. SSL would require 443. def port = 80 //Opens connection def httpClient = HTTP.open(host, port) //Get response def response = httpClient.get(endpointUrl) //Define status code def statusCode = httpClient.getStatusCode() //Close connection httpClient.close() //Extract values or handle error if(statusCode == 200){ response = new JsonSlurper().parseText(httpClient.getResponseBody()) if(response['dst'] == true){ status = 1 println("dstStatus=${status}") } else { status = 0 println("dstStatus=${status}") } } else { println("Your HTTP get request was not successful. StatusCode=${statusCode}") } 5) Add Normal datapoint named dstStatus 6) Save Module 7) You will see data painted in your portal for the device worldtimeapi.org under the name of the DataSource you created. You can learn more about this on this recently updated support doc: https://www.logicmonitor.com/support/terminology-syntax/scripting-support/access-a-website-from-groovy#505Views11likes0CommentsLogicMonitor Custom HTTP Integrations
In a little bit of a low profile announcement, we released the ability to import and export Custom HTTP integrations in LogicMonitor v.118! Using the collective available knowledge, I've sanitized and exported a handful of them as examples and/or starting points for anyone looking to utilize these solutions. See my 'LogicMonitor Integrations' Github repositoryto review and download the .JSON files for import to your LogicMonitor portal. Currently published integrations include: - Big Panda (Two Parts) -Freshdesk -Hipchat Server -Microsoft Teams -Neptune IO -OpsGenie -Status.IO -VictorOps -Zendesk278Views2likes10CommentsVariable json content in http integration
Hi all, we implemented custom http integration to create tickets in Jira Servicedesk. This works fine. However, new requirement is to put avariable (##jira.assetid##) inthe content to link the ticket to the correct asset. This works fine when the assetid is set. But when there is no asset id available the integration fails. Is there a way to make this output more dynami? I mean, if the value is set, write the value. If not, just write a default. Our json message (bit redacted): { "fields": { "summary": "##ALERTID## ##LEVEL## - ##HOST## ##DATASOURCE## ##DATAPOINT## ", "issuetype": { "id": "xxxxx" }, "project": { "key": "xxx" }, "description": { "type": "doc", "version": 1, "content": [ { "type": "paragraph", "content": [ { "text": "##MESSAGE## ##ALERTDETAILURL##", "type": "text" } ] } ] }, "customfield_10500": [##jira.organizationid##], "customfield_10681": [ { "workspaceId": "230f10d2-b759-405f-8d38-157edbe9e818", "id": "230f10d2-b759-405f-8d38-157edbe9e818:##jira.assetid##" } ] } }Solved101Views1like3Comments