How to create shell script based monitor for Linux servrs in SCOM for CPU and Drive usage?

Pradeep shunmugam 1 Reputation point
2022-11-23T15:32:55.523+00:00

Hello All,

I am new to SCOM. I am working on creating custom monitor for Linux servers using below Shell script.

Drive:
df -H | grep -vE '^Filesystem|tmpfs|cdrom'  | awk '{ print FNR "\t " $0 }' | awk '{ print $1 " " $6 " " $2 }'

CPU:
top -b -n2 -d1 | grep "Cpu(s)" | tail -n1 | awk '{print $2}' | awk -F. '{print $1}'

Drive alert using Threshold:

df -H | grep -vE '^Filesystem|tmpfs|cdrom'  | awk '{ print FNR "\t " $0 }' | awk '{ print $1 " " $6 " " $2 }' | while read -r output;
do  snum=$(echo "$output" | awk '{print $1}' )  usep=$(echo "$output" | awk '{ print $2}' | cut -d'%' -f1 )  partition=$(echo "$output" | awk '{ print $3 }' )  if [ $usep -ge 40 ]; then    echo $usep       fi
done

Using script "Drive alert using Threshold:",I am receiving only one alert even multiple drive/mountpoints have disk space greater than 40%. I have to receive alerts for each drive when it exceeds the threshold based on our organization requirement.

The default monitor allows us to have alert only for one threshold. We have to receive alert whenever threshold exceeds 70% , 85% and 95%.
Can someone please help me to create customized monitor for Linux CPU and Drive?

Thanks in advance.

Regards,
Pradeep

Operations Manager
Operations Manager
A family of System Center products that provide infrastructure monitoring, help ensure the predictable performance and availability of vital applications, and offer comprehensive monitoring for datacenters and cloud, both private and public.
1,601 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. SChalakov 10,576 Reputation points MVP Volunteer Moderator
    2022-11-23T20:00:16.713+00:00

    HI Pradeep (@Pradeep shunmugam ),

    I would encourage you to ask this in a Linux related forum. You have way better chances of getting a proper answer there, as here most of the people answering the threads are SCOM exeperts, but not necessarily Linux experts.
    SCOM will be able to either execute the script locally on your Linux systeme as exampled here and then get the data back to SCOM (never nmmind the version of SCOM from the article, the approach is exactly the same in the current SCOM versions, the GUI also):

    SCOM 2012 – Linux Two-State Monitor With “Script In Script”
    https://www.stefanroth.net/2012/10/21/scom-2012-linux-two-state-monitor-with-script-in-script/

    or you can paste the script directly from SCOM as shown here:

    SCOM 2016 – What’s New UNIX/Linux Series: Monitors And Rules Running (Any) Script E.G. Perl
    https://www.stefanroth.net/2016/08/24/scom-2016-whats-new-unixlinux-series-monitors-and-rules-running-any-script-e-g-perl/

    I hope I was able to help.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
    Regards
    Stoyan Chalakov

    0 comments No comments

  2. Pradeep shunmugam 1 Reputation point
    2022-11-24T13:44:42.313+00:00

    Hello Stoyan,

    Thanks for your help.

    The shell script command line is working fine in Linux servers. But while using this in SCOM script based monitor for Linux server, we are not getting alerts for valid thresholds.
    I believe, I miss something in SCOM monitor. Hence I asked in SCOM forum.
    If possible, please help me to fix this.

    Please note that I followed the same document which you shared in your reply.

    Regards,
    Pradeep

    0 comments No comments

  3. Bob Cornelissen 331 Reputation points MVP
    2022-11-28T11:18:27.483+00:00

    For the disk threshold monitoring... If you want separate alerts for each disk, you will have to target the monitor at the Linux Disks (not the linux server). And make sure your command uses the name of the targeted disk (you could pass the script a parameter of the targeted disk name). That way, each disk has its own health state and they can separately go into another state and alert.

    For the multiple thresholds. We can only do 2-state and 3-state monitors. So green-red (or green-yellow) and green-yellow-red. meaning thats two thresholds at most. You had 3 thresholds in your question, which will not be possible in that case.

    0 comments No comments

  4. Pradeep shunmugam 1 Reputation point
    2022-11-29T17:38:17.19+00:00

    Hello Bob,

    Thanks for your help.

    I will try this in our environment and will update here.

    Regards,
    Pradeep S.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.