Showing posts with label OS script. Show all posts
Showing posts with label OS script. Show all posts

Monday, December 10, 2012

EM12c: How to create OS script based Metric Extension and deploy it on a target?

To create OS shell script based metric extension (ME), follow given steps:

1. Select Enterprise->Monitoring->Metric Extensions

2. Provide values for the metric extension properties in Create New wizard first page.


3. Provide shell scripting binary like /bin/sh, Shell Script name, Delimiter and Starts With expression as given below and Select Add button to add the shell script.


4. In this example, very simple script has been specified to explain the steps.


5. In next step of wizard, one needs to specify the output columns. As per given sample script, two columns Uptime and Users have been created here.



6. Select Credentials in next step to be used for this metric extension.


7. To test this metric extension, select Test Targets


8. Click on Run Test button to test the metric extension on Test target. You should see test output in Test Results panel.


9. Before submitting, review final definition for proposed metric extension.


10. Metric Extension is successfully created.


11. Once the metric extension is created, next step would be to save it as Deployable Draft as given below.


12. Once the status of metric extension shows as Deployable Draft. Select the metric extension and Deploy it to target as shown below.


13. You should see that the Metric Extension is deployed successfully.




14. After 15 min., Go to the target where this metric extension has been deployed. Select Monitoring->All Metrics. Yous should see following:

Tuesday, September 20, 2011

How to create an OS script based UDM to calculate “Network Packet Loss”?


To create OS script based UDM, following steps are needed:
1. Create the OS script
2. Create an OS script based UDM

Let’s look at these steps in detail:
1. Create the OS script (For details, look at http://download.oracle.com/docs/cd/E11857_01/em.111/e16790/udm.htm#CGDBACGA)
OS script can be created using any scripting language e.g. perl/shell scripting etc.
I have created a shell script (npl.sh) to calculate 'Network Packet Loss' as given below
================================================
#!/bin/sh
# Sample User Defined Event monitoring script.
export PATH="/bin:/usr/bin:/usr/sbin";
cmd=`mtr -c 1 -r`;

p=`echo $cmd|cut -d " " -f 9|cut -d '%' -f 1`

echo "em_result=${p}";
echo "em_message=Network Packet Loss is: ${p}"
================================================

You can create this script (npl.sh) at any location like in my case, I saved it as /u01/scripts/npl.sh
Ensure that you can run the script once as the required user and it should give you expected output on command prompt itself before you register the script for UDM.

This script uses "mtr" command that requires SUDO access, so I need to execute an additional step to ensure that SUDO access is given to the user while running this script. That additional step is to configure Privilege Delegation Providers (http://download.oracle.com/docs/cd/E11857_01/install.111/e16847/addnl_tasks.htm#BABDEADD)

Creating a Privilege Delegation Setting
a. Click on Setup link on the Enterprise Manager home page and then choose Manage Privilege Delegation Settings from the left menu panel.
b. It will show you list of target hosts. Click on Edit button against the target host where you want to run the script.
c. Select the SUDO privilege delegation type
d. Enter the privilege delegation command e.g. I entered "sudo -u %RUNAS% %COMMAND%" and click on Update to apply the settings to the host.
e. Confirm the setting

2. Create an OS script based UDM
Now that we have created the script (npl.sh), configured needed privilege and ensured that script g ves expected output. Next step is to register the script for UDM and create the UDM

a. From the home page of the target Host that has OS monitoring script (npl.sh), choose User-Defined Metrics link from Related Links at the page bottom. The User-Defined Metrics summary page appears.

b. Click Create.

Enter the Metric Name as "network_packet_loss"
Metric Type as Number
Command Line "/bin/sh /u01/scripts/npl.sh"
Provide Operating System Credentials to run the script. Do ensure to select Run Privilege as "Sudo" and Run as “root"

Enter Thresholds
For Comparison Operator ">=" Warning as "5" and Critical as "10"

Let other values be default values for Consecutive Occurrences or Schedule etc.
By default, metric evaluation will happen every 5 minutes.

c. Click OK.
"network_packet_loss" metric is created and will appear in the User-Defined Metric summary page.

After 5 min. , you should start seeing data/charts against this user defined metric.