Upload
odanyboy
View
504
Download
2
Tags:
Embed Size (px)
Citation preview
© 2009 BMC Educational Services
Basic TF Query Language
Power searching
© 2010 BMC Educational Services
Query Language Outline
Formulating Queries Basics SEARCH and WHERE Regular Expression Basics Controlling Display Putting it all together
© 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
© 2009 BMC Educational Services
Formulating Queries in the UI
© 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
© 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
© 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
© 2009 BMC Educational Services
SEARCH and WHERE
© 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
© 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]
© 2010 BMC Educational Services
Some Simple Conditions
Equality a = b
Not equals a <> b
Similarly a > b a < b a >= b a <= b
© 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
© 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 + - * /
© 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
© 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
© 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)
© 2009 BMC Educational Services
Query Exercises
© 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
© 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"
© 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"
© 2009 BMC Educational Services
Regular Expression Basics
© 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
© 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
© 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
© 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$'
© 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'
© 2009 BMC Educational Services
Controlling Display with SHOW
© 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
© 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"
© 2009 BMC Educational Services
Putting it all together
© 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
© 2009 BMC Educational Services
Final Exercises
© 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
© 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
© 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