OEM target property update 2
#!/bin/bash
# Define SQL query to fetch missing/incorrect properties
SQL_QUERY="
SELECT
h.target_name,
tp.property_name,
tp.property_value,
cd.support_group,
cd.install_status,
cd.oracle_home,
cd.u_cmdb_ci_used_for,
cd.u_cmdb_owner_group,
cd.name,
cd.correlation_id,
cd.version
FROM
sysman.mgmt\$target h
LEFT JOIN mgmt\$target_properties tp
ON h.target_name = tp.target_name
AND tp.property_name IN ('udtp_2', 'orcl_gtp_contact', 'orcl_gtp_lifecycle_status')
LEFT JOIN OEM.db_DAILY cd
ON h.target_name = cd.name
WHERE
(tp.property_value IS NULL OR tp.property_name IS NULL)
OR (tp.property_name = 'orcl_gtp_contact' AND tp.property_value != cd.support_group)
OR (tp.property_name = 'orcl_gtp_lifecycle_status' AND tp.property_value != cd.install_status)
OR (tp.property_name = 'udtp_2' AND tp.property_value IS NULL)
OR cd.oracle_home IS NULL;
"
# Execute SQL and store results in a temporary file
sqlplus -S user/password@your_db <<EOF > /tmp/missing_properties.txt
$SQL_QUERY
EOF
# Loop through each result and generate emcli update commands
while IFS=" " read -r target_name property_name property_value support_group install_status oracle_home; do
# Check for NULL or incorrect values and generate corresponding emcli command
if [[ "$property_name" == "orcl_gtp_contact" && "$property_value" != "$support_group" ]]; then
# Update orcl_gtp_contact property
emcli modify_target -name="$target_name" \
-type="oracle_database" \
-properties="orcl_gtp_contact->$support_group" \
-separator-properties="|" \
-subseparator-properties="->" \
-on_agent
echo "Updated orcl_gtp_contact for $target_name to $support_group"
elif [[ "$property_name" == "orcl_gtp_lifecycle_status" && "$property_value" != "$install_status" ]]; then
# Update orcl_gtp_lifecycle_status property
emcli modify_target -name="$target_name" \
-type="oracle_database" \
-properties="orcl_gtp_lifecycle_status->$install_status" \
-separator-properties="|" \
-subseparator-properties="->" \
-on_agent
echo "Updated orcl_gtp_lifecycle_status for $target_name to $install_status"
elif [[ "$property_name" == "udtp_2" && -z "$property_value" ]]; then
# Update udtp_2 (hosting) property to the correct value
# Assuming you know the value to update; adjust this accordingly
hosting_value="correct_value" # Replace with actual logic if needed
emcli modify_target -name="$target_name" \
-type="oracle_database" \
-properties="udtp_2->$hosting_value" \
-separator-properties="|" \
-subseparator-properties="->" \
-on_agent
echo "Updated udtp_2 for $target_name to $hosting_value"
fi
done < /tmp/missing_properties.txt
Comments
Post a Comment