6 Replies Latest reply on Mar 11, 2016 9:11 AM by Joe Haley

    Unmanaged Server Discovery Zipkit

    Joe Haley

      Has anyone successfully implemented this zipkit?

      Blade ZipKit - Unmanaged Server Discovery (Using AO, ADDM and BSA)


      I have gone through the manual installation instructions and ran the job in BSA.  However, we are not receiving any servers back from ADDM.  I am not getting any errors either, just the info below in the logs.


      I also ran the "Get Discovered Servers in ADDM" process separately in BAO and did not get any errors.  It looks like results are being returned from ADDM but I think the xml may need to be changed.


      BSA Job Results

      Info    05/12/2015 09:06:28    AO Process ':ADDM_BSA_Integration:Enroll Servers In BSA' Status is: 'ASSIGNED'

      Info    05/12/2015 09:07:15    Workflow Job completed, AO Process Status is: 'COMPLETED'

      Info    05/12/2015 09:07:15    <ns1:XmlDoc><addm-discovered-servers /></ns1:XmlDoc>



      BAO Job Results


      kind="Host"&gt;&lt;row&gt; &lt;string&gt;dwauslhmc1&lt;/string&gt;
        • 1. Re: Unmanaged Server Discovery Zipkit
          Akbar Aziz

          Hi Joe Haley. I am testing this kit out in my environment and will get back to you with the results.

          • 2. Re: Unmanaged Server Discovery Zipkit
            Joe Haley

            Thank you very much!

            • 3. Re: Unmanaged Server Discovery Zipkit
              Joe Haley

              I was able to get this to work a different way. Our ADDM team extracts servers to a SQL Server database so I was able to create a Jython script that runs daily in BladeLogic against a Smart Group where the agent is non-responding. If the server is not in ADDM, then a BLCLI command is ran to decom it from BladeLogic. If it was found in ADDM, then the list of servers if emailed to the appropriate team, e.g. Windows Admins to investigate and fix the rscd agents. Let me know if anyone would be interested in the script and I can attach it. Thanks

              • 4. Re: Unmanaged Server Discovery Zipkit
                Akbar Aziz

                Hi Joe,


                Please create this as a new ZipKit if you don't mind. You can follow the template that is defined here for the kit:


                How to submit community created Blade ZipKits

                • 5. Re: Unmanaged Server Discovery Zipkit
                  Raja Mohan

                  Joe Haley please share if you don't have issue

                  • 6. Re: Unmanaged Server Discovery Zipkit
                    Joe Haley

                    Hi Raja,


                    Below is the jython script I used in a NSH script to compare non-responding servers in BSA with servers from a SQL database that contains all the servers from ADDM. You will have to substitute all the values in <> with your own. The script writes the results to a file and emails as an attachment. It also updates the description server property. You will have to install jython on a server and generate a key file for authentication.






                    # Get the key file that was created so can authenticate on the fly. SRP

                    blcred cred -acquire -profile "<profile>" -i <.dat file location>


                    exec bljython - "$@"  <<__EndOfJython__



                    # Jython code goes here


                    import csv

                    import re

                    import sys

                    import os

                    import string as s

                    import socket

                    import smtplib

                    from email.mime.multipart import MIMEMultipart

                    from email.mime.text import MIMEText

                    import mimetypes

                    from email.mime.base import MIMEBase

                    import bladelogic.cli.CLI as blcli

                    from com.ziclix.python.sql import zxJDBC


                    # **************************************************************************

                    # Get the ADDM servers from a SQL table and write the results to a csv file

                    # **************************************************************************


                    # Open a csv file for writing the results of the ADDM servers

                    # Write without quotes since it was causing issues when trying to read the file

                    writer = csv.writer(open("<location to write csv file of addm servers, addm_servers.csv>", "wb"), lineterminator='\n', quoting=csv.QUOTE_NONE)


                    # Set credentials for logging into ADDM DB

                    # ToDo: See if can have this value passed in as param or make a property

                    userName = "<user-name for sql db>";

                    password = "<password for sql db>";


                    # Connect to the ADDM database and execute the query to retrieve the server names

                    strDataSource, strDBUser, strDBPassword, strDBVersion = "jdbc:sqlserver://<SQL Server Name>;databaseName=<database name>", userName, password, "com.microsoft.sqlserver.jdbc.SQLServerDriver"

                    objConnection = zxJDBC.connect(strDataSource, strDBUser, strDBPassword, strDBVersion)

                    objCursor = objConnection.cursor()

                    objCursor.execute('''SELECT DISTINCT <server name>, <os type> FROM <db table> GROUP BY <server name>, <os type> ORDER BY <server name> ASC''')


                    # Write all rows of the cursor to the file

                    rows = objCursor.fetchall()



                    # Close the db connections






                    # ********************************************************************

                    # Get the BladeLogic servers to check against ADDM from a Smart Group

                    # ********************************************************************

                    jli = blcli.CLI()





                    # Function that gets called to execute a blcli command

                    def execute(command):

                        #print command

                        # Main CLI command execution.

                        propertyObject = jli.run(cmd)


                        # If command executed successfully, return the result received after command execution.


                              propertyKey = propertyObject.returnValue

                        return str(propertyKey)


                    # Function to split the server names into a new line

                    def split(result):

                        # Using regular expression to split the result on new line

                        arr = re.split('\n',result)

                        counter = 0


                        # looping the array elements to remove newline.

                        for element in arr:

                              # Strips newlines from right end of the string.



                        return arr


                    # Declaring the command array to hold commands to be executed

                    cmd =[]

                    # Appending namespace


                    # Appending command


                    # Appending SmartGroup

                    cmd.append('<smart group location in BSA of servers where the agent status is non responding>')


                    # Result is returned as an array.

                    servers = split(execute(cmd))

                    #print servers



                    # Check the count of servers not responding, if over 20 then investigate to make sure that is correct before removing from bsa

                    print "Non-Responding BSA Server Count: " + str(len(servers));

                    # If the count on non-responding servers is over 25 then exit the script. There may have been a network issue

                    if(len(servers) > 25):

                      sys.exit("Non-Responding server count in BSA was greater than 20. Please Investigate to see if there were network issue overnight! No servers were auto decommed")



                    # ***********************************************************************

                    # Open the master ADDM file and create a new csv the results will be written to

                    # ***********************************************************************

                    f1 = file('<add csv file that was created above, addm_servers.csv>', 'r')

                    c1 = csv.reader(f1, delimiter=',', quoting=csv.QUOTE_NONE)

                    f3 = file('/var/tmp/stage/jython_scripts/results.csv', 'w')

                    masterlist = list(c1)

                    c3 = csv.writer(open("<results of comparing servers file, results.csv>", "w"), delimiter=',', lineterminator='\n', quotechar="'", quoting=csv.QUOTE_MINIMAL)



                    # Function to check if the hostname is an ip address

                    def validate_ip(s):

                        a = s.split('.')

                        if len(a) != 4:

                            return False

                        for x in a:

                            if not x.isdigit():

                                return False

                            i = int(x)

                            if i < 0 or i > 255:

                                return False

                        return True



                    # *********************************************************************************

                    # Loop thru BladeLogic servers from Smart Group and then loop thru master ADDM server list to see if the BladeLogic server is found

                    # ********************************************************************************

                    # Set a list so can email the results

                    results_list = ""



                    # Iterating over the list of servers

                    for server in sorted(servers):

                                if(server != ''):


                                  # Get the BSA server name

                                  bsa_server_name = server


                                  # Remove the fqdn from the BSA server, only compare host name

                                  #print server

                                  # First verify if the hostname is an ip address

                                  if not validate_ip(server):

                                      server = server.split('.')

                                      server = server[0]


                                  row = 1

                                  found = False


                                  # Check if server in ADDM list

                                  for master_row in masterlist:

                                      # Set initial results to bsa server name

                                      results_row = server + " | "


                                      # Check so its case insensitive

                                      if (server.lower() in master_row[0].lower()):


                                          results_row+=master_row[1] + ' | ' + bsa_server_name  + ' | ' + str('FOUND in ADDM server list (row ' + str(row) + ')')

                                          print server + ": found"


                                          # Can set a property on the server in BSA for filtering

                                          jli.run(['Server','setPropertyValueByName', bsa_server_name,'DESCRIPTION','In_ADDM_Please_INVESTIGATE'])


                                          found = True


                                      row = row + 1


                                  if not found:

                                      #print server + ": not found"

                                      results_row+=bsa_server_name + ' | ' + str('NOT FOUND in ADDM list - Removed from BladeLogic')



                                      # Update the description property so we know the server is inactive

                                      jli.run(['Server','setPropertyValueByName', bsa_server_name,'DESCRIPTION','Not_In_ADDM_DECOM'])


                                      # *********************************************************************

                                      # Auto-Decom the server if not found in ADDM - commented out for now

                                      # *********************************************************************

                                      #print bsa_server_name + 'Server Not In ADDM - Decom?'

                                      # Can auto-decom the server if not found in ADDM

                                      #jli.run(['Server','decommissionServer', bsa_server_name])                



                                  # Write the results to the csv file



                                  # Append to the list so can display in email

                                  results_list+=str(results_row + "\n")


                    # Close the files






                    # **************************************************************

                    # Email the results to the appropriate team          

                    # Get all servers left in the smart group BSA_Not_Responding

                    # **************************************************************

                    toEmail = ['<from email>']

                    fromEmail = '<from email>'


                    msg = MIMEMultipart()

                    msg['To'] = ", ".join(toEmail)

                    msg['Subject'] = 'Non-Responding Active BSA Servers'

                    msg['From'] = '<from email>'


                    msg.attach(MIMEText('See attached list of non-responding BladeLogic Servers that show as active in ADDM.' + "\n\n", 'plain'))

                    msg.attach(MIMEText(results_list, 'plain'))


                    # Send the email


                      smtpObj = smtplib.SMTP('localhost')

                      smtpObj.sendmail(fromEmail, toEmail, msg.as_string())      

                      print "Successfully sent email"

                      print results_list

                    except SMTPException:

                      print "Error: unable to send email"


                    # Exit successfully