MrTK

Members
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

1 Neutral

About MrTK

  • Rank
    Community Member
  1. Problem When we onboard ESXi hosts we use esx.user/esx.pass, we do not configure SNMP on our hosts. We found that details about the host hardware and esx were not getting populated. Checked with support and they confirmed that LM uses SNMP to pull that information. Solution Wrote a PropertySource which uses the ESXi API (esx.user/esx.pass must be set), to pull the information. I used an existing LM DataSource as the basis for the script. E7T2C7
  2. MrTK

    Script to rename devices

    This script makes the devices displayName the same as the sysName. It can be easily modified to update any property for any other property, or appending. We use a couple different variations of this script to keep our standard naming conventions consistent throughout LogicMonitor (and our CMDB). Made for API v1, I have not looked at how this might be different/easier with v2. Just sharing in case others find it useful. Script was adapted from a script example @Chengjie Zhu posted. import org.apache.http.client.methods.HttpGet import org.apache.http.client.methods.HttpPut import org.apache.http.impl.client.CloseableHttpClient import org.apache.http.impl.client.HttpClients import org.apache.http.util.EntityUtils import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Hex; import groovy.json.*; import org.apache.http.entity.StringEntity; import org.apache.http.entity.ContentType; //define credentials and url def accessId = '##accessid##'; def accessKey = '##accesskey##'; def account = '##subdomain##'; // Change GroupID def GroupID = '3919' def resourcePath = "/device/groups/" + GroupID+ "/devices" def queryParams = '?filter=systemProperties.name:system.sysname&size=200' def url = "https://" + account + ".logicmonitor.com" + "/santaba/rest" + resourcePath + queryParams def deviceID = [] //def sysName = [] //get current time epoch = System.currentTimeMillis(); //calculate signature requestVars = "GET" + epoch + resourcePath; hmac = Mac.getInstance("HmacSHA256"); secret = new SecretKeySpec(accessKey.getBytes(), "HmacSHA256"); hmac.init(secret); hmac_signed = Hex.encodeHexString(hmac.doFinal(requestVars.getBytes())); signature = hmac_signed.bytes.encodeBase64(); // HTTP Get CloseableHttpClient httpclient = HttpClients.createDefault(); httpGet = new HttpGet(url); httpGet.addHeader("Authorization" , "LMv1 " + accessId + ":" + signature + ":" + epoch); response = httpclient.execute(httpGet); responseBody = EntityUtils.toString(response.getEntity()); JsonSlurper slurper = new JsonSlurper() def json = slurper.parseText(responseBody) def items = json.data.items // Iterate all of devices in the parent group // Please note: It does not work on the group's child groups. for (i=0; i<items.size(); i++){ deviceID.add(items[i].id) // Use regex to get the system property you want, here I wanted sysname sysName = items[i].systemProperties =~/(?<=sysname, value:)([^\]]*)/ items[i].displayName = sysName[0][0] items[i] = JsonOutput.toJson(items[i]) StringEntity params = new StringEntity(items[i],ContentType.APPLICATION_JSON); println items[i] epoch = System.currentTimeMillis(); //get current time resourcePath = "/device/devices/" + deviceID[i] requestVars = "PUT" + epoch + items[i] + resourcePath; // Construct signature hmac = Mac.getInstance("HmacSHA256"); secret = new SecretKeySpec(accessKey.getBytes(), "HmacSHA256"); hmac.init(secret); hmac_signed = Hex.encodeHexString(hmac.doFinal(requestVars.getBytes())); signature = hmac_signed.bytes.encodeBase64(); // HTTP PUT url = "https://" + account + ".logicmonitor.com" + "/santaba/rest" + resourcePath; httpPut = new HttpPut(url); httpPut.addHeader("Authorization" , "LMv1 " + accessId + ":" + signature + ":" + epoch); httpPut.setHeader("Accept", "application/json"); httpPut.setHeader("Content-type", "application/json"); httpPut.setEntity(params); responsePut = httpclient.execute(httpPut); responseBodyPut = EntityUtils.toString(responsePut.getEntity()); codePut = responsePut.getStatusLine().getStatusCode(); // Print Response println "Status:" + codePut; println "Response body:" + responseBodyPut; } httpclient.close();
  3. MrTK

    ServiceNow integration with slack

    This may not meet all your requirements, but another way to think about it. LM integrates with both SNOW and Slack, you could have your escalation chains simultaneously create a SNOW incident and post to the Slack channel for those Critical alerts.