1 2 Previous Next 19 Replies Latest reply on Dec 7, 2017 9:35 AM by Greg Sacrey Go to original post
      • 15. Re: Add new details to a host node based on a text file.
        Greg Sacrey

        The currently active pattern is as follows:

         

        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 := "Unix Cloud Images";

            categories := "Unix 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 ("AltusImageInfo_Unix: entry");

         

            location := "/etc/bb-imageinfo";

         

                log.info ("Looking into %host.name% for %location%");

           

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

           

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

         

            if not instance_file then

         

                log.error("No file at %location%");

         

            else

         

                if instance_file.content then

         

                  content := instance_file.content;

         

                log.debug("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');

                   

                 log.info("Found regex values BUILDOS = %build_os%, BUILDVERSION = %build_version%, BUILDDATE = %build_date%, BUILDID = %build_id%");

         

                // 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, ["build_os", "build_version", "build_date", "build_id"]);

         

                else

           

                    log.error("No file content in %location%");

         

                end if;

         

            end if;

           

            log.info ("End Body");

         

        end body;

         

        end pattern;

        • 16. Re: Add new details to a host node based on a text file.
          Andrew Waters

          Have you defined PRIV_TEST to use sudo and not set it up on the machine?

           

          You could turn on session logging for the credential used and see if there is anything useful in the log.

          1 of 1 people found this helpful
          • 17. Re: Add new details to a host node based on a text file.
            Greg Sacrey

            I have never done anything with PRIV_TEST

             

            I did look through the get FileContent Linux platform script (it is the default one, never been modified) and I can see a reference to the priv_test but it is basically asking me to run what you did with the test -f  If the result is 0 then continue looking at content of the file.

             

            I wouldn't have thought something special would need to be done to read a wide open file.

             

            I am at least seeing the pattern logs in tw_svc_eca_patterns  It shows an error saying no file at /etc/bb-imageinfo

             

            The session log shows only this regarding that file of /etc/bb-imageinfo

             

             

            __TIDEWAY_CMD_END__

            addmscan@app1:~$ tw_command() {

            > lsmod |grep vxfs

            > tw_report

            > }

            addmscan@app1:~$ (tideway_i=__TIDEWAY; echo ${tideway_i}_CMD_START__

            > tw_command

            > echo ${tideway_i}_CMD_END__)

            __TIDEWAY_CMD_START__

            __TIDEWAY_CMD_END__

            addmscan@app1:~$ tw_command() {

            > PRIV_TEST -f '/etc/bb-imageinfo' > /dev/null 2> /dev/null

            > if [ $? -eq 0 ]; then

            > echo "ls:" `PRIV_LS -ld '/etc/bb-imageinfo'`

            > echo "md5sum:" `md5sum '/etc/bb-imageinfo' 2>/dev/null | awk '{print $1;}'

            `

            > else

            > echo "FILE NOT FOUND"

            > fi

            >

            >

            > P='/etc/bb-imageinfo'

            > PRIV_TEST -f "${P}" -a -r "${P}"

            > if [ $? -eq 0 ]; then

            > echo "begin content:"

            > PRIV_CAT "${P}" | sed -e 's/[^[:print:][:blank:]]//g'

            > fi

             

            I have tried various users to run that test -f /etc/bb-imageinfo

             

            They all return a 0

            • 18. Re: Add new details to a host node based on a text file.
              Andrew Waters

              It must show something running the commands.

               

              It has to have done either echo FILE NOT FOUND or ls and md5sum. If it hasn't then something is very broken on the machine you are discovering or with your PRIV definitions. If it is because you have decided to cut stuff out then you either need to provide more complete information or raise a case.

              • 19. Re: Add new details to a host node based on a text file.
                Greg Sacrey

                Thanks for your time on this Andrew. I am going to test some other machines and check and double check permissions on the user account used for scanning.

                1 2 Previous Next