Johnny Yuen

LogicMonitor Staff
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Johnny Yuen

  • Rank
    Community Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hey Jeff, Cool. That's a good idea. Thanks for the info
  2. How do we monitor our DataSources? One of our customers asked an interesting and challenging question. He would like to know how he can track and alert changes to his customised DataSources. Well, there was no straightforward way, not until recently. This is made possible with the recent release of the ConfigSource add-on module and the publishing of the dataSource REST API. At a high-level, we can create a Groovy script ConfigSource which makes a REST API call to export a targeted DataSource to XML format, store and check for changes to the XML in ConfigSource, then send an alert when there is a change. Creating the ConfigSource:- 1. Create REST API token 2. Create an embedded groovy script ConfigSource with the following information:- Name : DS_XML Display Name : DS_XML Applies To : This ConfigSource can be applied to any device Collect Every : Up to your company policy, minimum 1 hour Multi-instance? : Check this option Enable Active Discovery : Uncheck this option Collector Attributes : Select Embedded Groovy Script Groovy Script : [... Attached Below ...] Config Check : Select Any Change (Check For: option) 3. Save the ConfigSource import org.apache.http.HttpEntity import org.apache.http.client.methods.CloseableHttpResponse import org.apache.http.client.methods.HttpGet 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; //define credentials and url def accessId =hostProps.get("api.access.id"); def accessKey = hostProps.get("api.access.key"); def account =hostProps.get("api.account"); def resourcePath ="/setting/datasources/##WILDVALUE##"; def url = "https://" + account + ".logicmonitor.com" + "/santaba/rest" + resourcePath + "?format=xml"; // 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()); code = response.getStatusLine().getStatusCode(); println responseBody httpclient.close(); 4. Go to the device where the ConfigSource is applied to, define the following device properties :- api.access.id : < API Token Access Id > api.access.key : < API Token Access Key > api.account : < LM Account > Adding ConfigSource Instances 1. Identify the DataSource id. You can find it in the UI by looking at the URL of the DataSource definition 2. Add ConfigSource instances by selecting 'Add Monitored Instance' from the Manage Dropdown next to the manage button for the device Name : < DataSource Name > Wildcard value : < DataSource Id > DataSource : DS_XML 3. Repeat above step 1 and 2 to add more datasource instances. Point to Note: 1. To execute a ConfigSource, you will need a minimum collector version of 22.110 2. One Datasource Id per instance 3. Differences in DataSource are viewed in XML format 4. Previous DataSource version can be restored by downloading and importing the previously compared XML from the ConfigSource history 5. Thanks and credits to David Lee (Our Jedi Master) for enhancing the original concept to a more user-friendly multi-instances ConfigSource. Screenshots of the ConfigSource result:
  3. We receive requests from customers every now and then asking whether we could display the number of devices/instances dynamically on a widget, either through a Big Number Widget or Custom Graph Widget. An ancestral practice involves creating a complex datapoint with a value of 1, and then aggregate the sum of this datapoint on the widget to retrieve the total number of devices/instances. This could be tedious as it involves changes made on the DataSource level. There’s good news, though - We have modernized and simplified this method after making a breakthrough on a recent ticket utilizing the following neat and simple method, and we’d like to share this idea with our users: On a high-level, the quintessence of this stratagem is as follows: 1) Identify a non-zero datapoint where you'd like to see it's devices/instance count 2) Configure an Aggregate SUM of this datapoint e.g. AggregateSUM 3) Configure an Aggregate AVERAGE of this datapoint e.g. AggregateAVG 4) Create a Virtual Datapoint with the following expression: AggregateSUM/AggregateAVG Note: Datapoint with NaN will not be counted as a device or instance in the process of aggregation. Example of device count configuration:- Example of instance count configuration:-