1 2 Previous Next 19 Replies Latest reply on Dec 7, 2017 9:35 AM by Greg Sacrey

    Add new details to a host node based on a text file.

    Greg Sacrey

      Hi folks,

       

      I am struggling a bit here and hoping for some guidance.  I am using Discovery 11.2.0.1

       

      We have a file we want to read.  It is at /etc/bb-imageinfo

      The contents of this file adhere to a format as follows:

       

      BUILDOS=centos

      BUILDVERSION=7-master

      BUILDDATE=2017_11_29

      BUILDID=b374

       

      I would like to be able to read the contents of that file and place new attributes to the host.

      Example

       

      Image Build OS = centos

      Image Build Version = 7-master

      Image Build Date = 2017_11_29

      Image Build ID = b374

       

      This would allow us to see what image as VM was spun up as.

       

      Something is not working here. I have double checked permission of the file and the file is present.  I am testing this on one machine.  Can any point out where I am going wrong?  I think I have to be close but something is not working for me.

       

      I was looking through the eca logs as well.  I didn't see anything in there.  I wonder if my logging setup in the pattern is working.  I also set reasoning logs to debug prior to the last scan as well.

       

      Any help would be appreciated.

       

       

       

      The content of my pattern is here:

       

      tpl 1.12 module AltusImage_Info_UNIX;

       

      pattern AltusImageInfo_Unix 1.0

       

      """

      This pattern reads a text file to do some additional discovery about the image for a Unix VM.

      """

       

      // More metadata attributes may be set as required

       

      metadata

          origin := "Custom TPL";

          products := "Cloud Images";

          categories := "Images";

      end metadata;

       

      // Overview section

       

      overview

          tags Unix;

      end overview;

       

      triggers

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

      end triggers;

       

       

      body

       

          log.info ("Start Body");

       

              log.info ("Looking into %host.name% for /etc/bb-imageinfo");

         

          instance_file := discovery.fileGet(host, '/etc/bb-imageinfo');

         

          log.info ("file: %instance_file%");

       

          if not instance_file then

       

              log.error("No file at /etc/bb-imageinfo");

       

          else

       

        if instance_file.content then

                content := instance_file.content;

      log.info("Found the file content %content%");

                                   

               // extract values from file

                  build_os := regex.extract(instance_file.content, regex 'BUILDOS=(.*)', raw '\1');

                  build_version := regex.extract(instance_file.content, regex 'BUILDVERSION=(.*)', raw '\1');

                  build_date := regex.extract(instance_file.content, regex 'BUILDDATE=(.*)', raw '\1');

                  build_id := regex.extract(instance_file.content, regex 'BUILDID=(.*)', raw '\1');

                 

              // write values from found file

                  host.BUILD_OS := "%build_os%";

                  host.BUILD_VERSION := "%build_version%";

                  host.BUILD_DATE := "%build_date%";

                  host.BUILD_ID := "%build_id%";

       

              // extend host attributes

                  model.addDisplayAttribute(host, "Image Build OS");

                  model.addDisplayAttribute(host, "Image Build Version");

                  model.addDisplayAttribute(host, "Image Build Date");

                  model.addDisplayAttribute(host, "Image Build ID");

                  

              else

         

                  log.error("No file content in /etc/bb-imageinfo");

       

              end if;

       

          end if;

         

          log.info ("End Body");

       

      end body;

       

      end pattern;

        1 2 Previous Next