Johnny Yuen

Tracking DataSources changes with ConfigSource

Recommended Posts

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) 

  1. 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 :-

  1.         api.access.id             :  < API Token Access Id >
  2.         api.access.key           :  < API Token Access Key >
  3.         api.account               :  <  LM Account >

  4. DeviceProperty.png.5939cb44363f88660095398c955adbc3.png

 

Adding ConfigSource Instances

  1. 1.     Identify the DataSource id. You can find it in the UI by looking at the URL of the DataSource definition

DS_ID.thumb.jpg.dfc4f57e04792dfc41c9e860684ea372.jpg

  1.  
  2. 2.     Add ConfigSource instances by selecting 'Add Monitored Instance' from the Manage Dropdown next to the manage button for the device
    1.         Name                        :  < DataSource Name >
              Wildcard value          :  < DataSource Id >
    2.         DataSource               :  DS_XML
  3. Add-Monitored-Instance-Menu.png.d3bf4071fe81c83b67e61731b3ccf615.png

Add-Monitored-Instance-Box.png.41a2bba8463d12a2537e950d9e847c79.png

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:

1.DS_XML_WinServer.thumb.jpg.4faec62ba0975b3acac6b08c6f2e12d3.jpg

2.WinServer.thumb.jpg.191197f1423f7c06a9608d2397dc3a35.jpg

3.DS_XML.thumb.jpg.c1d9ef1b6cabe2567b3cd95385a235f8.jpg

4_DS.thumb.jpg.e6f0a6ebc6a242dd94e0eb2d7fea02bb.jpg

5_DS.thumb.jpg.f9362e973def5bf33faacc08616de8c5.jpg

 

Edited by Johnny Yuen

Share this post


Link to post
Share on other sites
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.