addmi 10.5-basic query-language

35
© 2009 BMC Educational Services Basic TF Query Language Power searching

Upload: odanyboy

Post on 12-Jun-2015

499 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Addmi 10.5-basic query-language

© 2009 BMC Educational Services

Basic TF Query Language

Power searching

Page 2: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Query Language Outline

Formulating Queries Basics SEARCH and WHERE Regular Expression Basics Controlling Display Putting it all together

Page 3: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Query language

A way of asking the datastore to extract a list nodes, and a subset of their attributes Performs the same function as SQL in a relational database

It forms the basis of every datastore read Used internally by Atrium Discovery Used when viewing built-in reports Used for user-generated queries Used for ad-hoc user queries Used within TPL (patterns)

There are special keywords to describe what to pick: SEARCH, WHERE

And keywords to decide how to display it: SHOW, ORDER

Page 4: Addmi 10.5-basic query-language

© 2009 BMC Educational Services

Formulating Queries in the UI

Page 5: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Generic Query Interface

Enter query, may split over several lines for clarity Press ‘Run Query’ to see results Results can be exported as CSV or XML

Page 6: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Previous Queries

Under the search query window a list of previous queries is available Clicking these copies the query into the search box

Page 7: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Saving Previous Queries

Use “//” to provide a title to your query Title is shown in Previous Queries section Can drag and drop query to bookmark

Query will work on any Atrium Discovery instance

Page 8: Addmi 10.5-basic query-language

© 2009 BMC Educational Services

SEARCH and WHERE

Page 9: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

SEARCH

Looks through all the data and returns a set of nodes based on the specified node kind

SEARCH kind Find all nodes of given kind e.g. SEARCH SoftwareInstance

These nodes are displayed as a list

Page 10: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Adding a WHERE

SEARCH Host Collect the set of nodes of kind “Host”

Add limiting conditions

WHERE os_type = 'Solaris' Restrict the set of nodes to those that

contain a specific string in the “os_type” attribute

WHERE <attribute> [conditional statement]

Page 11: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Some Simple Conditions

Equality a = b

Not equals a <> b

Similarly a > b a < b a >= b a <= b

Page 12: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

More Advanced Conditions

a HAS SUBSTRING b Works if the attribute contains the given string

a HAS SUBWORD b Works if the attribute contains the given word

a MATCHES b Lets you use pattern matching (Regular Expressions)

a IN [b, c, d, e] Lets you search for a number of possible values

Page 13: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Multiple Conditions and Arithmetic

Multiple conditions if you join them with logical operations AND OR NOT

Brackets are useful to aid readability, and ensure precedence ( )

Integer arithmetic only + - * /

Page 14: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Special Conditions

DEFINED This condition is true if the node has the attribute The value is not important Useful given the dynamic nature of the datastore

SEARCH Host WHERE processor_type NOT DEFINED

Page 15: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

A Word on Performance

a = b

a HAS SUBWORD b

a HAS SUBSTRING b

a MATCHES b

Full use of datastore indexes

Full use of datastore indexes

Partial use of datastore indexes

No use of datastore indexes

SP

EE

D

Page 16: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Alternatives to MATCHES

Case insensitive search WHERE name MATCHES ‘(?i)fred’ (0.20s) WHERE name HAS SUBWORD ‘fred’ (0.03s)

Multiple word match WHERE os MATCHES ‘(?i)Microsoft.+Datacenter’ (0.14s) WHERE os HAS SUBWORD 'Microsoft Datacenter‘ (0.09s)

A list of possible values WHERE name MATCHES ‘(?i)TSL-D’ (0.24s) WHERE name IN ['tsl-dkirby','tsl-dtweed','tsl-duncan'] (0.08s)

Page 17: Addmi 10.5-basic query-language

© 2009 BMC Educational Services

Query Exercises

Page 18: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Exercise 1

SEARCH host

SEARCH Host SEARCH SoftwareInstance SEARCH DiscoveredFile

Use “//” to title a report Drag and drop to create a bookmark

Page 19: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Exercise 2

SEARCH Host WHERE os = "SunOS 5.10"

SEARCH Host WHERE os <> "SunOS 5.10"

SEARCH Host WHERE name has substring "Win"

SEARCH Host WHERE name has subword "Win"

Page 20: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Exercise 3

SEARCH Host WHERE os = "SunOS 5.10" AND vendor = "Sun Microsystems"

SEARCH Host WHERE os = "SunOS 5.10" AND vendor NOT matches "Sun Microsystems"

Page 21: Addmi 10.5-basic query-language

© 2009 BMC Educational Services

Regular Expression Basics

Page 22: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Character and Anchoring Matches

Characters match themselves, except . ^ $ * + ? { } [ ] \ | () To match one of these you need to put a backslash before it

Be careful with Foundation pathnames Use \. to match a full stop Use \\ to match a (Windows) path separator

Anchoring matches ^expr – match only at start of string expr$ – match only at end of string

Page 23: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

General Matches

. A period matches any character

[ abcdef] square brackets match any one of the things inside [^123] match anything NOT contained within the brackets

a|b matches one thing or the other Brackets group things together: (Fred)|(Fiona) matches

either name

Page 24: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Repeated Characters

Very often want to repeat/extend matches to more than a single character

Sometimes called wildcard matching

? matches 0 or 1 occurrences + matches 1 or more occurrences * matches 0 or more occurrences

Control case matching(?i) means ignore case of matches

Page 25: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Exercise 4

SEARCH Host WHERE name matches '01app$'

SEARCH Host WHERE name matches '02aPP$'

SEARCH Host WHERE name matches '(?i)02aPP$'

Page 26: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Exercise 5

SEARCH Host WHERE name matches '(?i)0*App$' AND vendor matches '(?i)^sun'

SEARCH Host WHERE name matches '(?i)0*App$' AND vendor NOT matches '(?i)^sun'

Page 27: Addmi 10.5-basic query-language

© 2009 BMC Educational Services

Controlling Display with SHOW

Page 28: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

SHOW

By default results set nodes are displayed by showing the “summary attributes” Defined in the taxonomy

SHOW * All attributes defined in the taxonomy

SHOW att1, att2 Only named attributes of the nodes

SHOW summary, attr3 Summary attributes defined in the taxonomy, plus attr3

SHOW att1 AS ‘col1’ , att2 AS ‘col2’ Rename the column headings

Page 29: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Exercise 6

SEARCH Host WHERE name matches '(?i)0*App$' AND vendor NOT matches '(?i)^sun' SHOW *

SEARCH Host WHERE name matches '(?i)0*App$' AND vendor NOT matches '(?i)^sun' SHOW hostname, os_type

SEARCH Host WHERE name matches '(?i)0*App$' AND vendor matches '(?i)^sun'

SEARCH Host WHERE name matches '(?i)0*App$' AND vendor matches '(?i)^sun' SHOW summary, ram AS "Memory"

Page 30: Addmi 10.5-basic query-language

© 2009 BMC Educational Services

Putting it all together

Page 31: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Query Format

Basic format of Query: SEARCH <kinds> [where clause] [show clause]

<kinds> – Used to specify the nodes (objects) to search within

[where clause] – Optional – filters the current set of nodes A WHERE clause evaluates an attribute WHERE hostname = “itapp”

[show clause] – Optional – defines information to return SHOW summary, attribute1, attrbute2 SHOW hostname, os

Page 32: Addmi 10.5-basic query-language

© 2009 BMC Educational Services

Final Exercises

Page 33: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Exercise 7

For all hosts show following attributes: hostname, host type all os attributes

Let’s refine the query: Limit the query to only windows hosts Show attributes a bit more interesting to windows hosts Add the virtual attribute

Refine the query again: Limit by windows hosts that have any service pack details

Refine the query once again: Limit by windows hosts that DO NOT have service pack details

Page 34: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Exercise 8

Refine the query from the last labs : To display all hosts except for windows Remove service pack limitation Remove the windows specific attributes Add attributes that are more interesting to non windows hosts

Refine again by: Limit by hosts that have power supply status details Show package count totals

Page 35: Addmi 10.5-basic query-language

© 2010 BMC Educational Services

Online Documentation: http://www.tideway.com/confluence/display/81/Search+and+Reporting+Service http://docs.python.org/dev/howto/regex.html http://www.tideway.com/configipedia/Writing_Efficient_Regex

Further Resources