Groovy web console

subscribe to the feed Subscribe
to this
site
Veracode (via #groovywebconsole)
tweet this snippet Tweet
this
script

Veracode

Published 1 month ago by fozzin
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.text.SimpleDateFormat

def usr = "jenkins_toronto"
def pwd = "Intact20178"
def addr = "https://analysiscenter.veracode.com/api/3.0/getmaintenancescheduleinfo.do"
def authString = "${usr}:${pwd}".getBytes().encodeBase64().toString()

def conn = addr.toURL().openConnection()
conn.setRequestProperty( "Authorization", "Basic ${authString}" )
if ( conn.responseCode == 200 ) {
    def res = new XmlSlurper().parseText( conn.content.text )

    def maintenance_start_datetime = res.maintenancescheduleinfo.maintenanceschedule.downtime_start
    def maintenance_start_date = Date.parse("yyyy-MM-dd'T'hh:mm:ss", "${maintenance_start_datetime}").format("yyyyMMdd")
    def maintenance_start_time = Date.parse("yyyy-MM-dd'T'hh:mm:ss", "${maintenance_start_datetime}").format("hh:mm:ss")

    def maintenance_end_datetime = res.maintenancescheduleinfo.maintenanceschedule.downtime_end
    def maintenance_end_date = Date.parse("yyyy-MM-dd'T'hh:mm:ss", "${maintenance_end_datetime}").format("yyyyMMdd")
    def maintenance_end_time = Date.parse("yyyy-MM-dd'T'hh:mm:ss", "${maintenance_end_datetime}").format("hh:mm:ss")

    def currDate = new Date()
    def sdf_date = new SimpleDateFormat("yyyyMMdd")
    def sdf_time = new SimpleDateFormat("hh:mm:ss")

    if (sdf_date.format(currDate) >= maintenance_start_date && sdf_date.format(currDate) <= maintenance_end_date) {
        if (sdf_time.format(currDate) >= maintenance_start_time && sdf_time.format(currDate) <= maintenance_end_time) {
            printf "Got here"
        }
    }
} else {
    println "${conn.responseCode}: ${conn.responseMessage}"
}