Tracking DataSources changes with ConfigSource
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
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
-
Name : < DataSource Name >
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: