11.07.2015 Views

DDM 8.0 Advanced Student Guide

DDM 8.0 Advanced Student Guide

DDM 8.0 Advanced Student Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

HP Software & SolutionsGlobal Enablement2009HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.<strong>DDM</strong> <strong>8.0</strong> <strong>Advanced</strong> <strong>Student</strong> <strong>Guide</strong>Global EnablementHP1/1/2009


HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.00 DeLab Environment Setup 3Part 1: Initial Discovery Exercise 4Part 2: Regular Expression Exercises 20Exercise 1. Version of OS 20Use Regular expression to parse out the major, minor and, update versions for theOS. 20Exercise 2. Parse out the DHCP lease settings 21Exercise 3. Parse out the Processor settings 22Part 3: Jython Exercises 23Exercise 1. Jython program to read system information 23Part 4: Pattern Development 25Exercise 1. Using the Discovery Analyzer 25Exercise 2. Modify WMI Connection Pattern to get additional attributes 30Exercise 3. Pattern to read customers from a Spreadsheet. 41Exercise 4. Pattern to read product orders create order CIs and link them tocustomers. 43Part 5: Answers to Exercises 46Part 1 Answers 46Part 2 Answers 46Part 3 Answers 47HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 2


LAB ENVIRONMENT SETUPHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.1. Use remote desktop to login to the FC Access VM, the instructor will give youthe following information:<strong>Student</strong> Access VM NameAccess VM IP Address:Access VM User:Access VM Password:________________________________________________________________________________________________________________________________________________Access VM Domain:OVSC2. Use remote desktop to login to your UCMDB VM (192.168.254.10).UCMDB VM User:_________________________________HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 3


UCMDB VM Password:_________________________________PART 1: INITIAL DISCOVERY EXERCISEHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.In this exercise you will use <strong>DDM</strong> to discover some Hosts (Access VM and UCMDB VM)along with their host resources and SQL Server on your local network. This is to refresh yourmemory about running discovery and examination of the log files that the probe and gatewayuse.We will clear UCMDB by creating new schemas so that all the discovered CIs are new andeasy to distinguish.1. Login to the UCMDB VM (192.168.254.10)2. Shutdown the UCMDB server (Icon on the desktop)3. Start the UCMDB Configuration Wizard4.Click Next.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 4


HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 5


5.Create a new user schema for the Foundation, click next.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 6


6.Select Microsoft SQL Server, click next.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 7


7.Enter the schema name FoundDB_<strong>DDM</strong>A , click next.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 8


8.Click Next after you see the completed successfullymessage.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 9


9.Create a new user schema for the CMDB, click next.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 10


10. Select Microsoft SQL Server, click next.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 11


11. Enter the CMDB schema CMDB_<strong>DDM</strong>A , click next.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 12


12. Click Next after you see the completed successfullymessage.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 13


13. Create a new user schema for the CMDB History, clicknext.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 14


14. Select Microsoft SQL Server, click next.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 15


15. Enter the CMDB schema CMDB_HIST_<strong>DDM</strong>A , click next.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 16


16. Click Finish after you see the completedsuccessfully message.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.17. Restart UCMDB Server using Icon on desktop18. After the server is up, login to UCMDB using admin /admin.19. On your desktop , start your <strong>DDM</strong> probe by doubleclicking the <strong>DDM</strong> Probe icon.What information does the Server send to the probe onstart?List 2 things:What does the probe send to the Server? (Hint: Go look inCIT type Manager)HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 17


20. In UCMDB go to the Discovery Setup DiscoveryProbes. Click on the refresh and verify that your probeconnects.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.21. Enter a range for discovery of 192.168.254.* , ClickOK twice.22. Enter the following credentials for your discovery:WMI – (Use the credentials that you were given for your access VM and the UCMDB VM-Page 3)SQL – Microsoft SQL Server sa / HPS0ftware!HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 18


HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.23. Go to Run Discovery <strong>Advanced</strong> Mode. Run the followingdiscoveries:1. Ping Sweep of the IP Range2. WMI Connection3. Host Resources and Applications (Turn on alldiscovery options)4. Database TCP Ports5. MS SQL Connection6. MS SQL Topology24. Use the log file(s) to determine the followinginformation:What is the name of the database in the Select state run by the probe to get the jobs?What is total of CIs discovered by the MS SQL Topology discovery?HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 19


PART 2: REGULAR EXPRESSION EXERCISESExercise 1. Version of OSHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.Use Regular expression to parse out the major, minor and, update versionsfor the OS.1. Open a DOS command window in your VM.2. At the prompt type in the “ver” command .3. Copy the result from the ver command in the DOS window to Kodos tool (MiddleWindow).HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 20


HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.4. Build a regular expression in the top window to pick out the major, minor, and updateversion numbers.( Build it in the top window) Use Kodos to help you debug yourregular expression. (Result will be in the bottom window). You will need to useRegular expression grouping for the number you want to pick out.5. Write down the regular expression that you use to do this below.Exercise 2. Parse out the DHCP lease settings1. Open a DOS command window in your VM.2. At the prompt type “ipconfig /all” command3. Create a regular expression to pick out the DHCP lease obtained and lease expiresstrings. Use Kodos to help you debug your regular expression.Write down the regular expression that you use to do this below.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 21


Exercise 3. Parse out the Processor settings1. Open a DOS command window in your VM.2. At the prompt type “systeminfo” –3. Create a regular expression to pick out the number of processors and the processoridentifier strings. Use Kodos to help you debug your regular expression.Write down the regular expression that you use to do this below.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 22


PART 3: JYTHON EXERCISESHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.In these exercises you will become familiar with the jython programming language. We willwrite a program using the jython shell first before we start programming for the probe. Usethe resources available to you: Google, the course material, www.jython.org,www.python.org website for more information.Exercise 1. Jython program to read system information1. Open the jython shell by double clicking the jython.bat on the desktop.2. Write a jython program using an editor – the program should:a. Run the os command systeminfob. Output the contents to a filec. Read the filed. Parse the contents looking for patches that have updates. A patch with anupdate is designated by the word Update next to the patch.e. Use regular expressions in your program to do your parsing. Count theamount of patches with updates and print the result. Test your program byusing the jython command shell and observing the result. There is a sampleprogram below that may help you to get started.To invoke jython command interpreter (installed at c:\jython):Jython shell is invoked using the "jython" .bat script, a short script that invokes your localJVM, sets the Java property install.path to an appropriate value, and then runs the Javaclassfile org.python.util.jython.jython [options] [-jar jar | -c cmd | file | -] [args]HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 23


options-i: Inspect interactively after running script; force prompts even if stdin is not aterminal. -S: Do not imply import site on initialization -Dprop=[value]: Set thejython property prop to value.-jar jarthe program to run is read from the __run__.py file in the specified jar fileHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.-ccmdargs--help--versionprogram to run is passed in as the cmd string. This option terminates the optionslist file run file as the program script fileprogram is read from standard-in (default; interactive mode is used if on a tty). Thisflag allows you to pipe a file into Jython and have it be treated correctly. Forexample:filter file | jython -arguments passed to the program in sys.argv[1:]print a usage message and exitprint Jython version number and exitSample jython program that uses regular expressionsimport rename = "barry feigenbaum "print name# do a fancy string matchif re.search("^\s*barry\s+feigenbaum\s*$", name): print "It's Barry alright"# replace the first name with an initialname2 = re.sub(r"(B|b)arry", "B.", name)print name2HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 24


PART 4: PATTERN DEVELOPMENTExercise 1. Using the Discovery AnalyzerHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.In this exercise you will use the Discovery Analyzer to kick off a job and see the parameterspassed into the pattern and see the results that will be passed back to the server.1. Login to the VM were the UCMDB server is running. If the <strong>DDM</strong> probe is runningyou can shut it down by using CTRL-C when the <strong>DDM</strong> Probe window has focus- Itwill indicate the CTRL-C Trapped Shutting Down. Wait till the probe indicatesWRAPPER STOPPED. At that point you can close the <strong>DDM</strong>P Probe Window.2. In this exercise we will run the DA in standalone mode so we need to verify that theproperties file is configured to allow the DA to run in that mode. Go toc:\hp\<strong>DDM</strong>\DiscoveryProbe\root\lib\collectors directory. Open theDiscoveryProbe.properties file. Find the lineAppilog.agent.local.discoveryanalyzerFromEcplise = falseMake sure the value is false. If the value is not false , change it and save the file.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 25


HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.Make sure the value isfalse3. Start the Discovery Analyzer by running the command fileHP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 26


c:\hp\<strong>DDM</strong>\DiscoveryProbe\root\lib\collectors\DiscoveryAnalyzer.cmdHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.4. Click on the new task icon to start the task editor. Select the job Host Connection byWMI. Fill in the ip_domain “DefaultDomain”. Right click in the hosted field andselect Generate Random CMDB ID. In the ip_address field put in the ip of your localhost. For the id field right click and select Generate Random CMDB ID. Select Ok toclose the Task Editor.5.Run the job by selecting the circle icon. The job willrun and you will see output in the General Log window.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 27


HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.6.Examine the communication and the result log. Thecommunication log is the parameters passed into the taskand any communication such as messages such as messages.The result log shows the OSH vector and the OSHs.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 28


HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 29


HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.7.Choose other patterns to run and look at the results.Exercise 2. Modify WMI Connection Pattern to get additionalattributes<strong>DDM</strong> does not discover the time zone that hosts are in. In this exercise you will modify theWindows CIT to add two new attributes; one for Standard time and another for DaylightSavings Time. We will do this for just Windows machines in this lab.Use the reference below to the W32_Timezone class. Retrieve the fields StandardName ,DaylightName and Caption into three new attributes . You will modify theWMI_NET_Dis_Connection pattern and in particular the WMI_Connection_Utils.py toSelect the fields from the host and populate the new attributes using OSHs. Use theWMIExplorer tool to get familiar with querying WMI. You can use it to show you the dataand help you to build Select statements for WMI. After you know the fields and how to querythe data, modify the WMI_Connection_Utils.py script to retrieve and populate the host classwith new attributes.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 30


1. Use WMIExplorer to understand the query of W32_Timezone and the fieldsStandardName , DaylightName, and Caption. Look at the data to understand whatwill be returned.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.2. Add three new attributes to CIT Host for your new fields. Use best practice namingconventions for you new attribute names.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 31


3.Edit the WMI_Connection_Utils.py script.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.4.Determine the best place in the code to place yourmodifications, make sure it will get executed when yourun. Use the logger (Best Practice) to print out debugstatements.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 32


HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.5.Query the W32_Timezone class for the fields and save theresult in a variable.6.Parse the result and build an OSH for your Host with theattributes.7. Build an OSH for the Host with your attributes. Make sureyou add your OSH to the Vector.8. Save the code , make sure that the script has downloadedto the probe before you activate it (Look at the <strong>DDM</strong>Probe Window)9. Activate it and debug it till you get the results showingup in your attributes.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 33


References :MicrosoftWMI Win32 TimeZone http://msdn2.microsoft.com/en-us/library/aa394498(VS.85).aspxWin32_TimeZone ClassHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.The Win32_TimeZone WMI class represents the time zone information for a computer system runningWindows, which includes the changes required for transitioning to daylight saving time transition.The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inheritedproperties. Properties and methods are in alphabetic order, not MOF order.Syntaxclass Win32_TimeZone : CIM_Setting{sint32 Bias;string Caption;sint32 DaylightBias;uint32 DaylightDay;uint8 DaylightDayOfWeek;uint32 DaylightHour;uint32 DaylightMillisecond;uint32 DaylightMinute;uint32 DaylightMonth;string DaylightName;uint32 DaylightSecond;uint32 DaylightYear;string Description;string SettingID;uint32 StandardBias;uint32 StandardDay;uint8 StandardDayOfWeek;uint32 StandardHour;uint32 StandardMillisecond;uint32 StandardMinute;uint32 StandardMonth;string StandardName;uint32 StandardSecond;uint32 StandardYear;};MethodsThe Win32_TimeZone class does not define any methods.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 34


PropertiesThe Win32_TimeZone class defines the following properties.BiasData type: sint32Access type: Read-onlyQualifiers: Units(Minutes)HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.Current bias for local time translation. The bias is the difference between Coordinated Universal Time(UTC) and local time. All translations between UTC and local time are based on the following formula:UTC = local time - bias. This property is required.CaptionData type: stringAccess type: Read-onlyShort description of the CIM_Setting object—a one-line string.DaylightBiasData type: sint32Access type: Read-onlyQualifiers: Units(Minutes)Bias value to be used during local time translations that occur during daylight saving time. Thisproperty is ignored if a value for the DaylightDay property is not supplied. The value of this propertyis added to the Bias property to form the bias used during daylight time. In most time zones, thevalue of this property is -60.DaylightDayData type: uint32Access type: Read-onlyDaylightDayOfWeek of the DaylightMonth when the transition from standard time to daylightsaving time occurs on this operating system.Example: If the transition day (DaylightDayOfWeek) occurs on a Sunday, then the value "1"indicates the first Sunday of the DaylightMonth, "2" indicates the second Sunday, and so on. Thevalue "5" indicates the last DaylightDayOfWeek in the month.DaylightDayOfWeekData type: uint8Access type: Read-onlyDay of the week when the transition from standard time to daylight saving time occurs on anoperating system.ValueMeaning0 (0x0) SundayHP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 35


1 (0x1) Monday2 (0x2) Tuesday3 (0x3) Wednesday4 (0x4) Thursday5 (0x5) Friday6 (0x6) SaturdayHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.Example: 1DaylightHourData type: uint32Access type: Read-onlyHour of the day when the transition from standard time to daylight saving time occurs on anoperating system.Example: 2DaylightMillisecondData type: uint32Access type: Read-onlyMillisecond of the DaylightSecond when the transition from standard time to daylight saving timeoccurs on an operating system.DaylightMinuteData type: uint32Access type: Read-onlyMinute of the DaylightHour when the transition from standard time to daylight saving time occurs onan operating system.Example: 59DaylightMonthData type: uint32Access type: Read-onlyMonth when the transition from standard time to daylight saving time occurs on an operating system.ValueMeaning1 (0x1) January2 (0x2) FebruaryHP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 36


3 (0x3) March4 (0x4) April5 (0x5) May6 (0x6) June7 (0x7) July8 (0x8) AugustHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.9 (0x9) September10 (0xA) October11 (0xB) November12 (0xC) DecemberDaylightNameData type: stringAccess type: Read-onlyQualifiers: MaxLen(256)Time zone being represented when daylight saving time is in effect.Example: "EDT" (Eastern Daylight Time)DaylightSecondData type: uint32Access type: Read-onlySecond of the DaylightMinute when the transition from standard time to daylight saving time occurson an operating system.Example: 59DaylightYearData type: uint32Access type: Read-onlyYear when daylight saving time is in effect. This property is not required.Example: 1997DescriptionData type: stringAccess type: Read-onlyDescription of the CIM_Setting object.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 37


SettingIDData type: stringAccess type: Read-onlyIdentifier for the CIM_Setting object.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.StandardBiasData type: uint32Access type: Read-onlyQualifiers: Units(Minutes)Bias value to use when daylight saving time is not in effect. This property is ignored if a value forStandardDay is not supplied. The value of this property is added to the Bias property to form thebias during standard time.Example: 0StandardDayData type: uint32Access type: Read-onlyStandardDayOfWeek of the StandardMonth when the transition from daylight saving time tostandard time occurs on an operating system.If the transition day (StandardDayOfWeek) occurs on a Sunday, then the value "1" indicates thefirst Sunday of the StandardMonth, "2" indicates the second Sunday, and so on. The value "5"indicates the last StandardDayOfWeek in the month.StandardDayOfWeekData type: uint8Access type: Read-onlyDay of the week when the transition from daylight saving time to standard time occurs on anoperating system.ValueMeaning0 (0x0) Sunday1 (0x1) Monday2 (0x2) Tuesday3 (0x3) Wednesday4 (0x4) Thursday5 (0x5) Friday6 (0x6) SaturdayHP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 38


StandardHourData type: uint32Access type: Read-onlyHour of the day when the transition from daylight saving time to standard time occurs on anoperating system.Example: 11HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.StandardMillisecondData type: uint32Access type: Read-onlyMillisecond of the StandardSecond when the transition from daylight saving time to standard timeoccurs on an operating system.StandardMinuteData type: uint32Access type: Read-onlyMinute of the StandardDay when the transition from daylight saving time to standard time occurs onan operating system.Example: 59StandardMonthData type: uint32Access type: Read-onlyMonth when the transition from daylight saving time to standard time occurs on an operating system.ValueMeaning1 (0x1) January2 (0x2) February3 (0x3) March4 (0x4) April5 (0x5) May6 (0x6) June7 (0x7) July8 (0x8) August9 (0x9) September10 (0xA) October11 (0xB) NovemberHP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 39


12 (0xC) DecemberStandardNameData type: stringAccess type: Read-onlyQualifiers: Key, MaxLen(256)HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.Name of the time zone being represented when standard time is in effect.Example: "EST" (Eastern Standard Time)StandardSecondData type: uint32Access type: Read-onlySecond of the StandardMinute when the transition from daylight saving time to standard timeoccurs on an operating system.Example: 59StandardYearData type: uint32Access type: Read-onlyYear when standard time is in effect. This property is not required.Example: 1997RemarksThe Win32_TimeZone class is derived from CIM_Setting.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 40


Exercise 3. Pattern to read customers from a Spreadsheet.Develop a new pattern that will read data from a spreadsheet (CSV). You can use anyresources available to you ( I want you to write the pattern from scratch, no using the existingOOTB pattern) Make sure you follow best practices for writing your script , use the loggers,use the API routines when needed, etc.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.The pattern will read rows in the supplied CSV file - c:\customerdata.csv and populate theCIT class “Customers”.You will debug the script using the Discovery Analyzer and Eclipse prior to running it in theprobe.1. Create a new CIT class in UCMDB “Customers”, make it a sub-class of Business.Use best practice naming conventions.2. Create the attributes according to the columns in the CSV – C:/customerdata.csv.Use best practice naming for your attributes. Examine the data using an editor to helpyou determine more information.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 41


HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.CustomerID (Key)Customers_company_nameCustomer_contact_nameCustomer_contact_titleCustomers_addressCustomers_CityCustomers_regionCustomers_postal_codeCustomers_countryCustomers_phoneCustomers_faxStringStringStringStringStringStringStringStringStringStringString3. Create a new pattern, module, job, python script , and a readme file for reading thedata from the file. Also create a view for the data in UCMDB.a. Create the pattern firstb. Create the script secondc. Associate your script with the patternd. Create the modulee. Create the job4. Create a new package <strong>DDM</strong>_<strong>Advanced</strong>_CSV that contains your pattern, module, job,view, cutomers class CIT, readme file5. Debug your script using Eclipse with the Discovery Analyzer. Do not run it in theprobe until you debug it using the DA.6. Once you have the script working load the script into your probe and run it. Verifythe CIs get created in the Customers CIT.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 42


Exercise 4. Pattern to read product orders create order CIs and linkthem to customers.HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.This lab will create a new package from scratch. You will need 6 things in this package. New CIT (class) Orders make it inherited from System. Three attributes City,OrderID, CustomerID New Module Order – lab New Job Orderjob , use a trigger TQL of SQLServer New Pattern Orderpattern , Trigger CIT SQLServer New python script to do your discovery Orderscript.py New view showing orders with their shipped to customersFollow best practices for design, coding, debugging and productization.MAIN1. Create a new CIT called orders in UCMDBa. Add an attribute for City, OrderID, and CustomerID2. Create a new link called “shipped to” in UCMDB3. Allow the link between the orders and customers CITs4. Create your new pattern Orderpattern5. Create a script that will read all the OrderIDs , Ship City, and CustomerID from theNorthwind database in the MS SQL Server on your VM. Use logger.info to printmessages. Outline for the script:a. Initialize variablesb. Retrieve the parameter attributes (CredentialsID)c. Use the getClientFactory framework get the SQL Server client credentialsd. Establish a client connection to SQL Server using ClientSQLServerConnectione. Call the ORDER FUNCTIONf. Add the returned result to the vectorg. Close the client connectionh. Return the vector to UCMDB serverORDER FUNCTION:a. Open the connectionb. Select all rows for the OrderID, ShipCity, CustomerID from the DBNorthwind..Orders DBc. Create a OSH to hold the orderd. Loop over all the rows returned, parsing each and inserting attributes into theOSHe. Get the Customer for the Order by using a framework call (The customers werecreated in Exercise 2 above)f. Create a link OSH to link each Order to a Customer using the cusdomer youretrieved. Use a link type of “shipped to”.g. Close the connectionh. return the vector to the main6. Create your module and your job7. Debug your script using the DA , use Eclipse if you want (optional).HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 43


8. Create a package for your items, save it to disk9. Deploy the package to the probe and run it10. Bring up your view and validate that it is correctHAVE FUN!References:HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.UCMDBDiscoveryDevelopment<strong>Guide</strong>.docUCMDB80 Framework APIClass materialExample Screen shot of the CIT OrdersHP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 44


Screen shot of the example package OrdersHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 45


PART 5: ANSWERS TO EXERCISESPart 1 AnswersFinds Major , minor, update version numbers from the ver command:HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.\[Version\s(\d)\.(\d)\.(\d{4})Gets the Lease obtained and the lease expired from ipconfig /all command:Obtained.+?:\s(.+)Expires.+?:\s(.+)Gets the processor information from the Systeminfo commandProcessor\(\s\):^*(\d*).*\n\s*(.*)Processor\(.\):\s*(\d*).*\s*(\[.*]*)Processor\(s\):\s*(.*)\n\s*(.*)Part 2 Answersimport reimport osfilename = "c:/test.dat"# Create a file object:# in "write" modeFILE = open(filename,"w")# Run the os command systeminfo and send the output to the file#buffer = os.popen("systeminfo")## Write the buffer to the file and close the file#FILE.writelines(buffer)FILE.close()# Open the file for readFILE = open (filename,"r")HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 46


count = 0for line in FILE:if re.search(".*?\s-?\sUpdate", line): count = count + 1FILE.close()print "The number of updates on the system is ",countHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.Part 3 AnswersExercise 1import reimport stringimport loggerimport netutilsimport modelingfrom modeling import NetworkInterface# Java importsfrom java.lang import *from java.util import *from appilog.common.system.types.vectors import ObjectStateHolderVectorfrom appilog.common.system.types import ObjectStateHolderfrom appilog.collectors.clients import ClientsConstsfrom appilog.common.system.types.vectors import ObjectStateHolderVector#fix version formatdef fixformat(version):if version[3] == '.':version = version[0:3] + '0' +version[3:]return version#separate caption to vendor, os name and installation typedef seperateCaption(hostOSH, caption, osbundle):osnames = osbundle.getKeys()found = 0for osname in osnames:indexWMI = osname.find('WMI_')if indexWMI < 0:continue;fixosname = osname[4:]fixosname = fixosname.replace('_', ' ')index = caption.find(fixosname)if index > -1:value = osbundle.getString(osname)values = value.split('#')hostOSH.setAttribute('host_vendor', values[0])hostOSH.setAttribute('host_os', values[1])hostOSH.setAttribute('host_osinstalltype', values[2])found = 1breakif found == 0:if len(caption) > 250:HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 47


caption = caption[0:249]hostOSH.setAttribute('host_os', caption)return hostOSHHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.# WMI may report mulitple ip's in a comma separated string# WMI may report mulitple ip masks in a comma separated stringdef getIPNetworkMemebrList(ipList, netmaskList, dnsname=''):_ipList = []_maskList = []_ipOshList = []vec = ObjectStateHolderVector()ips = string.split(ipList, ',')for ip in ips:_ipList.append(ip)masks = string.split(netmaskList, ',')for mask in masks:_maskList.append(mask)for i in range(len(_ipList)):try:ip = _ipList[i]mask = _maskList[i]if ((not netutils.isValidIp(ip)) ornetutils.isLocalIp(ip)):# invalid or local iplogger.debug('ignoring invalid ip=%s' % ip )continuereturn vec# ip is valid and not local (i.e. 0.0.0.0, 127.0.0.1)# create an IPipOSH = modeling.createIpOSH(ip, mask)vec.add(ipOSH)# create networknetOSH = modeling.createNetworkOSH(ip, mask)link = modeling.createLinkOSH('member', ipOSH, netOSH)vec.add(netOSH)vec.add(link)except:logger.errorException("Failed parsing IP: ", ip)def doWMI(client, wmiOSH, ip_address, ip_domain, osbundle):wmihostForLinkOSH = modeling.createHostOSH(ip_address)wmiOSH.setContainer(hostForLinkOSH)machineName = ''#Modification made on 13/06/2006 to retrive host name directly from_wmiQuery6 = 'select Name from Win32_ComputerSystem'resultSet = client.executeQuery(_wmiQuery6)if resultSet.next():machineName = resultSet.getString(1)machineName = machineName.lower()DuplicateTest = ''HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 48


ip definedipOSH, interfaceOSH)# create link interface to its ip only it has anparentLink = modeling.createLinkOSH('parent',parentLinkList.add(parentLink)interfaceList.append(interface)ipIndex = ipIndex + 1HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.# create the host and all the objectsif len(interfaceList) > 0:hostOSH = Nonetry:hostOSH =modeling.createCompleteHostOSHByInterfaceList('nt', interfaceList,'Windows', machineName)except:hostOSH = modeling.createHostOSH(ip_address, 'nt')logger.debugException('Could not find a valid MACaddress for key on ip : %s. Creating incomplete host\n' % ip_address )logger.warn('Could not find a valid MAC address for keyon ip : %s. Creating incomplete host\n' % ip_address )# select from Win32_OperatingSystem_wmiQuery = 'selectCaption,Version,ServicePackMajorVersion,ServicePackMinorVersion,BuildNumber,Organization,RegisteredUser,TotalVisibleMemorySize fromWin32_OperatingSystem'resultSet = client.executeQuery(_wmiQuery)if resultSet.next():Caption = resultSet.getString(1)Version = resultSet.getString(2)Version = fixformat(Version)ServicePackMajorVersion = resultSet.getString(3)ServicePackMinorVersion = resultSet.getString(4)BuildNumber = resultSet.getString(5)Organization = resultSet.getString(6)RegisteredUser = resultSet.getString(7)TotalVisibleMemorySize = resultSet.getString(8)hostOSH = seperateCaption(hostOSH, Caption, osbundle)hostOSH.setAttribute('host_osversion', Version)sp = ServicePackMajorVersion + '.' +ServicePackMinorVersionif len(sp) > 1:hostOSH.setAttribute('nt_servicepack', sp)try:hostOSH.setAttribute('nt_kernelbuild',int(BuildNumber))except:passhostOSH.setAttribute('nt_registrationorg', Organization)hostOSH.setAttribute('nt_registeredowner',RegisteredUser)hostOSH.setAttribute('nt_physicalmemory',TotalVisibleMemorySize)hostOSH.setAttribute('host_hostname', machineName)# Modification made on 05/09/2006 to retrieve the hostmanufacturer from the win32_computersystem class_wmiQuery2 = 'select Manufacturer from Win32_ComputerSystem'HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 50


esultSet = client.executeQuery(_wmiQuery2)if resultSet.next():Manufacturer = resultSet.getString(1)if ((Manufacturer != None) and(Manufacturer.find('system manufacturer') == -1)):hostOSH.setAttribute('host_manufacturer',Manufacturer)HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.# Modification made on 05/12/2006 to retrieve the hostNumberOfProcessors from the win32_computersystem class_wmiQuery3 = 'select NumberOfProcessors fromWin32_ComputerSystem'resultSet = client.executeQuery(_wmiQuery3)if resultSet.next():NumberOfProcessors = resultSet.getString(1)hostOSH.setAttribute('nt_processorsnumber',int(NumberOfProcessors))# Modification made on 05/09/2006 to retrieve the host modelfrom the win32_computersystem class_wmiQuery4 = 'select Model from Win32_ComputerSystem'resultSet = client.executeQuery(_wmiQuery4)if resultSet.next():Model = resultSet.getString(1)hostOSH.setAttribute('host_model', Model)# Modification made on 05/18/2006 to retrieve the host serialfrom the Win32_SystemBIOS.PartComponent class_wmiQuery5 = 'select SerialNumber from Win32_BIOS'resultSet = client.executeQuery(_wmiQuery5)if resultSet.next():SerialNumber = resultSet.getString(1)hostOSH.setAttribute('host_serialnumber', SerialNumber)vector.add(hostOSH)# Query for standard and daylight time from Win32_TimeZoneclasswmiQueryTime = 'SELECT StandardName,DaylightName FROMWin32_TimeZone'#print("QUERY: ", wmiQueryTime)resultSetTime = client.executeQuery(wmiQueryTime)while resultSetTime.next():StandardTime = resultSetTime.getString(1)DaylightTime = resultSetTime.getString(2)hostOSH.setAttribute('nt_standardtime', StandardTime)hostOSH.setAttribute('nt_daylighttime', DaylightTime)#print("STANDARD TIME: ", StandardTime)#print("DAYLIGHT TIME: ", DaylightTime)hostOSH))# add all interfaces to the hostvector.addAll(modeling.createInterfacesOSHV(interfaceList,for i in range(vector.size()):osh = vector.get(i)if osh.getObjectClass() == 'ip':HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 51


hostOSH)osh)link = modeling.createLinkOSH('contained', osh,vector.add(link)elif osh.getObjectClass() == 'network':link = modeling.createLinkOSH('member', hostOSH,vector.add(link)vector.addAll(parentLinkList)HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.vector.add(wmiOSH)return vectordef mainFunction(Framework):_vector = ObjectStateHolderVector()ip_address = Framework.getDestinationAttribute('ip_address')ip_domain = Framework.getDestinationAttribute('ip_domain')errStr = ''clientFactory =Framework.getClientFactory(ClientsConsts.WMI_PROTOCOL_NAME)protocols = clientFactory.getAvailableProtocols(ip_address,ip_domain)if protocols.__len__() == 0:errStr = 'No credentials defined for the triggered ip'logger.debug(errStr)return (_vector, errStr)osbundel = 'osdepend'osbund = Framework.getBundle(osbundel)connected = 0for protocol in protocols:client = Nonetry:debug_string = ip_domain + "\\" + ip_addresslogger.debug('try to get wmi agent for: ', debug_string)client = clientFactory.createClient(protocol)logger.debug('got wmi agent for: ', debug_string)# create wmi OSHwmiOSH = ObjectStateHolder('wmi')wmiOSH.setAttribute('data_name',ClientsConsts.WMI_PROTOCOL_NAME)wmiOSH.setAttribute('application_ip', ip_address)wmiOSH.setAttribute('credentials_id',client.getCredentialId())_vector = doWMI(client, wmiOSH, ip_address, ip_domain,osbund)if _vector.size() > 0:connected = 1breakexcept:logger.debugException('Failed connecting usingcredentialID on ip=%s' % ip_address, protocols)if client != None:client.close()if (not connected):errStr = 'Failed to connect using all protocols'logger.debug(errStr)HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 52


elif (_vector.size()


##############################################def DiscoveryMain(Framework):HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.print 'Start CSV Parser'OSHVResult = ObjectStateHolderVector()# Destination DatafileName = Framework.getParameter('file_name')logger.info('FileName: ', fileName)try:CSV_readFile(fileName, OSHVResult)except:stacktrace = traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1],sys.exc_info()[2])logger.info( 'Exception:')logger.info( stacktracet)print 'End CSV Parser'## Write implementation to return new result CIs here...return OSHVResultExercise 3Jython scriptimport loggerimport SqlServerConnectionfrom java.util import Propertiesfrom appilog.common.system.types.vectors import ObjectStateHolderVectorfrom appilog.common.system.types import ObjectStateHolderfrom com.mercury.topaz.cmdb.shared.model.object.id import CmdbObjectIDfrom appilog.collectors.clients import ClientsConstsdef geOrders(connection):print 'geOrders 1'connection.open()rs = connection.getTable("SELECT OrderID, ShipCity FROMNorthwind..Orders")vec = ObjectStateHolderVector()print 'geOrders 2'while rs.next():print 'geOrders 3'OrderID = rs.getString("OrderID")ShipCity = rs.getString("ShipCity")print 'OrderID ', OrderIDorder = ObjectStateHolder("aaOrder")HP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 54


order.setAttribute("aaID",OrderID)order.setAttribute("aaCity",ShipCity)vec.add(order)rs.close()connection.close()return vecHP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.################################## ## MAIN ENTRY POINT ## ################################### Destination Datadef DiscoveryMain(Framework):print '1'OSHVResult = ObjectStateHolderVector()hostId=CmdbObjectID.Factory.restoreObjectID(Framework.getDestinationAttribute('hostId'))sqlServerId=CmdbObjectID.Factory.restoreObjectID(Framework.getDestinationAttribute('id'))print '2'if 1: #try:#### TRY CONNECT TO DATABASE ####mssqlClient =Framework.getClientFactory(ClientsConsts.SQL_PROTOCOL_NAME).createClient()print '22'connection =SqlServerConnection.ClientSqlServerConnection(mssqlClient)logger.debug("got connection")print '3'# do the workorderVec = geOrders(connection)# add it to result vecOSHVResult.addAll(orderVec)mssqlClient.close()else: #except:#### FAILED TO CONNECT ####logger.debugException('Failed to connect')return OSHVResultHP Global Enablement© Copyright 2009 Hewlett-Packard Development Company, L.P. 55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!