|
|
Tip 11: Interesting query
Tip 11. For Grid control, How to get the following results
Group Name Target Name Host Name
------------------------------------------------------------------
Grp1 db1 host1
Grp1 db2 host 1
Grp1 db3 host2
Grp2 db4 host2
Grp3 +ASM1 host1
....
A11: This comes from mail list, I replied one approach.
[B]A single group can include many members(targets), they can be
same target type or different target type. Some targets have
relationship with hosts(e.g. database instance, rac instance,
ASM instance,Listeners,,etc) others have not. So, user should
first understand the relationship between group,target and
associate target.[/B]
Let's see an example.
First you should know the relationship between these tables:
"MGMT_TARGETS", "MGMT_TARGET_TYPES",
"MGMT_TARGET_ASSOCS".
Then build single queries, Finally combine them.
For example:
(Optional) [B]Step 1: Get the target type definition[/B]
select target_type from mgmt_target_types where NLS_UPPER(type_display_name)=NLS_UPPER('group')
[B]Step 2: Get the target guid, group name of your created groups[/B]
select rawtohex(target_guid),target_name from mgmt_targets where target_type
in (select target_type from mgmt_target_types where NLS_UPPER(type_display_name)=NLS_UPPER('group'))
[B]Step 3: Get the relationship between source and accoc targets[/B]
select T2.target_name,Rawtohex(T1.ASSOC_TARGET_GUID)
from MGMT_TARGET_ASSOCS T1, MGMT_TARGETS T2
where T2.target_guid=T1.source_target_guid
and T1.source_target_guid in
(select target_guid from mgmt_targets where target_type='composite')
[B]Step 4: Get the relationship between host and specified targets[/B]
select target_name, host_name from mgmt_targets
where target_guid in (Q3) ...
[B]Step 5: Combine these queries, using self-join on tables:[/B]
select T2.target_name as "Group Name",
T3.target_name as "Target Name" ,T3.host_name as "Host Name" from
MGMT_TARGET_ASSOCS T1, MGMT_TARGETS T2,
(select target_guid,target_name, host_name from mgmt_targets) T3
where T2.target_guid=T1.source_target_guid
and T1.source_target_guid in
(select target_guid from mgmt_targets where target_type='composite')
and T3.target_guid=T1.ASSOC_TARGET_GUID |
|