4 Replies Latest reply on Dec 24, 2010 9:18 AM by Bill Robinson

    Grouping servers by Application

    Jim Campbell

      Is there a way to create smart groups and/or report dynamically on a list of servers based on applications installed on them without having to set a static property of the server object?

       

      What we'd like to be able to do is to use either an extended object or e.g. a registry key to determine the presence of an application on a server and then install updates based on whether or not the application is present.  Preferably I'd like to be able to both use this as a part of the criteria for a smart group and report on it with BSARA, but even if we could only report on it we could export the lists of servers.

        • 1. Re: Grouping servers by Application
          Joshua Skirde

          Hi Jim,

           

          If you want to create dynamic targets based upon the existence of some criteria, you can create a component template (make sure you tick discover and deploy in this case). You can then run a discovery job to identify which hosts meet your discovery criteria and the system will automatically create components for each host where the application was discovered.

          You can then create Component smart groups if you want to group these together and you can make these the target of your "update" jobs.

           

          I hope this helps!

          Kind regards,

          Joshua

          1 of 1 people found this helpful
          • 2. Re: Grouping servers by Application
            Jim Campbell

            Thank you, thats what I was looking for in terms of targetting jobs.  I was unaware I could target a component and affect the server as a whole.  For reporting, will I be able to pull out e.g. a list of servers on which the application is installed (as determined by the criteria of the component template) in BSARA (or even some sort of copy/paste from the console)?

            • 3. Re: Grouping servers by Application
              Joshua Skirde

              Hi again Jim,

               

              You should be able to report on the components (Component.Target.Name should give you the hostname).

              Otherwise you can dump on all the component names using blcli.

              Something like this:

              export BL_AUTH_PROFILE_NAME=defaultProfile
              TEMPLATE_GROUP="/Workspace"
              TEMPLATE_NAME="Discover VMWare Tools"
              TEMPLATE_DBKEY=`blcli Template getDBKeyByGroupAndName "$TEMPLATE_GROUP" "$TEMPLATE_NAME"`
              COMPONENTS=`blcli Component getAllComponentKeysByTemplateKey "$TEMPLATE_DBKEY"`
              for COMPONENT_KEY in ${COMPONENTS}
              do
                blcli Component getFullyResolvedPropertyValue $COMPONENT_KEY "NAME"
                echo ""
              done

               

              Although if you have a lot of hosts then you should probably re-write using the performance commands (listed in the BLCLI help).

               

              Kind regards,

              Joshua

              • 4. Grouping servers by Application
                Bill Robinson

                The script below will look for component existence and add the servers to a static group.  you could probably adopt this to set a property

                 

                #!/bin/nsh
                # vim: syntax=sh

                BLCLIOUT="/tmp/$$.out.blcli"
                BLCLIERR="/tmp/$$.err.blcli"

                ### Functions
                initTmpFile()
                {
                        ! [ -d /tmp ] && mkdir /tmp
                        date > ${BLCLIOUT}
                        date > ${BLCLIERR}
                }

                removeTmpFile()
                {
                        rm -f ${BLCLIOUT}
                        rm -f ${BLCLIERR}
                }

                setNull()
                {
                        if [ `uname -s` = "WindowsNT" ]
                                then
                                NULL=NUL
                        else
                                NULL=/dev/null
                        fi
                }

                print_info()
                {
                        echo "INFO: $@"
                }

                print_error()
                {
                        echo "ERROR: $@"
                        exit 1
                }

                print_warn()

                {
                        echo "WARN: $@"
                }
                print_result()
                {
                        echo "  RESULT: $@"
                }

                print_debug()
                {
                        [ "${DEBUG}" = "true" ] && echo "DEBUG: $@"
                }

                openBLConnection()
                {
                        blcli_disconnect
                        local role="${1}"
                        if [ -n "${role}" ]; then
                          print_info "Opening connection to BladeLogic as ${role}"
                          blcli_setoption roleName "${role}"
                        else
                          print_info "Opening connection to BladeLogic"
                        fi
                        blcli_connect && RESULT="ok"
                }

                closeBLConnection()
                {
                        print_info "Closing connection to BladeLogic"
                        blcli_destroy && RESULT="ok"
                }


                exec_blcli()
                {
                        print_debug "blcli_execute ${BLCLICMD[@]}"
                        blcli_execute "${BLCLICMD[@]}"  > ${BLCLIOUT} 2> ${BLCLIERR}
                        blcli_storeenv RESULT 2>${NULL}

                        if [ $? -ne 0 ]
                                then
                                RESULT=`cat ${BLCLIERR} | cut -f2- -d:`
                                print_error "${RESULT}"
                        fi

                }

                TEMPLATE_GROUP="${1}"
                SERVER_GROUP_ROOT="${2}"
                DEBUG="true"

                setNull
                initTmpFile

                blcli_setjvmoption -Xmx1536M
                blcli_setoption authType SRP
                openBLConnection

                # Get the GroupId of the Template Group
                BLCLICMD=(Template getTemplateKeysByGroupName "${TEMPLATE_GROUP}")
                exec_blcli
                TEMPLATE_LIST="${RESULT}"
                print_debug "TemplateKeys: ${TEMPLATE_LIST}"

                for TEMPLATE in ${TEMPLATE_LIST}
                        do
                        print_debug "Key: ${TEMPLATE}"

                        # Find or create the server group
                        BLCLICMD=(Template getNameByDBKey "${TEMPLATE}")
                        exec_blcli
                        print_debug "TemplateName: ${RESULT}"
                        SERVER_GROUP_NAME="${RESULT}"
                        SERVER_GROUP="${SERVER_GROUP_ROOT}/${SERVER_GROUP_NAME}"

                        BLCLICMD=(StaticServerGroup groupExists "${SERVER_GROUP}")
                        exec_blcli
                        if [ "${RESULT}" = "false" ]
                                then
                                BLCLICMD=(ServerGroup groupNameToId "${SERVER_GROUP_ROOT}")
                                exec_blcli
                                GROUP_ID="${RESULT}"
                                BLCLICMD=(StaticServerGroup createServerGroup "${SERVER_GROUP_NAME}" ${GROUP_ID})
                                exec_blcli
                        fi

                        # Get the ServerGroup Id
                        BLCLICMD=(ServerGroup groupNameToId "${SERVER_GROUP}")
                        exec_blcli

                        SERVER_GROUP_ID="${RESULT}"
                        print_debug "ServerGroupId: ${RESULT}"

                        # Get the list of servers in the group
                        BLCLICMD=(Server listServersInGroup "${SERVER_GROUP}")
                        exec_blcli
                        SERVERS_FROM_GROUP="${RESULT}"

                        # Get the Server Ids associated w/ the template
                        BLCLICMD=(Template getServerIdsByTemplateKey "${TEMPLATE}")
                        exec_blcli
                        SERVER_IDS="`echo ${RESULT} | sort -u`"
                        print_debug "Server Ids: ${SERVER_IDS}"

                        # Get the server names
                        SERVERS_FROM_TEMPLATE=""
                        for SERVER_ID in ${SERVER_IDS}
                                do
                                BLCLICMD=(Server getServerNameById ${SERVER_ID})
                                exec_blcli
                                SERVER_NAME="${RESULT}"
                                SERVERS_FROM_TEMPLATE="${SERVER_NAME} ${SERVERS_FROM_TEMPLATE}"
                        done


                        # Figure out what needs to be added
                        for SERVER_T in ${SERVERS_FROM_TEMPLATE}
                                do
                                print_debug "Checking to Add ServerName: ${SERVER_T}"
                                # If the server is already in the group, we don't need to add it
                                addServer="true"
                                for SERVER_G in ${SERVERS_FROM_GROUP}
                                        do
                                        if [ "${SERVER_G}" = "${SERVER_T}" ]
                                                then
                                                addServer="false"
                                        fi
                                done
                                if [ "${addServer}" = "true" ]
                                        then
                                        # Add the server, it's not in the group
                                        BLCLICMD=(StaticServerGroup addServerToServerGroupByName ${SERVER_GROUP_ID} "${SERVER_T}")
                                        exec_blcli
                                        print_result "${RESULT}"

                                fi
                        done
                        # If the server isn't in the list, I need to remove it
                        for SERVER_G in ${SERVERS_FROM_GROUP}
                                do
                                print_debug "Checking to Remove ServerName: ${SERVER_G}"
                                removeServer="true"
                                for SERVER_T in ${SERVERS_FROM_TEMPLATE}
                                        do
                                        if [ "${SERVER_G}" = "${SERVER_T}" ]
                                                then
                                                removeServer="false"
                                        fi
                                done
                                if [ "${removeServer}" = "true" ]
                                        then
                                        # Remove the server from the group
                                        BLCLICMD=(ServerGroup removeServerFromServerGroupByName "${SERVER_GROUP}" "${SERVER_G}")
                                        exec_blcli
                                fi
                        done

                 


                done

                closeBLConnection
                removeTmpFile