Automic Workload Automation

Expand all | Collapse all

Get list of HostGroups via AE scripting

  • 1.  Get list of HostGroups via AE scripting

    Posted Dec 05, 2016 03:41 PM
    I am looking to implement a cron conversion tool using the Java API, but would like the initial execution of the Job to implement a READ that collects some general information such as the name of the Job they are creating, the cron command line, and what HostGroup they want the Job created against to be fed into the Java code.  Is there a way to gather the HostGroups on a given Client using AE scripting so I can present them as a drop-down selection list or will I have to get it another route?


  • 2.  Get list of HostGroups via AE scripting

    Posted Dec 05, 2016 04:01 PM
    Do you mean something like putting this SQL statement in a SQLI object?

    select * from oh where oh_otype like 'HOSTG' and oh_deleteflag = 0 and oh_client = 100


  • 3.  Get list of HostGroups via AE scripting

    Posted Dec 05, 2016 04:43 PM
    I appreciate the command, Pete.  I am far more versed in the Java-end of AE at this point and can easily get it from there if I need, but that and the SQLI would necessitate a separate Job, wouldn't they?  Our department doesn't really want to mess with SQL queries much mostly due to their own unfamiliarity with them.  The question is does the AE scripting language itself support a function to do this or is SQL or Java API required for this (what I think would be) basic information?


  • 4.  Get list of HostGroups via AE scripting

    Posted Dec 05, 2016 04:51 PM
    You could use a SQL Internal Secure type Variable object to place the results of this query in and then use a GET_VAR to build your drop-down.


  • 5.  Get list of HostGroups via AE scripting

    Posted Dec 05, 2016 05:00 PM
    Yeah, taking a look at that based on Pete's initial input.  I'm getting an error returned when I attempt to preview, but that's likely because I have absolute no idea how this should be configured at this point.  I'll play around with it and see. Any idea what "Binary fields are forbidden in memsv record ('OH_LASTRUNS')" indicates?


  • 6.  Get list of HostGroups via AE scripting

    Posted Dec 05, 2016 05:05 PM
    It indicates that some of the columns in the OH table are of a type that can not be easily displayed.  Try this one instead;

    select oh_name from oh where oh_otype like 'HOSTG' and oh_deleteflag = 0 and oh_client = 100


  • 7.  Get list of HostGroups via AE scripting

    Posted Dec 05, 2016 05:07 PM
    GET_VAR works fine for returning a single result.  But you might need to use PREP_PROCESS_VAR to be able to loop through each returned row.


  • 8.  Get list of HostGroups via AE scripting

    Posted Dec 05, 2016 05:11 PM
    Pete's correct regarding using the PREP_PROCESS_VAR for this and I'm not, hangs head in shame. . .   :(


  • 9.  Get list of HostGroups via AE scripting

    Posted Dec 05, 2016 05:15 PM
    Thanks a ton for the quick responses. I'll try that when I get back to the office and let you know. I still feel it's silly how you need specialized functions for general Client object information. Ah well, I've put off SQL this long I should probably start mixing that in. 


  • 10.  Get list of HostGroups via AE scripting

    Posted Dec 06, 2016 10:07 AM
    It indicates that some of the columns in the OH table are of a type that can not be easily displayed.  Try this one instead;

    select oh_name from oh where oh_otype like 'HOSTG' and oh_deleteflag = 0 and oh_client = 100
    This works great, thanks again!

    GET_VAR works fine for returning a single result.  But you might need to use PREP_PROCESS_VAR to be able to loop through each returned row.
    Where is PREP_PROCESS_VAR documented?  I can't seem to find it in either 12.0 or 11.2 guides (we're currently using 11.2, by the way), only PREP_PROCESS_VAR_XML.  Do you have a usage example?  I see the engine accepts PREP_PROCESS_VAR as a command, but without an example of use I'm not sure how to structure the command or handle the result.

    Update:
    Hilariously, Google returns better results for Automic documentation than the Automic search does.  Looks like PREP_PROCESS_VAR is available in 10.0 documention, but nothing newer.  No idea why, as it doesn't appear deprecated.  :|

    bgna3h1iobls.pnghttps://us.v-cdn.net/5019921/uploads/editor/tn/bgna3h1iobls.png" width="1600">

    https://docs.automic.com/documentation/webhelp/english/ALL/components/AE/10.0/All%20Guides/Content/ucaasc.htm



  • 11.  Get list of HostGroups via AE scripting

    Posted Dec 06, 2016 12:41 PM
    Alright, so the SQLI works fine and PREP_PROCESS_VAR works as well, but how do I feed the resulting values into the READ statement?  I created a variable and formatted the values into the text that READ requires, but it looks like as-is it's just reading the variable value and not reading it as literal text.

    Here's what I've got, which currently doesn't work, but the values are present in the &HGLIST# variable.
    :SET &HND#=PREP_PROCESS_VAR(TOOLS.VSQLI.TEST)

    :SET &HGLIST# = """"
    :PROCESS &HND#
    :   SET &HG# = GET_PROCESS_LINE(&HND#,1)
    :   SET &HGLIST# = STR_CAT(&HGLIST#, "'")
    :   SET &HGLIST# = STR_CAT(&HGLIST#, &HG#)
    :   SET &HGLIST# = STR_CAT(&HGLIST#, "',")
    :ENDPROCESS
    :CLOSE_PROCESS &HND#

    :SET &HGLENGTH# = STR_LENGTH(&HGLIST#)
    :SET &HGLENGTH2# = SUB(&HGLENGTH#,1)
    :SET &HGLIST# = STR_CUT(&HGLIST#,1,&HGLENGTH2#)
    :SET &HGLIST# = STR_CAT(&HGLIST#, """")

    User input
    :BEGINREAD "Please specify the HostGroup:"
    :  READ &HOSTGROUP#,&HGLIST#,'HOSTGROUP',,M
    :ENDREAD

    Thoughts?


  • 12.  Get list of HostGroups via AE scripting

    Posted Dec 06, 2016 01:14 PM
    I think you need quotes around a list selection -

    :  READ &HOSTGROUP#,"&HGLIST#",'HOSTGROUP',,M



  • 13.  Get list of HostGroups via AE scripting

    Posted Dec 06, 2016 01:28 PM
    I think you need quotes around a list selection -

    :  READ &HOSTGROUP#,"&HGLIST#",'HOSTGROUP',,M

    It is basically what you said, in that I was passing the quotations in the variable and apparently the quotations are needed to define the values as literal, so I stripped out the "s from the &HGLIST# and applied them to the READ statement and it works like the charm!
    :BEGINREAD "ENTER YOUR TEAM ACRONYM (EX: R99, EDD, ETC.):" :  READ &TEAM#,,'TEAM ACRONYM',,M :ENDREAD :SET &HND#=PREP_PROCESS_VAR(TOOLS.VSQLI.HOSTGROUPS) :PROCESS &HND# :   SET &HG# = GET_PROCESS_LINE(&HND#,1) :   SET &TEAMHG# = STR_FIND(&HG#,&TEAM#) :   IF &TEAMHG# <> 0 :     IF &HG# <> "&TEAM#.HG" :       SET &HGLIST# = STR_CAT(&HGLIST#, "'") :       SET &HGLIST# = STR_CAT(&HGLIST#, &HG#) :       SET &HGLIST# = STR_CAT(&HGLIST#, "',") :     ENDIF :   ENDIF :ENDPROCESS :CLOSE_PROCESS &HND# :SET &HGLENGTH# = STR_LENGTH(&HGLIST#) :SET &HGLENGTH2# = SUB(&HGLENGTH#,1) :SET &HGLIST# = STR_CUT(&HGLIST#,1,&HGLENGTH2#) :BEGINREAD "SELECT HOSTGROUP:" :  READ &HOSTGROUP#,"&HGLIST#",'HOSTGROUP',,M :ENDREAD
    Thanks for your help, all!


  • 14.  Get list of HostGroups via AE scripting
    Best Answer

    Posted Dec 06, 2016 01:29 PM
    I got this working for me;


    :SET &HND#=PREP_PROCESS_VAR(HOSTGROUP.TEST.QUERY)
    :PROCESS &HND#
    :   SET &HG# = GET_PROCESS_LINE(&HND#,1)
    :   SET &HGLIST# = STR_CAT(&HGLIST#, ",'&HG#'")
    :ENDPROCESS
    :CLOSE_PROCESS &HND#
    :SET &HGLIST# = mid(&HGLIST#,2)
    :print &HGLIST#
    :BEGINREAD "Please specify the HostGroup:"
    :  READ &HOSTGROUP#,"&HGLIST#",'HOSTGROUP',,M
    :ENDREAD

    .


  • 15.  Get list of HostGroups via AE scripting

    Posted Dec 06, 2016 01:32 PM
    Wow that formatting is so much nicer.  I'm nabbing that if that's okay. :)

    Thanks to you both, everything is working now!  Wish I could split the answer credit...