Skip navigation
4472 Views 5 Replies Latest reply: Jul 13, 2012 12:55 PM by Steve Smith RSS
Dan Wright Level 1 21 posts since
Oct 12, 2010
Currently Being Moderated

May 7, 2012 9:04 AM

Examples of the Groovy scripts for Asset Tagging

Any one have any examples of the groovy scripts for setting up tags? I am looking to create asset tags for each OS.

  • Aaron Clark Level 1 19 posts since
    Mar 21, 2012
    Currently Being Moderated
    May 15, 2012 10:06 AM (in response to Dan Wright)
    Examples of the Groovy scripts for Asset Tagging

    Hi Dan,

     

    This isn't exactlty what you were asking for, but maybe it will help, it's a Groovy method to add tags to WAS web applications.

    /**

         * Add a single tag to a web application

         *

         * @param username Qualys user account username

         * @param password Qualys user account password

         * @param platformUrl The base URL for your respective Qualys platform

         * @param webAppID The numberic identifier for the web app you want to add the tag to

         * @param tagID The numeric identifier for the tag you want to add, you have to find this out separately

         * @return

         */

        public List addTag(String username,String password,String platformUrl,String webAppID,String tagID){

            def wasSite = new HTTPBuilder( platformUrl)

     

            //Need to explicitly set basic authentication header on each request as Groovy's basic auth implementation

            //is incompatible with the Qualys API impl

            wasSite.headers.'Authorization' = "Basic "+"$username:$password".getBytes('iso-8859-1').encodeBase64()

            println "auth header: "+wasSite.headers.'Authorization'

           

            //build the POST body

            String postBody = "<ServiceRequest>"

            postBody += "<data>"

            postBody += "<WebApp>"

            postBody += "<tags><set><Tag><id>"+tagID+"</id></Tag></set></tags>"

            postBody += "</WebApp>"

            postBody += "</data>"

            postBody +="</ServiceRequest>"

           

            wasSite.post( path: '/qps/rest/3.0/update/was/webapp/'+webAppID, body: postBody,requestContentType: 'text/xml', contentType : 'TEXT') {resp, reader->

                return reader.readLines()

            }

        }

  • Steve Smith Level 2 89 posts since
    May 31, 2011
    Currently Being Moderated
    Jun 25, 2012 10:04 AM (in response to Dan Wright)
    Re: Examples of the Groovy scripts for Asset Tagging

    Hi Dan,

     

    Did you figure this one out? There are actually a bunch of Operating System tags already built into the module.  Navigate to the asset module -> tags. Scroll down to Operating System and expand the list.

     

    If you don't see one that is specific to your needs (ie, it isn't an OS we detect), you can always create a static tag and apply it manually.

  • Steve Smith Level 2 89 posts since
    May 31, 2011
    Currently Being Moderated
    Jul 13, 2012 12:55 PM (in response to Dan Wright)
    Examples of the Groovy scripts for Asset Tagging

    Dan,

     

    You probably already figured this out, but the other thing you can do is create a dynamic tag based on the rule "operating system regular expression". Examples:

     

    windows

    windows 2003

    windows 2003 R2

    windows 2003 service pack

    windows 2003 R2 service pack 2

     

    I'd recommend using the checkbox "ignore case".

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 6 points