Service And Operations Bridge Best Practices BSM 9

Service And Operations Bridge Best Practices: BSM 9. 20 - Groovy scripts Denis Rachal Sept. 2012 © Copyright 2011 -2013 Hewlett-Packard Development Company, L. P. The information contained herein is subject to change without notice.

Agenda Topic Details Minutes Groovy Scripting Types Available APIs Debugging Memory & Performance Examples Feedback & Q&A Total event minutes 2 60

Groovy Scripts Types Available APIs Dos & Don’ts Debugging Memory Usage & Performance Examples 3

Groovy Script Types in BSM Six Types • • • 4 EPI Cusom Action Topology Synchronization Certificates Event Forwarding Service Health

Groovy Script Types in BSM EPI • Event Processing Interface • Stored in the DB • • Admin->Operations Management->Event Automation->Event Processing Customizations OOTB • <install>examples/epi-scripts • Called by Event Pipeline on DPS • Executed in hpbsm_opr-scripting-host (9. 20) • • Executed in hpbsm_opr-epi-server (9. 0 x, 9. 1 x) • 5 log/opr-scripting-host. log/opr-epi-server. log

Groovy Script Types in BSM Custom Action • Custom actions for automation of event browser functions • Stored in DB • • Admin->Operations Management->Operations Console>Custom Actions OOTB • <install>examples/ca-scripts • Launched by Operator • Executed in hpbsm_opr-scripting-host (9. 20) on GW Server • • Executed in hpbsm_opr-ctxm-server (9. 1 x) on GW Server • 6 log/opr-scripting-host. log/opr-ctxm-server. log

Groovy Script Types in BSM Topology Synchronization • Custom business logic during topology synchronization execution • Stored in DB • • Uploaded from file system at install: conf/opr/topology-sync/sync-packages bin/opr-sdtool. [bat|sh] • Some OOTB packages have groovy scripts, e. g. • • • HPOpr. Mss HPOpr. Ora HPOpr. Vir • Called by Topology Synchronization on GW Server • Basic topology executed by command line tool: opr-start. Topology. Sync. bat • • Dynamic Toplogy Synchronization: Executed in wde ovsvcdiscserver webapp • 7 log/opr-topologysync log/wde/opr-svcdiscserver. log

Groovy Script Types in BSM (3) Certificates • Automates certificate handling • Stored in the DB • • Admin->Operations Management->Setup=>Certificate Requests OOTB – Auto. Grant script • Called by Certifcate handling on GW Server • 8 Executed in opr-scripting-host (9. 20) • log/opr-scripting-host • Script inti() called on first certificate request

Groovy Script Types in BSM (3) • Event Forwarding • For building adapters to 3 rd party applications • Stored in the DB • • Admin->Operations Management->Setup>Connected Server OOTB • Logfile. Adapter • Service. Manager. Adapter • Called by Event Forwarding on GW Server • Executed in hpbsm_opr-scripting-host (9. 20) • • Executed in hpbsm_opr-ctxm-server (9. 1 x) • • log/opr-ctxm-server/opr-event-sync-adapter. log Executed in hpbsm_wde (9. 0 x) • 9 log/opr-scripting-host/opr-event-sync-adapter. log/wde/opr-event-sync-adapter. log

Groovy Script Types in BSM • Service Health Rules • Custom business logic to affect KPI status calculation • Executed in Marble process • Covered in more detail in SH module 10

Available BSM Platform APIs • Platform • BSM Extensibility Guide • • • Service Health SLM EUM Topology Synchronization Event WS Event Forwarding • BSM API documentation • • <install>/App. Server/webapps/site. war/amdocs/eng/doc_lib/API_docs <install>/opr/api/doc • RTSM Developers Reference • • RTSM Java API RTSM Web Service • Command Line Tools • • 11 opr/support/submit. Events etc. . .

Available External APIs • External • Java JDK • Generic JDBC Access • • http: //docs. oracle. com/javase/tutorial/jdbc/basics/index. html General Web Service access • • URL. open. Connection() Command Line Tools • JSON • http: //json. org • Apache • Log 4 j logging • • Wink JSR 311, REST Web Service APIs • • http: //incubator. apache. org/wink/ Commons HTTP Client • • 12 http: //logging. apache. org/log 4 j/1. 2/ http: //hc. apache. org/httpclient-3. x/ Axis 2 - SOAP • http: //axis. apache. org/axis 2/java/core/

Dos • • • Cache data wherever possible (CIs) Use Goovy Console for validation & testing (more in debugging) Use logging for debugging Use comments & verbose variable names Use Notepad++, VI, Emacs, etc. • Copy/paste from emails/pdfs/word documents may result in invalid code • Mark EPI scripts read only that don‘t need to update events • Make it robust • Use try/catch • Recover from DB disconnects by reconnecting • Use ‚? ‘ when dereferencing properties of a structure, e. g. if (event. assigned. User? . user. Name) 13

Dont‘s • • • 14 Use slow APIs in performance critical code (event pipeline) Avoid use of „def“ Excessive logging in production Connecting to DB on each call Call System. exit(), etc. . .

EPI Specific Tips • Take care of Performance • • Too many scripts Too much memory (see JVM statistics later) • • Relase resources and watch for memory leaks Calling slow APIs (avoid web services, CLIs) • Use background threads and cache information where possible • Open close files and DB in init() Mark Read Only when possible Script filter can slow execution • Watch for script timeouts • • Use reasonable values Read only versus Read/Write Scripts • Logging 15

Debugging Groovy Console • Check BSM Groovy version • • 9. 20: 1. 7. 3 9. 10: • lib: 1. 7. 3 • opr/lib inadvertently contained version 1. 6. 0, fixed in 9. 13 to contain 1. 7. 3 • 9. 01: • lib: 1. 5. 6 • opr/lib: 1. 6. 0 • Don’t forget to “import” the classes you use • Use the Groovy Console for testing and validation • • • 16 Download from http: //groovy. codehaus. org Copy external libs to <groovy install>/lib Launch Groovy Console from <groovy install>/bin/groovy. Console

Debugging Logging • Log messages using Apache logger. • Event Forwarding & Topology Synchronization will pass you a logger • Separate logger can be directly instantiated private static Log s_log = Log. Factory. get. Log("com. hp. opr. epi. My. Logs") • Methods • info() : Use sparingly, e. g. on init/destroy • error(): Use for indicating error conditions • warn(): Use for possible errors • debug(): Use for debugging • is. Debug. Enabled() : Check when concatenating strings in debug() call, e. g. if (s_log. debug. Enabled) s_log. debug("Event discarded: '${event. title}'") • OMi scripting runs in opr-scripting-host process • SH scripting runs in the marble process 17

Memory Usage & Performance • JVM Statistics • OOTB for opr-backend • log/opr-backend/jvm_statistics. log 2012 -09 -21 16: 13: 26, 159 INFO - JVMStatistics is started !!! 2012 -09 -21 16: 13: 26, 173 INFO - Starting JVMStatistics task with interval 60000 ms. 2012 -09 -21 16: 13: 26, 186 INFO - HEAP - [USAGE: 57. 1, FREE: 188. 2, TOTAL: 245. 3, MAX: 245. 3]; PERM - [USAGE: 23. 9, FREE: 72. 0, MAX: 96. 0]; CLASSES - [Loaded: 3921, Unloaded: 0, Left: 3921]; THREADS - [Count: 26] • Can be added for other processes, e. g. • opr-scripting-host • Check log files for execution times • Log entry and exit to methods (debug mode) 18

Code Snippets Command Line Tool Execution • Code Snippet: How to Call a Command Line Tool • http: //groovy. codehaus. org/Executing+External+Processes+From+Groovy /* execute an external command get the output in a string */ String cmd = "ipconfig" String cmd. Args = "/all" String external. Cmd = "cmd /c ${cmd} ${cmd. Args}" String. Buffer input. Buffer = new String. Buffer() String. Buffer error. Buffer = new String. Buffer() Process runcmd = "${external. Cmd}". execute() runcmd. consume. Process. Output(input. Buffer, error. Buffer) runcmd. wait. For() 19

Code Snippets Event WS Call • Code Snippet: How to Call the Event WS • See also BSM Extensibility Guide • Create. Event. groovy for full sample private final Rest. Client m_client = new Rest. Client() private final Password. Authentication m_credentials = new Password. Authentication(USERNAME, PASSWORD. to. Char. Array()). . . String address = “http: //mygw. ex. com/opr-web/9. 10/event_list“ Resource resource = m_client. resource(address) resource. accept(Media. Type. APPLICATION_ATOM_XML). content. Type(Media. Type. APPLICATION_ATOM_XML) // Set the username and password in the request. String encoded. User. Password = Base 64. encode. Bytes((m_credentials. user. Name + ": " + new String(m_credentials. password)). bytes) resource. header("Authorization", "Basic " + encoded. User. Password) 20

Code Snippets Event WS Call (cont. ) try { final Client. Response response = resource. post(opr. Event) if (response. status. Code > 299) { // just log an error final String message = response. get. Entity(String. class) if (message) s_log. error("HTTP error response on event creation - ${response. message} (${response. status. Code}): ${message}") else s_log. error("HTTP error response on event creation - ${response. message} (${response. status. Code})") } } catch (Client. Web. Exception e) { // clear the cookies. they may be stale clear. Cookies() } 21

Code Snippets Event WS Update Call • Just add the ID to the end of the URL and PUT an event • You can also „bulk“ update several events at once • Instead of specifying event ID add a query string, e. g. • http: //host/opr-web/rest/9. 10/event_list? query=title like “%node down%“ • Event with change will be applied to all events that match the query • Careful! No query string will update ALL events. 22

Code Snippets Get the OMi version running import com. hp. opr. api. Version. . . Integer omi. Version = 0 // determine the OPR version that is running String version. String = Version. get. Property(Version. COMPONENT_VERSION) String[] version = version. String. split('\. ') omi. Version = (Integer. value. Of(version[0]) * 100) + Integer. value. Of(version[1]) // result = 920 or 913 or 912 or 901, etc. . . 23

Code Snippets Access RTSM • Query the RTSM for Cis – Sample Potentially. Affected. CIs. groovy Ucmdb. Service. Provider provider = null Ucmdb. Service service = null void init() { provider = Ucmdb. Service. Factory. get. Service. Provider(HOST_NAME, PORT) service = provider. connect(provider. create. Credentials(USERNAME, PASSWORD), provider. create. Client. Context("Potentially. Affected. CIs")) s_log. info("Initialized. ") } 24

Code Snippets SOAP WS Call • Apache Axis 2 • http: //axis. apache. org/axis 2/java/core/ • Use wsdl 2 java to generate client stub code • Best to download the WSDL to local directory wsdl 2 java. sh -s -o /tmp/om_axis -uri. /wsdls/Incident. Service. wsdl • Add Axis 2 libraries to the DPS/Gateway server as appropriate rather than loading into DB 25

Sample Scripts EPI • Zip File with Sample Scripts • EPI • • • • 26 Add. Generic. CIHint Add. Generic. Node. Hint Automate. Data. Store. CIHint Epi. Event. Discard Extend. NNMi. Ci. Hint. For. Global. IDs Potentially. Affected. CIs Integration of CA Spectrum Alarm and node topology into BSM/OMi 9. 13 OMi 9. x-Tech. Note-EPIFor. Tivoli. Adaptor. Update. Enhancement OMi Technote – Owner. Resolver OMi Technote – View. Folder. Mapping OMi_SM_Event_Integration_Custom_White. Paper_v 1_2 (EPI & Event Forwarding) OMi_Topology_Based_Event_Enrichment_White. Paper_v 1_0 <install>/opr/examples/epi-scripts

Sample Scripts • Zip File with Sample Scripts • Custom Action • • <install>/opr/examples/ca-scripts Forwarding • • Logfile. Adpater Code Snippets • • • Create. Event - Calling a REST Web Service Calling a CLI – shown in slide KPI • • Provided in the OMi OOTB Content Pack Topology • 27 Provided in OOTB Topology Synchronization packages • HPOpr. Mss • HPOpr. Ora • HPOpr. Vir

Q&A 28
- Slides: 28