5 Replies Latest reply on Oct 21, 2019 12:17 PM by Andrew Waters

    Text file comparison

    Vishnu Parihar
      Share This:

      Hi, I have written a TPL to extract the data from text(WIndows) or rxt(Unix) file, that is working fine. That text file contains the data like:

      AppName=BMC Discovery

      OwnerName=John Wick



      Filename : customdata.txt


      Now with the help of custom TPL we have extracted the data from Windows and Unix host, but the text file is free text file and any one can change the text file that will affect the CMDB data as well.


      Now I am planning to create different TPL to compare the old and new data and whatever difference/change is there, just trigger a mail to Discovery admin.


      Note: Filename will remain same. it will never change, only data will change inside the file.


      i.e after one month the server owner has changed from John to Edwin Loren, then server owner details will change from John to Edwin.

      Now I want Discovery should compare the data and send a mail to Discovery admin, if changes exist else exit.


      I also go through with below discussion, it is very useful but not in my case. Below article is comparing two different file but I want to compare same file during every scan..


      ADDM Experts - I want to use TPL to find a specific Unix host and diff two known files. If there is a difference then send an email warning that the file changed. If it does not find a difference then just exit gracefully out of the pattern. - Thank You

        • 1. Re: Text file comparison
          Brice-Emmanuel Loiseaux

          The only way to know the file content changed is to parse it, no? Why don't you enrich your initial pattern to email admin if you detect a change compared to what is currently stored on your Host.

          Alternatively, if a file checksum command is available on your target Host, you could run a file checksum, store it on the Host node and compare it next time you scan the Host before you parse the file.

          • 2. Re: Text file comparison
            Vishnu Parihar

            Thanks Brice for you suggestion.

            Below I attached the short code of custom data extraction from Windows, could you please help me to understand, how to compare ?


            tpl 1.15 module customdata;



            configuration ComplDiscCfg 3.0

            """Set Configuration options to control location of Compliance File Discovery"""

            "Common Windows File Locations"

            win_location := ["c:\\custom\\customdata.txt"];

            end configuration;



            pattern CustData 1.1




            on host := Host created, confirmed where os_class = "Windows";

            end triggers;





            for custdata in ComplDiscCfg.win_location do

            log.info ("Looking in directory %custdata%");

            instance_file := discovery.fileGet(host, custdata);


            if instance_file and instance_file.content then

            log.info ("Found the custdata file.");


            OwnerName := '';

            UsedByBusinessContact := '';


            det_type :=  "Windows Custom Data";


            OwnerName := text.strip(regex.extract(instance_file.content, regex 'OwnerName=(.*)', raw '\1'));



            if OwnerName <> "" then

            OwnerName := text.upper(OwnerName);

            log.debug ("OwnerName = %OwnerName%");


            OwnerName := "Unknown";


            log.debug ("OwnerName not found");

            end if;


            det_name := "%host.hostname%";

            det_key := "%det_name%/%host.key%";


            //ADD a new detail to the host node

            detail := model.Detail(

            key  := det_key,

            name := det_name,

            type := det_type,

            OwnerName := OwnerName,


            model.rel.Detail(ElementWithDetail := host, Detail := detail);

            model.setRemovalGroup(detail, det_type);

            end if;

            end for;

            end body;

            end pattern;

            • 3. Re: Text file comparison
              Andrew Waters

              Basically you would need to find the Detail from a previous scan and check if the values have changed.

              details := search(in host traverse ElementWithDetail:Detail:Detail:Detail where type = %det_type%);


              if details then

                old_detail = details[0];


                // Compare the fields, e.g.


                if old_detail.OwnerName <> OwnerName then


                end if;

              end if;

              1 of 1 people found this helpful
              • 4. Re: Text file comparison
                Bob Anderson

                add these attributes from instance_file to the Detail node.  Then compare them on every run:






                If any of these have changed since last discovery run, send email, then update the values in the Detail node


                From ViewTaxonomy:

                1 of 1 people found this helpful
                • 5. Re: Text file comparison
                  Andrew Waters

                  This is true if you are sure the only changes there are modify the value or values you are interested in.

                  1 of 1 people found this helpful