Forum Discussion

Johnny_Yuen's avatar
Johnny_Yuen
Former Employee
8 years ago

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) 

  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 >

 

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

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

 

  • Johnny_Yuen's avatar
    Johnny_Yuen
    Former Employee

    Hey Jeff,

    Cool. That's a good idea. Thanks for the info :)/emoticons/smile@2x.png 2x" title=":)" width="20">

  • I used this trick today to monitor future alert rule changes for a customer.  Works great and they love it!