5 Replies Latest reply: Jul 13, 2012 12:55 PM by Steve Smith RSS

Examples of the Groovy scripts for Asset Tagging

Dan Wright

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

  • Examples of the Groovy scripts for Asset Tagging
    Aaron Clark

    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()

            }

        }

  • Re: Examples of the Groovy scripts for Asset Tagging
    Steve Smith

    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.

  • Examples of the Groovy scripts for Asset Tagging
    Steve Smith

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