Forum Discussion
5 years ago
Last one for cluster health status.
<?xml version="1.0" encoding="UTF-8" ?> <feed version="1.0" hasPendingRequests="false" > <company></company> <status>200</status> <errmsg>OK</errmsg> <interval>0</interval> <entry type="predatasource"> <version>1573572264</version> <name>Elasticsearch_Cluster_Health_Status_veri</name> <displayedas>Cluster Health Status_veri</displayedas> <description>Elasticsearch Cluster status: 2 == green, 1 == yellow, 0 == red.</description> <collector>script</collector> <hasMultiInstances>false</hasMultiInstances> <schedule>60</schedule> <appliesTo>hasCategory("elasticsearch") or system.deviceId == "6986"</appliesTo> <wildcardauto>false</wildcardauto> <wildcardpersist>false</wildcardpersist> <wildcardlinuxscript></wildcardlinuxscript> <wildcardlinuxcmdline></wildcardlinuxcmdline> <wildcardwinscript></wildcardwinscript> <wildcardwincmdline></wildcardwincmdline> <wildcardgroovyscript></wildcardgroovyscript> <wildcardschedule>1440</wildcardschedule> <wildcarddisable>false</wildcarddisable> <wildcarddeleteinactive>false</wildcarddeleteinactive> <agdmethod>none</agdmethod> <agdparams></agdparams> <group></group> <tags>cluster,elasticsearch,health,status</tags> <technology></technology> <adlist><![CDATA[{"agdmethod":"none","agdparams":"","id":0,"filters":[],"params":{}}]]></adlist> <schemaVersion>2</schemaVersion> <dataSourceType>1</dataSourceType> <attributes> <attribute> <name>scripttype</name> <value>embed</value> <comment></comment> </attribute> <attribute> <name>scriptgroovy</name> <value>import groovy.json.JsonSlurper import org.apache.http.client.methods.HttpGet import org.apache.http.conn.ssl.SSLConnectionSocketFactory import org.apache.http.conn.ssl.SSLContextBuilder import org.apache.http.conn.ssl.TrustSelfSignedStrategy import org.apache.http.impl.client.HttpClients import org.apache.http.util.EntityUtils def hostname = hostProps.get("system.hostname") def slurper = new JsonSlurper() def cluster_status_map = ["green" : 2, "yellow": 1, "red" : 0] def request_endpoint = "http://${hostname}:9200/_cluster/health" def request_headers = ["User-Agent" : "LogicMonitor Polling Agent", "Content-Type": "application/json"]; /* * http_get - do an HTTP GET with apache http client * @param string request_endpoint * @param map request_headers * @return map [code,status,body] */ def http_get(request_endpoint, request_headers) { def http_get = new HttpGet(request_endpoint); // what type of request? if (request_endpoint.startsWith('https:')) { // https -- create an ssl-safe client ssl_builder = new SSLContextBuilder(); ssl_builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); ssl_sf = new SSLConnectionSocketFactory(ssl_builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); client = HttpClients.custom().setSSLSocketFactory(ssl_sf).build(); } else { // vanilla http -- use the default client client = HttpClients.createDefault(); } // iterate over request headers request_headers.each() { key, value -> http_get.setHeader(key, value); } def http_response = client.execute(http_get); def response_message = http_response.getEntity(); def response_status = http_response.getStatusLine(); def response_code = response_status.getStatusCode(); def response_body = EntityUtils.toString(response_message); http_response.close(); return; } // Make HTTP GET call def get_response = http_get(request_endpoint, request_headers); // Parse result to JSON def result = slurper.parseText(get_response['body']) // Print the results println cluster_status_map[result.status] return 0;</value> <comment></comment> </attribute> <attribute> <name>windowsscript</name> <value></value> <comment></comment> </attribute> <attribute> <name>linuxscript</name> <value></value> <comment></comment> </attribute> <attribute> <name>windowscmdline</name> <value></value> <comment></comment> </attribute> <attribute> <name>linuxcmdline</name> <value></value> <comment></comment> </attribute> </attributes> <datapoints> <datapoint> <name>cluster_status</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>none</postprocessormethod> <postprocessorparam></postprocessorparam> <usevalue>output</usevalue> <alertexpr>= 1 0</alertexpr> <alertmissing>1</alertmissing> <alertsubject></alertsubject> <alertbody>The ElasticSearch Cluster at ##HOST## is reporting a state of ##VALUE## putting it in a ##LEVEL## state. The cluster has been in this state since ##START## or for ##DURATION##.</alertbody> <enableanomalyalertsuppression></enableanomalyalertsuppression> <adadvsettingenabled>false</adadvsettingenabled> <warnadadvsetting></warnadadvsetting> <erroradadvsetting></erroradadvsetting> <criticaladadvsetting></criticaladadvsetting> <description>ElasticSearch Cluster status: 2 = green, 1 = yellow, 0 = red.</description> <maxvalue>2</maxvalue> <minvalue>0</minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>1</alertTransitionIval> <alertClearTransitionIval>0</alertClearTransitionIval> </datapoint> </datapoints> <graphs> <graph> <name>Elasticsearch Cluster Health Status</name> <title>Elasticsearch Cluster Health Status</title> <verticallabel>status</verticallabel> <rigid>false</rigid> <maxvalue>2.0</maxvalue> <minvalue>0.0</minvalue> <displayprio>1</displayprio> <timescale>1day</timescale> <base1024>false</base1024> <graphdatapoints> <graphdatapoint> <name>cluster_status</name> <datapointname>cluster_status</datapointname> <cf>1</cf> </graphdatapoint> </graphdatapoints> <graphvirtualdatapoints> </graphvirtualdatapoints> <graphdatas> <graphdata> <type>1</type> <legend>Status</legend> <color>blue</color> <datapointname>cluster_status</datapointname> <isvirtualdatapoint>false</isvirtualdatapoint> </graphdata> </graphdatas> </graph> </graphs> <overviewgraphs> </overviewgraphs> <scripts> </scripts> </entry> </feed>
Related Content
- 6 days ago
- 11 months ago
- 9 months ago
- 2 years ago