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
# 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.


KevinM said...

Useful article, thanks. Do you know what EM Packs are required in order to be able to use this?

Neelima Bawa said...

As I understand, this feature should be free and be available for any EM pack.

Kevin MacIver said...

EM licensing is horribly complex but I would have expected you to need the System Monitoring Plug-in for Hosts at least. Do you have this enabled on the system where you set this up?

Neelima Bawa said...

I did not enable any system monitoring plugin. In my case, I have a normal linux box as a target host.

Anonymous said...

Currently em only monitors the UP/Down status in Emgc.i want to monitor the different states of WLS like Admin/Suspended/Failed status and health status like Warning,Overloaded etc

Neelima Bawa said...

As of now EM doesn't have those metrics. However, to get the WLS health status, you can write WLDF watch notification for 'SubsystemHealthStates' in WLS and get alerts.